Mercurial > repos > IBBoard.GtkSharp
changeset 16:c9aeaeaa3ea2
Re #47: Add translatable GTK# widgets
* Add initial "translatable dialog"
* Add basics of a control translator that will cascade through widgets
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 23 Nov 2010 21:01:28 +0000 |
parents | f6126047dd8c |
children | a9c60e6c4b5b |
files | IBBoard.GtkSharp.csproj Translatable/ControlTranslator.cs Translatable/TranslatableDialog.cs |
diffstat | 3 files changed, 94 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <Compile Include="NotebookUtil.cs" /> <Compile Include="TreeUtils.cs" /> <Compile Include="ComboBoxUtils.cs" /> + <Compile Include="Translatable\TranslatableDialog.cs" /> + <Compile Include="Translatable\ControlTranslator.cs" /> </ItemGroup> <ItemGroup> <None Include="COPYING.GPL" /> @@ -43,4 +45,22 @@ <Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <ItemGroup> + <ProjectReference Include="..\IBBoard\IBBoard.csproj"> + <Project>{5DFD64F6-FC2B-4B4F-B92E-483BAC468105}</Project> + <Name>IBBoard</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Folder Include="Translatable\" /> + </ItemGroup> + <ProjectExtensions> + <MonoDevelop> + <Properties> + <Policies> + <StandardHeader Text=" This file (${FileName}) is a part of the ${ProjectName} project and is copyright ${Year} ${CopyrightHolder}

// 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." inheritsSet="Apache2License" /> + </Policies> + </Properties> + </MonoDevelop> + </ProjectExtensions> </Project> \ No newline at end of file
--- /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 +{ + /// <summary> + /// A custom cascading translator. It takes any widget type and translates them if they implement <see>ITranslatable</see> + /// and optionally cascades the process to translate all children. + /// </summary> + 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); + } + } + } + + } +} +
--- /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