view Lang/TranslationLanguage.cs @ 98:e260fce130eb

* Remove deprecated version of maths code no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 13 Feb 2011 16:17:34 +0000
parents 90b9a3fe3c18
children a5714f82073d
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 LGPL, 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();
		}
	}
}