view Lang/TranslationLanguage.cs @ 80:a23c07137fa4

Re #32: Add staged loading of translations * Move from passing entire document to XmlTranslationSet to just passing XmlNodeList of translation nodes
author IBBoard <dev@ibboard.co.uk>
date Sat, 10 Apr 2010 19:05:26 +0000
parents 091bfa54d6c7
children 90b9a3fe3c18
line wrap: on
line source

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