1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| private traductionItem[] itemField;
private Dictionary<string, string> items = null;
private string lang;
public void InitTranslator(string language)
{
if (items == null)
{
items = new Dictionary<string, string>();
}
else
{
items.Clear();
}
// built the dictonnary with the correct language...
this.lang = language;
for (int i = 0; i < this.item.Length; ++i)
{
string key = item[i].name;
string value = item[i].name;
for(int j = 0; j < item[i].trad.Length;++j)
{
if (item[i].trad[j].lang == language)
{
value = item[i].trad[j].text;
break;
}
}
items.Add(key, value);
}
}
public void TranslateWindow(Form f)
{
foreach (Control c in f.Controls)
{
TranslateControl(c);
}
}
private void TranslateControl(Control c)
{
c.Text = items[c.Name];
if (c.Controls.Count > 0)
{
foreach (Control a in c.Controls)
{
TranslateControl(a);
}
}
} |