159 lines
4.6 KiB
C#
159 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using Newtonsoft.Json;
|
|
using SteamWare;
|
|
|
|
namespace CMS_SC.WebUserControls
|
|
{
|
|
public partial class mod_textTrans : SteamWare.UserControl
|
|
{
|
|
|
|
protected Dictionary<string, string> flagList
|
|
{
|
|
get
|
|
{
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
// se trovo da cache restituisco...
|
|
if (memLayer.ML.isInCacheObject("FlagList.map"))
|
|
{
|
|
if (memLayer.ML.cacheOnRedis)
|
|
{
|
|
answ = JsonConvert.DeserializeObject<Dictionary<string, string>>(memLayer.ML.objCacheObj("FlagList.map").ToString());
|
|
}
|
|
else
|
|
{
|
|
answ = (Dictionary<string, string>)memLayer.ML.objCacheObj("FlagList.map");
|
|
}
|
|
}
|
|
// altrimenti rileggo....
|
|
else
|
|
{
|
|
answ = getDictFromFile("FlagList.map");
|
|
// salvo serializzando se necessario
|
|
if (memLayer.ML.cacheOnRedis)
|
|
{
|
|
string serVal = JsonConvert.SerializeObject(answ);
|
|
memLayer.ML.setCacheVal("FlagList.map", serVal, true);
|
|
}
|
|
else
|
|
{
|
|
memLayer.ML.setCacheVal("FlagList.map", answ, true);
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// mostra tutte le lingue o SOLO il lang corrente
|
|
/// </summary>
|
|
public bool showAllLang { get; set; }
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// Lettura file di conf e ritorna dictionary
|
|
/// </summary>
|
|
/// <param name="filePath">File con le conf key-val tipo file.map</param>
|
|
/// <returns></returns>
|
|
protected Dictionary<string, string> getDictFromFile(string filePath)
|
|
{
|
|
// leggo file...
|
|
string[] contenuto = File.ReadAllLines(resDir + filePath);
|
|
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
foreach (var line in contenuto)
|
|
{
|
|
// se la linea non è commento e non è vuota...
|
|
if (line.Length > 0 && line[0] != '#')
|
|
{
|
|
string[] tokens = line.Split('|');
|
|
answ.Add(tokens[0], tokens[1]);
|
|
}
|
|
}
|
|
// ritorno valori...
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// folder Risorse x configurazione (Resources)
|
|
/// </summary>
|
|
public static string resDir
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\Resources\", HttpContext.Current.Server.MapPath("~"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Versione compelta del testo
|
|
/// </summary>
|
|
public string fullText
|
|
{
|
|
get
|
|
{
|
|
return hfFullText.Value;
|
|
}
|
|
set
|
|
{
|
|
hfFullText.Value = value;
|
|
}
|
|
}
|
|
public string tagOpen { get; set; }
|
|
public string tagClose { get; set; }
|
|
/// <summary>
|
|
/// Effettua una traduzione del testo da originale a test con FLAG + a capo ove necessario
|
|
/// </summary>
|
|
/// <param name="fullData"></param>
|
|
/// <returns></returns>
|
|
public string tradTesto(string fullData)
|
|
{
|
|
fullData = fullData.Replace("\n", "");
|
|
int idx = 1;
|
|
int endPos = 0;
|
|
int strLenght = fullData.Length;
|
|
string Lang = "";
|
|
string Translation = "";
|
|
string currOpen, currClose;
|
|
string outStr = "";
|
|
// proseguo estraendo a blocchi...
|
|
while (strLenght > 0)
|
|
{
|
|
// verifico formato inizia per iniziale del TAG
|
|
if (fullData[0] == tagOpen[0])
|
|
{
|
|
Lang = fullData.Substring(1, 2);
|
|
}
|
|
// compongo i 2 tag di apertura/chiusura...
|
|
currOpen = tagOpen.Replace("IT", Lang);
|
|
currClose = tagClose.Replace("IT", Lang);
|
|
// calcolo fine tag...
|
|
endPos = fullData.IndexOf(currClose);
|
|
try
|
|
{
|
|
// recupero la stringa effettiva
|
|
Translation = fullData.Substring(0, endPos).Replace(currOpen, "").Replace(currClose, "");
|
|
// tolgo tag+stringa da full e calcolo lunghezza, poi procedo
|
|
fullData = fullData.Substring(endPos).Replace(currClose, "");
|
|
strLenght = fullData.Length;
|
|
if (showAllLang || Lang == user_std.UtSn.lingua)
|
|
{
|
|
// accodo stringa... SE è abilitato ALL oppure se è lingua corrente...
|
|
outStr += string.Format(@"<img src='Images/blank.gif' class='flag {0}'/> {1}</br>", flagList[Lang], Translation);
|
|
}
|
|
idx++;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(exc.ToString(), tipoLog.EXCEPTION);
|
|
strLenght = 0;
|
|
}
|
|
}
|
|
return outStr;
|
|
}
|
|
}
|
|
} |