Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
annotate 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 |
rev | line source |
---|---|
140
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 using System; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 using System.Collections.Generic; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 using System.ComponentModel; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System.Data; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System.Drawing; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Globalization; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.Text; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using System.Windows.Forms; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using IBBoard.Lang; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using IBBoard.Windows.Forms; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 using IBBoard.Windows.Forms.I18N; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 namespace IBBoard.WarFoundry.GUI.WinForms |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 public partial class FrmPreferences : IBBForm |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 private Preferences prefs; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 public FrmPreferences(Preferences preferences) |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 prefs = preferences; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 InitializeComponent(); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 TranslateForm(); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 SetValues(); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 private void TranslateForm() |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 ControlTranslator.TranslateComponent(this); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language"); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 private void SetValues() |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 preferenceSections.Nodes.Add(Translation.GetTranslation("languagePrefSection", "language")); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 ICollection<TranslationLanguage> langs = Translation.GetLanguages(); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 sortedLangs.Sort(CompareLanguages); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 languageList.DataSource = sortedLangs; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 languageList.DisplayMember = "Name"; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 languageList.SelectedItem = Translation.GetTranslationSet(Translation.GetTranslationLanguage()).Language; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 private void languageList_SelectedIndexChanged(object sender, EventArgs e) |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 bttnOkay.Enabled = !(languageList.SelectedItem.Equals(Translation.GetTranslationLanguage())); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 private void bttnCancel_Click(object sender, EventArgs e) |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 Close(); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 private void bttnOkay_Click(object sender, EventArgs e) |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 TranslationLanguage lang = (TranslationLanguage)languageList.SelectedItem; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 string langCode = lang.Code; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 Translation.LoadTranslation(langCode); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 prefs["language"] = langCode; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 prefs.Save(); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 Close(); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2) |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 { |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth; |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
68 return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options); |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 } |
60c795eca8de
Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 } |