Sviluppo di un sito multilingua... e 3
Dopo il db, ecco come ho esteso i controlli base del Framework. Prima di tutto ho definito 3 interfacce, una base e 2 che ereditano da questa:
public interface ILocalizable{
string LocalizationCode{
get;
set;
}
}
public interface ISingleLocalizable : ILocalizable{
string LocalizationText{
get;
set;
}
}
public interface IMultipleLocalizable : ILocalizable{
string[] LocalizationText{
get;
set;
}
}
<p />public class GNLiteral : System.Web.UI.WebControls.Literal, ISingleLocalizable{
public string LocalizationText{
get { return Text; }
set { Text = (value == null) ? "???" : value; }
}
public string LocalizationCode{
get {
if (ViewState["IDLOC"] != null){
return Convert.ToString(ViewState["IDLOC"]);
}
return String.Empty;
}
set { ViewState["IDLOC"] = value; }
}
}La terza interfaccia serve per controlli che visualizzano più testi come ListBox, DropDownList, CheckboxList ecc.
public class GNDropDownList : System.Web.UI.WebControls.DropDownList, IMultipleLocalizable{
public string[] LocalizationText{
get {
string[] result = new string[Items.Count];
for (int i=0; i<items.count; /> result[i] = Items[i].Text;
}
return result;
}
set {
for (int i=0; i<items.count; /> if (value == null || value.Length <= i)
Items[i].Text = "???";
else
Items[i].Text = value[i];
}
}
}
public string LocalizationCode{
get {
if (ViewState["IDLOC"] != null){
return Convert.ToString(ViewState["IDLOC"]);
}
return String.Empty;
}
set { ViewState["IDLOC"] = value; }
}
}Le interfacce vengono utilizzate per astrarre il nome della proprietà che contiene il testo da tradurre, lasciando al controllo l'implementazione. Per esempio, se per un Button la proprietà da tradurre è "Text", per un Validator è "ErrorMessage".
Nel prossimo post, concluderò mostrando il metodo che traduce tutti gli oggetti della pagina.
Stay tuned...
Aggiungi un nuovo commento »»»
Per inserire un commento, devi registrarti alla nostra community.
Nella stessa categoria
I più letti del mese




Stampa
Download
10annidi.ASPItalia.com: iscriviti alla competizione e vinci fantastici premi ogni mese!
SM15455