예제 #1
0
 /// <summary>
 ///     Load the resources from the language file
 /// </summary>
 /// <param name="languageFile">File to load from</param>
 private static void LoadResources(LanguageFile languageFile)
 {
     Log.Info().WriteLine("Loading language file {0}", languageFile.Filepath);
     try
     {
         var xmlDocument = new XmlDocument();
         xmlDocument.Load(languageFile.Filepath);
         var resourceNodes = xmlDocument.GetElementsByTagName("resource");
         foreach (XmlNode resourceNode in resourceNodes)
         {
             var key = resourceNode.Attributes["name"].Value;
             if (!string.IsNullOrEmpty(languageFile.Prefix))
             {
                 key = languageFile.Prefix + "." + key;
             }
             var text = resourceNode.InnerText;
             if (!string.IsNullOrEmpty(text))
             {
                 text = text.Trim();
             }
             if (!Resources.ContainsKey(key))
             {
                 Resources.Add(key, text);
             }
             else
             {
                 Resources[key] = text;
             }
         }
     }
     catch (Exception e)
     {
         Log.Error().WriteLine(e, "Could not load language file " + languageFile.Filepath);
     }
 }
예제 #2
0
        /// <summary>
        ///     Load the language file information
        /// </summary>
        /// <param name="languageFilePath"></param>
        /// <returns></returns>
        private static LanguageFile LoadFileInfo(string languageFilePath)
        {
            try
            {
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(languageFilePath);
                var nodes = xmlDocument.GetElementsByTagName("language");
                if (nodes.Count <= 0)
                {
                    throw new XmlException("Root element <language> is missing");
                }

                var languageFile = new LanguageFile
                {
                    Filepath = languageFilePath
                };
                var node = nodes.Item(0);
                if (node?.Attributes == null)
                {
                    return(languageFile);
                }

                languageFile.Description = node.Attributes["description"]?.Value;
                languageFile.Ietf        = ReformatIETF(node.Attributes["ietf"]?.Value);
                if (node.Attributes["version"]?.Value != null)
                {
                    languageFile.Version = new Version(node.Attributes["version"].Value);
                }
                languageFile.Prefix        = node.Attributes["prefix"]?.Value.ToLower();
                languageFile.LanguageGroup = node.Attributes["languagegroup"]?.Value.ToLower();
                return(languageFile);
            }
            catch (Exception e)
            {
                Log.Error().WriteLine(e, "Could not load language file " + languageFilePath);
            }
            return(null);
        }