Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
view FrmPreferences.cs @ 143:28105d9c2b25
Re #265: Add language preference UI
* Make unit form and army tree translate on translation language change
Army tree title translation still seems patchy
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 14 Apr 2010 19:59:35 +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); } } }