# HG changeset patch # User IBBoard # Date 1290546088 0 # Node ID c9aeaeaa3ea2d9ae574f97a176967ad34aae561a # Parent f6126047dd8ca527f5b86f3f53293a75742c8c10 Re #47: Add translatable GTK# widgets * Add initial "translatable dialog" * Add basics of a control translator that will cascade through widgets diff -r f6126047dd8c -r c9aeaeaa3ea2 IBBoard.GtkSharp.csproj --- a/IBBoard.GtkSharp.csproj Fri Aug 27 10:56:51 2010 +0000 +++ b/IBBoard.GtkSharp.csproj Tue Nov 23 21:01:28 2010 +0000 @@ -33,6 +33,8 @@ + + @@ -43,4 +45,22 @@ + + + {5DFD64F6-FC2B-4B4F-B92E-483BAC468105} + IBBoard + + + + + + + + + + + + + + \ No newline at end of file diff -r f6126047dd8c -r c9aeaeaa3ea2 Translatable/ControlTranslator.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Translatable/ControlTranslator.cs Tue Nov 23 21:01:28 2010 +0000 @@ -0,0 +1,50 @@ +// This file (ControlTranslator.cs) is a part of the IBBoard.GtkSharp project and is copyright 2010 IBBoard +// +// // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; +using Gtk; +using IBBoard.Lang; + +namespace IBBoard.GtkSharp.Translatable +{ + /// + /// A custom cascading translator. It takes any widget type and translates them if they implement ITranslatable + /// and optionally cascades the process to translate all children. + /// + public class ControlTranslator + { + public static void TranslateWidget(Widget toTranslate) + { + if (toTranslate is ITranslatable) + { + Translation.Translate((ITranslatable)toTranslate); + } + } + + public static void TranslateWidget(Widget toTranslate, bool cascade) + { + TranslateWidget(toTranslate); + } + + public static void TranslateWidget(Container toTranslate) + { + TranslateWidget(toTranslate, true); + } + + public static void TranslateWidget(Container toTranslate, bool cascade) + { + TranslateWidget(toTranslate); + + if (cascade) + { + foreach (Widget childWidget in toTranslate.AllChildren) + { + TranslateWidget(childWidget, cascade); + } + } + } + + } +} + diff -r f6126047dd8c -r c9aeaeaa3ea2 Translatable/TranslatableDialog.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Translatable/TranslatableDialog.cs Tue Nov 23 21:01:28 2010 +0000 @@ -0,0 +1,24 @@ +// This file (TranslatableDialog.cs) is a part of the IBBoard.GtkSharp project and is copyright 2010 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using Gtk; +using IBBoard.Lang; + +namespace IBBoard.GtkSharp.Translatable +{ + public abstract class TranslatableDialog : Dialog, ITranslatable + { + public string Text + { + get + { + return Title; + } + set + { + Title = value; + } + } + } +} \ No newline at end of file