changeset 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 09f71d10c249
files Lang/TranslationXmlExtractor.cs Lang/TranslationXmlLoader.cs Lang/XmlTranslationSet.cs
diffstat 3 files changed, 9 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/Lang/TranslationXmlExtractor.cs	Fri Apr 09 19:48:51 2010 +0000
+++ b/Lang/TranslationXmlExtractor.cs	Sat Apr 10 19:05:26 2010 +0000
@@ -10,21 +10,11 @@
 {
 	public class TranslationXmlExtractor
 	{		
-		public Dictionary<string, string> ExtractTranslationsFromDocument(XmlDocument doc)
+		public XmlNodeList GetTranslationNodes(XmlDocument doc)
 		{
 			try
 			{
-				XmlNodeList translationNodes = doc.GetElementsByTagName("translation");
-				Dictionary<string, string> translationStrings = new Dictionary<string, string>();
-
-				foreach (XmlNode node in translationNodes)
-				{
-					string id = node.Attributes["id"].Value;
-					string text = node.InnerText;
-					translationStrings.Add(id, text);
-				}
-							
-				return translationStrings;
+				return doc.GetElementsByTagName("translation");
 			}
 			catch(Exception ex)
 			{
--- a/Lang/TranslationXmlLoader.cs	Fri Apr 09 19:48:51 2010 +0000
+++ b/Lang/TranslationXmlLoader.cs	Sat Apr 10 19:05:26 2010 +0000
@@ -40,7 +40,7 @@
 			XmlDocument doc = LoadTranslationDocument(file);
 			XmlTranslationSet translations = new XmlTranslationSet(extractor.GetLanguageOfDocument(doc));
 			translations.SetParentLanguage(extractor.GetParentLanguageOfDocument(doc));
-			translations.SetSourceXml(doc);
+			translations.SetTranslationNodes(extractor.GetTranslationNodes(doc));
 			return translations;
 		}
 		
--- a/Lang/XmlTranslationSet.cs	Fri Apr 09 19:48:51 2010 +0000
+++ b/Lang/XmlTranslationSet.cs	Sat Apr 10 19:05:26 2010 +0000
@@ -11,7 +11,7 @@
 	public class XmlTranslationSet : AbstractTranslationSet
 	{
 		private string parentLanguage;
-		private XmlDocument doc;
+		private XmlNodeList nodes;
 		
 		public XmlTranslationSet(String languageCode) : base(languageCode)
 		{
@@ -22,7 +22,7 @@
 		{
 			get
 			{
-				if (translations.Count == 0 && doc != null)
+				if (translations.Count == 0 && nodes != null)
 				{
 					PopulateTranslations();
 				}
@@ -33,15 +33,11 @@
 
 		private void PopulateTranslations()
 		{
-			Dictionary<string, string> docTranslations = new TranslationXmlExtractor().ExtractTranslationsFromDocument(doc);
-			
-			foreach (KeyValuePair<string, string> pair in docTranslations)
+			foreach (XmlElement node in nodes)
 			{
-    			translations.Add(pair.Key, pair.Value);
+				translations.Add(node.GetAttribute("id"), node.InnerText);
 			}
 		}
-
-
 		
 		public void SetParentLanguage(string parentLanguageCode)
 		{
@@ -53,9 +49,9 @@
 			return Translation.GetTranslationSet(parentLanguage);
 		}
 		
-		public void SetSourceXml(XmlDocument sourceDocument)
+		public void SetTranslationNodes(XmlNodeList translationNodes)
 		{
-			doc = sourceDocument;
+			nodes = translationNodes;
 		}
 	}
 }