From dd83330191e8a11e767cd7424cc3ddc182e5b26f Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 17 Jan 2016 15:35:02 -0800 Subject: [PATCH] Implement ContextMenuStrip translation --- Misc/Util.cs | 38 ++++++++++++++++++++++++++++++++------ PKX/f1-Main.cs | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Misc/Util.cs b/Misc/Util.cs index a56381dbe..9e484eff1 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -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()) { // 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()).Distinct()) + { + ToolStripItem[] TSI = cs.Items.Find(ctrl, true); + if (TSI.Length <= 0) continue; + + TSI[0].Text = text; goto next; + } + + next:; } } + internal static List FindContextMenuStrips(IEnumerable c) + { + List cs = new List(); + 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())); + } + return cs; + } // Message Displays internal static DialogResult Error(params string[] lines) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 46ffbc504..f84bafd59 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -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; }