Mercurial > repos > IBBoard.GtkSharp
changeset 23:ae37467335ae
Re #47: Add translatable GTK# widgets
* Handle tool buttons, assuming that they're shown as icons and need a tooltip for text
* Translate actions before contained widgets (where they exist) on the assumption that some widgets (e.g. menus and buttons) may want to use the action text
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 28 Dec 2010 20:18:46 +0000 |
parents | edae1d817962 |
children | 3da8cf449717 |
files | Translatable/ControlTranslator.cs |
diffstat | 1 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Translatable/ControlTranslator.cs Tue Dec 28 19:50:04 2010 +0000 +++ b/Translatable/ControlTranslator.cs Tue Dec 28 20:18:46 2010 +0000 @@ -29,24 +29,44 @@ { TranslateAction(((MenuItem)toTranslate).Action); } - + else if (toTranslate is ToolButton) + { + ToolButton toolButton = ((ToolButton)toTranslate); + TranslateToolButton(toolButton); + } + if (cascade && toTranslate is Container) { CascadeTranslations((Container)toTranslate, cascade); } } + private static void TranslateToolButton(ToolButton toolButton) + { + Action action = toolButton.Action; + string translation = Translation.GetTranslation(toolButton.Name, ""); + + if (translation == "") + { + toolButton.TooltipText = action.Label; + } + else + { + toolButton.TooltipText = translation; + } + } + private static void CascadeTranslations(Container container, bool cascade) { + if (container is ITranslatableWithActions) + { + TranslateActions((ITranslatableWithActions)container); + } + foreach (Widget childWidget in container.AllChildren) { TranslateWidget(childWidget, cascade); } - - if (container is ITranslatableWithActions) - { - TranslateActions((ITranslatableWithActions)container); - } } private static void TranslateActions(ITranslatableWithActions actionContainer)