Mercurial > repos > IBBoard.GtkSharp
changeset 20:06715f517af6
Re #47: Add translatable GTK# widgets
* Add ITranslatableWithActions interface to provide a common way to get at actions (WinForms menu items are widgets, GTK uses Actions and ActionGroups)
* Add implementation of interface for Windows (most likely candidate for having translatable actions)
* Translate actions as well as sub-widgets
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 27 Dec 2010 20:48:29 +0000 |
parents | 2ddde7f1730e |
children | 0364560fcec2 |
files | IBBoard.GtkSharp.csproj Lang/ITranslatableWithActions.cs Translatable/ControlTranslator.cs Translatable/TranslatableWindowWithActions.cs |
diffstat | 4 files changed, 70 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/IBBoard.GtkSharp.csproj Mon Dec 27 20:19:36 2010 +0000 +++ b/IBBoard.GtkSharp.csproj Mon Dec 27 20:48:29 2010 +0000 @@ -36,6 +36,8 @@ <Compile Include="Translatable\TranslatableDialog.cs" /> <Compile Include="Translatable\ControlTranslator.cs" /> <Compile Include="Translatable\TranslatableWindow.cs" /> + <Compile Include="Lang\ITranslatableWithActions.cs" /> + <Compile Include="Translatable\TranslatableWindowWithActions.cs" /> </ItemGroup> <ItemGroup> <None Include="COPYING.GPL" /> @@ -54,6 +56,7 @@ </ItemGroup> <ItemGroup> <Folder Include="Translatable\" /> + <Folder Include="Lang\" /> </ItemGroup> <ProjectExtensions> <MonoDevelop>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lang/ITranslatableWithActions.cs Mon Dec 27 20:48:29 2010 +0000 @@ -0,0 +1,17 @@ +// This file (ITranslatableWithActions.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 IBBoard.Lang; +using Gtk; +using System.Collections.Generic; + +namespace IBBoard.GtkSharp +{ + public interface ITranslatableWithActions : ITranslatable + { + ICollection<Action> Actions { get; } + } +} +
--- a/Translatable/ControlTranslator.cs Mon Dec 27 20:19:36 2010 +0000 +++ b/Translatable/ControlTranslator.cs Mon Dec 27 20:48:29 2010 +0000 @@ -38,8 +38,23 @@ { TranslateWidget(childWidget, cascade); } + + if (container is ITranslatableWithActions) + { + TranslateActions((ITranslatableWithActions)container); + } } + private static void TranslateActions(ITranslatableWithActions actionContainer) + { + foreach (Action action in actionContainer.Actions) + { + if (action is ITranslatable) + { + Translation.Translate((ITranslatable)action); + } + } + } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Translatable/TranslatableWindowWithActions.cs Mon Dec 27 20:48:29 2010 +0000 @@ -0,0 +1,35 @@ +// This file (TranslatableWindowWithActions.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 System.Collections.Generic; +using Gtk; + +namespace IBBoard.GtkSharp.Translatable +{ + public abstract class TranslatableWindowWithActions : TranslatableWindow, ITranslatableWithActions + { + + public TranslatableWindowWithActions(IntPtr ptr) : base(ptr) + { + //Do nothing extra + } + + public TranslatableWindowWithActions(Gtk.WindowType windowType) : base(windowType) + { + //Do nothing extra + } + + public TranslatableWindowWithActions(string windowTitle) : base(windowTitle) + { + //Do nothing extra + } + + public abstract ICollection<Action> Actions + { + get; + } + } +} +