Mercurial > repos > IBBoard
diff Lang/TranslationLanguage.cs @ 73:091bfa54d6c7
Re #33: Add method to get list of available translations
* Add "translation language" object to pair up code and name
* Load all translations at initialisation time
Also:
* Remove rogue "set" property on abstract translation set
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 06 Apr 2010 18:58:30 +0000 |
parents | |
children | 90b9a3fe3c18 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lang/TranslationLanguage.cs Tue Apr 06 18:58:30 2010 +0000 @@ -0,0 +1,76 @@ +// This file (TranslationLanguage.cs) is a part of the IBBoard project and is copyright 2010 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL 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.Globalization; + +namespace IBBoard.Lang +{ + /// <summary> + /// A simple object that holds the name and code pairing for a language + /// </summary> + public class TranslationLanguage + { + private string langCode; + private string langName; + + public TranslationLanguage(string languageCode) + { + langCode = languageCode; + } + + public string Name + { + get + { + if (langName == null) + { + LoadLangName(); + } + + return langName; + } + } + + public string Code + { + get { return langCode; } + } + + private void LoadLangName() + { + try + { + CultureInfo culture = CultureInfo.GetCultureInfo(langCode); + langName = culture.NativeName; + } + catch (ArgumentException) + { + langName = "Unknown (" + langCode + ")"; + } + } + + public override bool Equals(object obj) + { + bool equal = true; + + if (obj == null || !obj.GetType().Equals(GetType())) + { + equal = false; + } + + else + { + equal = Code.Equals(((TranslationLanguage)obj).Code); + } + + return equal; + } + + public override int GetHashCode() + { + return GetType().GetHashCode() + langCode.GetHashCode(); + } + } +}