changeset 74:726731c78414

Re #37: Add event to indicate change of translation * Add event and trigger when current language value changes
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Apr 2010 14:56:17 +0000
parents 091bfa54d6c7
children b1ae6fce2e3f
files Lang/Translation.cs
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Lang/Translation.cs	Tue Apr 06 18:58:30 2010 +0000
+++ b/Lang/Translation.cs	Wed Apr 07 14:56:17 2010 +0000
@@ -28,6 +28,7 @@
 		private static readonly string DIVIDER_STRING = "-";
 		private static AbstractTranslationSet currentTranslations;
 		private static Dictionary<string, AbstractTranslationSet> langToTranslationMap;
+		public static event MethodInvoker TranslationChanged;
 		
 		static Translation()
 		{
@@ -91,9 +92,22 @@
 		/// </summary>
 		public static void Reset()
 		{
-			currentTranslations = null;
+			SetCurrentTranslations(null);
 			langToTranslationMap.Clear();
 		}
+		
+		private static void SetCurrentTranslations(AbstractTranslationSet newTranslations)
+		{
+			if (currentTranslations != newTranslations || (currentTranslations != null && !currentTranslations.Equals(newTranslations)))
+			{
+				currentTranslations = newTranslations;
+				
+				if (TranslationChanged != null)
+				{
+					TranslationChanged();
+				}
+			}
+		}
 
 		/// <summary>
 		/// Loads translations for a given language and sets them as the current language.
@@ -115,7 +129,7 @@
 		
 		private static void LoadTranslationForLanguage(string translationLanguage)
 		{			
-			currentTranslations = DictionaryUtils.GetValue(langToTranslationMap, translationLanguage);
+			SetCurrentTranslations(DictionaryUtils.GetValue(langToTranslationMap, translationLanguage));
 		}
 
 		/// <summary>