Mercurial > repos > IBBoard
annotate Lang/XmlTranslationSet.cs @ 80:a23c07137fa4
Re #32: Add staged loading of translations
* Move from passing entire document to XmlTranslationSet to just passing XmlNodeList of translation nodes
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 10 Apr 2010 19:05:26 +0000 |
parents | da339d10c5fe |
children |
rev | line source |
---|---|
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (XmlTranslationSet.cs) is a part of the IBBoard project and is copyright 2010 IBBoard |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
da339d10c5fe
Re #32: Add staged loading of 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 LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Collections.Generic; |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.Xml; |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 namespace IBBoard.Lang |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 public class XmlTranslationSet : AbstractTranslationSet |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 private string parentLanguage; |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
14 private XmlNodeList nodes; |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 public XmlTranslationSet(String languageCode) : base(languageCode) |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 //Do nothing extra |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 public override string this[string key] |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 get |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 { |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
25 if (translations.Count == 0 && nodes != null) |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 PopulateTranslations(); |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 return base[key]; |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 private void PopulateTranslations() |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 { |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
36 foreach (XmlElement node in nodes) |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 { |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
38 translations.Add(node.GetAttribute("id"), node.InnerText); |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 public void SetParentLanguage(string parentLanguageCode) |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 parentLanguage = parentLanguageCode; |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 protected override AbstractTranslationSet GetParentTranslations() |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 return Translation.GetTranslationSet(parentLanguage); |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
52 public void SetTranslationNodes(XmlNodeList translationNodes) |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 { |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
54 nodes = translationNodes; |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 } |