예제 #1
0
 /// <summary>
 /// Recursively traverse the XDocument and add properties when a bottom element is found.
 /// </summary>
 /// <param name="elements">The elements to explore.</param>
 /// <param name="dictionnary">The dictionnary to add translations to.</param>
 /// <param name="file">The information about the file currently being loaded.</param>
 /// <param name="path">The path to this dept.</param>
 private static void XmlLoadRecursive(IEnumerable <XElement> elements, IDictionary <string, TranslationItem> dictionnary, TranslationFileInfo file, string path = "")
 {
     foreach (var element in elements)
     {
         var nextPath = String.IsNullOrWhiteSpace(path) ? element.Name.ToString() : path + "." + element.Name;
         if (element.HasElements)
         {
             XmlLoadRecursive(element.Elements(), dictionnary, file, nextPath);
         }
         else
         {
             dictionnary[nextPath] = new TranslationItem
             {
                 Text            = element.Value,
                 LanguageIsoCode = file.Language,
                 FileName        = file.FileName
             };
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Loads a translation file.
        /// </summary>
        /// <param name="source">The XML translation source.</param>
        /// <param name="dictionnary">The translations dictionary to load string into.</param>
        /// <param name="file">The information of the file that contains the XML translations.</param>
        private static void LoadDocument(XDocument source, IDictionary <string, TranslationItem> dictionnary, TranslationFileInfo file)
        {
            if (source == null)
            {
                return;
            }
            if (source.Root == null)
            {
                return;
            }

            XmlLoadRecursive(source.Root.Elements(), dictionnary, file);
        }