diff Lang/AbstractTranslationSet.cs @ 72:cec6c4c0892d

Fixes #34: Get name for translation * Add code for translation name fetching (using native name)
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Apr 2010 18:20:14 +0000
parents b5d7e8b93205
children 091bfa54d6c7
line wrap: on
line diff
--- a/Lang/AbstractTranslationSet.cs	Tue Apr 06 18:08:43 2010 +0000
+++ b/Lang/AbstractTranslationSet.cs	Tue Apr 06 18:20:14 2010 +0000
@@ -4,6 +4,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 
 namespace IBBoard.Lang
 {
@@ -14,6 +15,7 @@
 	public class AbstractTranslationSet
 	{
 		private string langCode;
+		private string langName;
 		protected Dictionary<string, string> translations;
 		
 		public AbstractTranslationSet(string languageCode)
@@ -46,6 +48,32 @@
 			{
 				return DictionaryUtils.GetValue(translations, key);
 			}
-		}	
+		}
+		
+		public string LanguageName
+		{
+			get
+			{
+				if (langName == null)
+				{
+					LoadLangName();
+				}
+				
+				return langName;				
+			}
+		}
+		
+		private void LoadLangName()
+		{
+			try
+			{
+				CultureInfo culture = CultureInfo.GetCultureInfo(langCode);
+				langName = culture.NativeName;
+			}
+			catch(ArgumentException)
+			{
+				langName = "Unknown ("+langCode+")";
+			}
+		}
 	}
 }