Mercurial > repos > IBBoard
annotate Lang/TranslationXmlExtractor.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 | a70d89de1435 |
children |
rev | line source |
---|---|
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (TranslationXmlExtractor.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 TranslationXmlExtractor |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
79
diff
changeset
|
13 public XmlNodeList GetTranslationNodes(XmlDocument doc) |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 { |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 try |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 { |
80
a23c07137fa4
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
79
diff
changeset
|
17 return doc.GetElementsByTagName("translation"); |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 catch(Exception ex) |
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 throw new TranslationLoadException("Error while parsing " + GetLanguageOfDocument(doc)+" translation: "+ex.Message, ex); |
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 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 public string GetLanguageOfDocument(XmlDocument doc) |
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 return doc != null ? doc.DocumentElement.GetAttribute("lang") : ""; |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 } |
79
a70d89de1435
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
29 |
a70d89de1435
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
30 public string GetParentLanguageOfDocument(XmlDocument doc) |
a70d89de1435
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
31 { |
a70d89de1435
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
32 return doc != null ? doc.DocumentElement.GetAttribute("extends") : ""; |
a70d89de1435
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
33 } |
78
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 } |
da339d10c5fe
Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 } |