Mercurial > repos > IBBoard
comparison Lang/TranslationXmlLoader.cs @ 113:e32b5ccda410
* Update Translations to use built-in schema
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 24 Jun 2012 15:48:25 +0100 |
parents | 90b9a3fe3c18 |
children | de0ed24eb961 |
comparison
equal
deleted
inserted
replaced
112:3262c0ad2d3d | 113:e32b5ccda410 |
---|---|
1 // This file (TranslationXmlLoader.cs) is a part of the IBBoard project and is copyright 2010 IBBoard | 1 // This file (TranslationXmlLoader.cs) is a part of the IBBoard project and is copyright 2010 IBBoard |
2 // | 2 // |
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. | 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. |
4 | |
5 using System; | 4 using System; |
6 using System.IO; | 5 using System.IO; |
7 using System.Xml; | 6 using System.Xml; |
8 using System.Xml.Schema; | 7 using System.Xml.Schema; |
9 using System.Collections.Generic; | 8 using System.Collections.Generic; |
10 using IBBoard.IO; | 9 using IBBoard.IO; |
11 using IBBoard.Xml; | 10 using IBBoard.Xml; |
11 using System.Reflection; | |
12 | 12 |
13 namespace IBBoard.Lang | 13 namespace IBBoard.Lang |
14 { | 14 { |
15 /// <summary> | 15 /// <summary> |
16 /// A simple loader of translations from XML files | 16 /// A simple loader of translations from XML files |
17 /// </summary> | 17 /// </summary> |
18 public class TranslationXmlLoader | 18 public class TranslationXmlLoader |
19 { | 19 { |
20 private XmlReaderSettings settings; | 20 private XmlReaderSettings settings; |
21 private string schemaLocation; | |
22 private TranslationXmlExtractor extractor; | 21 private TranslationXmlExtractor extractor; |
23 | 22 |
24 public TranslationXmlLoader(string schemaLocation) | 23 public TranslationXmlLoader() |
25 { | 24 { |
26 this.schemaLocation = schemaLocation; | |
27 extractor = new TranslationXmlExtractor(); | 25 extractor = new TranslationXmlExtractor(); |
28 } | 26 } |
29 | |
30 | 27 |
31 public AbstractTranslationSet LoadTranslations(string path) | 28 public AbstractTranslationSet LoadTranslations(string path) |
32 { | 29 { |
33 FileInfo file = new FileInfo(path); | 30 FileInfo file = new FileInfo(path); |
34 | 31 |
35 if (!file.Exists) | 32 if (!file.Exists) |
36 { | 33 { |
37 throw new TranslationLoadException("Translation file "+file.FullName+" did not exist"); | 34 throw new TranslationLoadException("Translation file " + file.FullName + " did not exist"); |
38 } | 35 } |
39 | 36 |
40 XmlDocument doc = LoadTranslationDocument(file); | 37 XmlDocument doc = LoadTranslationDocument(file); |
41 XmlTranslationSet translations = new XmlTranslationSet(extractor.GetLanguageOfDocument(doc)); | 38 XmlTranslationSet translations = new XmlTranslationSet(extractor.GetLanguageOfDocument(doc)); |
42 translations.SetParentLanguage(extractor.GetParentLanguageOfDocument(doc)); | 39 translations.SetParentLanguage(extractor.GetParentLanguageOfDocument(doc)); |
86 try | 83 try |
87 { | 84 { |
88 settings = new XmlReaderSettings(); | 85 settings = new XmlReaderSettings(); |
89 settings.ValidationType = ValidationType.Schema; | 86 settings.ValidationType = ValidationType.Schema; |
90 settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings; | 87 settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings; |
91 settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod); | 88 settings.ValidationEventHandler += new ValidationEventHandler(ValidationEventMethod); |
92 XmlSchemaSet cache = new XmlSchemaSet(); | 89 XmlSchemaSet cache = new XmlSchemaSet(); |
93 cache.Add("http://ibboard.co.uk/translation", schemaLocation); | 90 cache.Add("http://ibboard.co.uk/translation", new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("IBBoard.schemas.translation.xsd"))); |
94 settings.Schemas.Add(cache); | 91 settings.Schemas.Add(cache); |
95 } | 92 } |
96 catch (DirectoryNotFoundException ex) | 93 catch (DirectoryNotFoundException ex) |
97 { | 94 { |
98 throw new TranslationLoadException("Problem validating schema for translation: " + ex.Message, ex); | 95 throw new TranslationLoadException("Problem validating schema for translation: " + ex.Message, ex); |