view Translatable/ControlTranslator.cs @ 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
children a9c60e6c4b5b
line wrap: on
line source

//  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);
				}
			}
		}

	}
}