Mercurial > repos > IBBoard
annotate Lang/TranslationLanguage.cs @ 77:eb47e17ec824
Re #35: Add multi-level cascading of translations
* Check for loops using the method defined at http://ostermiller.org/find_loop_singly_linked_list.html ("Floyd's Cycle-Finding Algorithm")
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 09 Apr 2010 15:12:01 +0000 |
parents | 091bfa54d6c7 |
children | 90b9a3fe3c18 |
rev | line source |
---|---|
73
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (TranslationLanguage.cs) is a part of the IBBoard project and is copyright 2010 IBBoard |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // 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. |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Globalization; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 namespace IBBoard.Lang |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 /// <summary> |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 /// A simple object that holds the name and code pairing for a language |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 /// </summary> |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 public class TranslationLanguage |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 private string langCode; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 private string langName; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 public TranslationLanguage(string languageCode) |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 langCode = languageCode; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 public string Name |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 get |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 if (langName == null) |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 LoadLangName(); |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 return langName; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 public string Code |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 get { return langCode; } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 private void LoadLangName() |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 try |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 CultureInfo culture = CultureInfo.GetCultureInfo(langCode); |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 langName = culture.NativeName; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 catch (ArgumentException) |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 langName = "Unknown (" + langCode + ")"; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 public override bool Equals(object obj) |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 bool equal = true; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 if (obj == null || !obj.GetType().Equals(GetType())) |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 equal = false; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 else |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 equal = Code.Equals(((TranslationLanguage)obj).Code); |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
68 return equal; |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 public override int GetHashCode() |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 { |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 return GetType().GetHashCode() + langCode.GetHashCode(); |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 } |
091bfa54d6c7
Re #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 } |