Mercurial > repos > IBBoard.Windows.Forms
changeset 6:97cab866aba9
Re #22 - Make failing control translation cleaner for normal use
* Use new translation method with default text parameter and pass current text as default
Also:
* Cleanup control translator tabbing
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 25 May 2009 10:29:21 +0000 |
parents | c70356dc5609 |
children | 02a7c7aaf2c1 |
files | Windows/Forms/I18N/ControlTranslator.cs |
diffstat | 1 files changed, 77 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/Windows/Forms/I18N/ControlTranslator.cs Mon May 25 10:27:46 2009 +0000 +++ b/Windows/Forms/I18N/ControlTranslator.cs Mon May 25 10:29:21 2009 +0000 @@ -11,81 +11,87 @@ namespace IBBoard.Windows.Forms.I18N { - public class ControlTranslator - { - public static void TranslateControl(Control ctrl, params object[] replacements) - { - TranslateControl(ctrl, true, replacements); - } - - public static void TranslateControl(Control ctrl, bool cascadeTranslate, params object[] replacements) - { - if (ctrl is ITranslatable) - { - Translation.Translate((ITranslatable)ctrl, replacements); - } + public class ControlTranslator + { + public static void TranslateControl(Control ctrl, params object[] replacements) + { + TranslateControl(ctrl, true, replacements); + } - if (cascadeTranslate) - { - CascadeControlTranslation(ctrl, replacements); - } - } + public static void TranslateControl(Control ctrl, bool cascadeTranslate, params object[] replacements) + { + if (ctrl is ITranslatable) + { + Translate((ITranslatable)ctrl, replacements); + } - private static void CascadeControlTranslation(Control ctrl, params object[] replacements) - { - if (ctrl is ToolBar) - { - foreach (ToolBarButton bttn in ((ToolBar)ctrl).Buttons) - { - TranslateComponent(bttn, true, replacements); - } - } - else - { - foreach (Control subctr in ctrl.Controls) - { - TranslateControl(subctr, true, replacements); - } - } - } + if (cascadeTranslate) + { + CascadeControlTranslation(ctrl, replacements); + } + } + + private static void Translate(ITranslatable translatable, params object[] replacements) + { + Translation.Translate(translatable, translatable.Text, replacements); + } - public static void TranslateComponent(Component comp, params object[] replacements) - { - TranslateComponent(comp, true, replacements); - } + private static void CascadeControlTranslation(Control ctrl, params object[] replacements) + { + if (ctrl is ToolBar) + { + foreach (ToolBarButton bttn in ((ToolBar)ctrl).Buttons) + { + TranslateComponent(bttn, true, replacements); + } + } + else + { + foreach (Control subctr in ctrl.Controls) + { + TranslateControl(subctr, true, replacements); + } + } + } - public static void TranslateComponent(Component comp, bool cascadeTranslate, params object[] replacements) - { - if (comp is ITranslatable) - { - Translation.Translate((ITranslatable)comp, replacements); - } - else if (comp is FileDialog) - { - //HACK: We can't override SWF dialogs in .Net 1.1, so put in a special condition check for them - FileDialog dialog = (FileDialog)comp; + public static void TranslateComponent(Component comp, params object[] replacements) + { + TranslateComponent(comp, true, replacements); + } - if (dialog.Title.StartsWith("Translatable:")) - { - dialog.Title = Translation.GetTranslation(dialog.Title.Substring(13), replacements); - } - } + public static void TranslateComponent(Component comp, bool cascadeTranslate, params object[] replacements) + { + if (comp is ITranslatable) + { + Translate((ITranslatable)comp, replacements); + } + else if (comp is FileDialog) + { + //HACK: We can't override SWF dialogs in .Net 1.1, so put in a special condition check for them + FileDialog dialog = (FileDialog)comp; - if (cascadeTranslate) - { - CascadeComponentTranslations(comp, cascadeTranslate, replacements); - } - } + if (dialog.Title.StartsWith("Translatable:")) + { + string title = dialog.Title.Substring(13); + dialog.Title = Translation.GetTranslation(title, title, replacements); + } + } - private static void CascadeComponentTranslations(Component comp, params object[] replacements) - { - if (comp is Menu) - { - foreach (MenuItem mi in ((Menu)comp).MenuItems) - { - TranslateComponent(mi, true, replacements); - } - } - } - } -} + if (cascadeTranslate) + { + CascadeComponentTranslations(comp, cascadeTranslate, replacements); + } + } + + private static void CascadeComponentTranslations(Component comp, params object[] replacements) + { + if (comp is Menu) + { + foreach (MenuItem mi in ((Menu)comp).MenuItems) + { + TranslateComponent(mi, true, replacements); + } + } + } + } +} \ No newline at end of file