view FrmPreferences.cs @ 142:e0af96397e26

Re #203: Translate WarFoundry * Actually add German translation * Make controls on Pref form use custom translatable IBB versions so that they translate * Make new menu item a custom translatable IBB version so that it translates
author IBBoard <dev@ibboard.co.uk>
date Wed, 14 Apr 2010 19:42:45 +0000
parents 60c795eca8de
children 4023a9bdcb8b
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using IBBoard.Lang;
using IBBoard.Windows.Forms;
using IBBoard.Windows.Forms.I18N;

namespace IBBoard.WarFoundry.GUI.WinForms
{
	public partial class FrmPreferences : IBBForm
	{
		private Preferences prefs;

		public FrmPreferences(Preferences preferences)
		{
			prefs = preferences;
			InitializeComponent();
			TranslateForm();
			SetValues();
		}

		private void TranslateForm()
		{
			ControlTranslator.TranslateComponent(this);
			languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language");
		}

		private void SetValues()
		{
			preferenceSections.Nodes.Add(Translation.GetTranslation("languagePrefSection", "language"));
			ICollection<TranslationLanguage> langs = Translation.GetLanguages();
			List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
			sortedLangs.Sort(CompareLanguages);
			languageList.DataSource = sortedLangs;
			languageList.DisplayMember = "Name";
			languageList.SelectedItem = Translation.GetTranslationSet(Translation.GetTranslationLanguage()).Language;
			languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged);
		}

		private void languageList_SelectedIndexChanged(object sender, EventArgs e)
		{
			bttnOkay.Enabled = !(languageList.SelectedItem.Equals(Translation.GetTranslationLanguage()));
		}

		private void bttnCancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void bttnOkay_Click(object sender, EventArgs e)
		{
			TranslationLanguage lang = (TranslationLanguage)languageList.SelectedItem;
			string langCode = lang.Code;
			Translation.LoadTranslation(langCode);
			prefs["language"] = langCode;
			prefs.Save();
			Close();
		}

		private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)
		{
			CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
			return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options);
		}
	}
}