Implement ContextMenuStrip translation

This commit is contained in:
Kaphotics 2016-01-17 15:35:02 -08:00
parent 0b89682a64
commit dd83330191
2 changed files with 33 additions and 7 deletions

View file

@ -255,7 +255,7 @@ namespace PKHeX
}
// Form Translation
internal static void TranslateInterface(Control form, string lang, MenuStrip menu = null)
internal static void TranslateInterface(Control form, string lang)
{
// Check to see if a the translation file exists in the same folder as the executable
string externalLangPath = Application.StartupPath + Path.DirectorySeparatorChar + "lang_" + lang + ".txt";
@ -303,17 +303,43 @@ namespace PKHeX
string ctrl = SplitString[0]; // Control to change the text of...
string text = SplitString[1]; // Text to set Control.Text to...
Control[] controllist = form.Controls.Find(ctrl, true);
if (controllist.Length == 0 && menu != null) // If Control isn't found... check menustrip
if (controllist.Length != 0) // If Control is found
{ controllist[0].Text = text; goto next; }
// Check MenuStrips
foreach (MenuStrip menu in form.Controls.OfType<MenuStrip>())
{
// Menu Items aren't in the Form's Control array. Find within the menu's Control array.
ToolStripItem[] TSI = menu.Items.Find(ctrl, true);
if (TSI.Length > 0) // Found
TSI[0].Text = text;
if (TSI.Length <= 0) continue;
TSI[0].Text = text; goto next;
}
else // Set the input control's text.
controllist[0].Text = text;
// Check ContextMenuStrips
foreach (ContextMenuStrip cs in FindContextMenuStrips(form.Controls.OfType<Control>()).Distinct())
{
ToolStripItem[] TSI = cs.Items.Find(ctrl, true);
if (TSI.Length <= 0) continue;
TSI[0].Text = text; goto next;
}
next:;
}
}
internal static List<ContextMenuStrip> FindContextMenuStrips(IEnumerable<Control> c)
{
List<ContextMenuStrip> cs = new List<ContextMenuStrip>();
foreach (Control control in c)
{
if (control.ContextMenuStrip != null)
cs.Add(control.ContextMenuStrip);
else if (control.Controls.Count > 0)
cs.AddRange(FindContextMenuStrips(control.Controls.OfType<Control>()));
}
return cs;
}
// Message Displays
internal static DialogResult Error(params string[] lines)

View file

@ -882,7 +882,7 @@ namespace PKHeX
Menu_Options.DropDown.Close();
InitializeStrings();
InitializeLanguage();
Util.TranslateInterface(this, lang_val[CB_MainLanguage.SelectedIndex], menuStrip1); // Translate the UI to language.
Util.TranslateInterface(this, lang_val[CB_MainLanguage.SelectedIndex]); // Translate the UI to language.
populateFields(data); // put data back in form
fieldsInitialized |= alreadyInit;
}