Mercurial > repos > IBBoard
changeset 79:a70d89de1435
Re #32: Add staged loading of translations
* Add "extends" attribute to schema so that translation files can define what they extend
* Add "get parent language" method to extractor
* Move loader to using XML translation sets
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 09 Apr 2010 19:48:51 +0000 |
parents | da339d10c5fe |
children | a23c07137fa4 |
files | Lang/TranslationXmlExtractor.cs Lang/TranslationXmlLoader.cs schemas/translation.xsd |
diffstat | 3 files changed, 9 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/Lang/TranslationXmlExtractor.cs Fri Apr 09 19:35:18 2010 +0000 +++ b/Lang/TranslationXmlExtractor.cs Fri Apr 09 19:48:51 2010 +0000 @@ -36,5 +36,10 @@ { return doc != null ? doc.DocumentElement.GetAttribute("lang") : ""; } + + public string GetParentLanguageOfDocument(XmlDocument doc) + { + return doc != null ? doc.DocumentElement.GetAttribute("extends") : ""; + } } }
--- a/Lang/TranslationXmlLoader.cs Fri Apr 09 19:35:18 2010 +0000 +++ b/Lang/TranslationXmlLoader.cs Fri Apr 09 19:48:51 2010 +0000 @@ -38,8 +38,9 @@ } XmlDocument doc = LoadTranslationDocument(file); - ModifiableTranslationSet translations = new ModifiableTranslationSet(extractor.GetLanguageOfDocument(doc)); - LoadTranslationsFromDocument(doc, translations); + XmlTranslationSet translations = new XmlTranslationSet(extractor.GetLanguageOfDocument(doc)); + translations.SetParentLanguage(extractor.GetParentLanguageOfDocument(doc)); + translations.SetSourceXml(doc); return translations; } @@ -113,15 +114,5 @@ { throw new TranslationLoadException("Problem validating schema for translation: " + e.Exception.Message, e.Exception); } - - private void LoadTranslationsFromDocument(XmlDocument doc, ModifiableTranslationSet translations) - { - Dictionary<string, string> translationStrings = extractor.ExtractTranslationsFromDocument(doc); - - foreach (KeyValuePair<string, string> translation in translationStrings) - { - translations.SetTranslation(translation.Key, translation.Value); - } - } } }
--- a/schemas/translation.xsd Fri Apr 09 19:35:18 2010 +0000 +++ b/schemas/translation.xsd Fri Apr 09 19:48:51 2010 +0000 @@ -13,6 +13,7 @@ <xs:element name="translation" minOccurs="0" maxOccurs="unbounded" type="translationtype"/> </xs:sequence> <xs:attribute name="lang" type="xs:string" use="required"/> + <xs:attribute name="extends" type="xs:string" default=""/> </xs:complexType> </xs:element> </xs:schema> \ No newline at end of file