Пример #1
0
        public static void SetCultureCode(string code)
        {
            Culture = new CultureInfo(code);

            Strings.Clear();
            Strings.Add(LoadXmlDoc(PathMod.ModPath("Strings/strings." + code + ".resx")));
            if (LangNames.ContainsKey(code))
            {
                foreach (string fallback in LangNames[code].Fallbacks)
                {
                    Strings.Add(LoadXmlDoc(PathMod.ModPath("Strings/strings." + fallback + ".resx")));
                }
            }
            Strings.Add(LoadXmlDoc(PathMod.ModPath("Strings/strings.resx")));

            StringsEx.Clear();

            StringsEx.Add(LoadXmlDoc(PathMod.ModPath("Strings/stringsEx." + code + ".resx")));
            if (LangNames.ContainsKey(code))
            {
                foreach (string fallback in LangNames[code].Fallbacks)
                {
                    StringsEx.Add(LoadXmlDoc(PathMod.ModPath("Strings/stringsEx." + fallback + ".resx")));
                }
            }
            StringsEx.Add(LoadXmlDoc(PathMod.ModPath("Strings/stringsEx.resx")));
        }
Пример #2
0
        public static void Init()
        {
            Strings   = new List <Dictionary <string, string> >();
            StringsEx = new List <Dictionary <string, string> >();

            string        path  = PathMod.ModPath("Strings/Languages.xml");
            List <string> codes = new List <string>();
            Dictionary <string, LanguageSetting> translations = new Dictionary <string, LanguageSetting>();

            try
            {
                if (File.Exists(path))
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load(path);
                    foreach (XmlNode xnode in xmldoc.DocumentElement.ChildNodes)
                    {
                        if (xnode.Name == "data")
                        {
                            string value  = null;
                            string name   = null;
                            var    atname = xnode.Attributes["name"];
                            if (atname != null)
                            {
                                name = atname.Value;
                            }

                            //Get value
                            XmlNode valnode = xnode.SelectSingleNode("value");
                            if (valnode != null)
                            {
                                value = valnode.InnerText;
                            }

                            List <string> fallbacks = new List <string>();
                            foreach (XmlNode fallbacknode in xnode.SelectNodes("fallback"))
                            {
                                fallbacks.Add(fallbacknode.InnerText);
                            }

                            codes.Add(name);
                            translations[name] = new LanguageSetting(value, fallbacks);
                        }
                    }
                }
                SupportedLangs = codes.ToArray();
                LangNames      = translations;
            }
            catch (Exception ex)
            {
                DiagManager.Instance.LogError(ex);
                SupportedLangs = new string[1] {
                    "en"
                };
                LangNames["en"] = new LanguageSetting("English", new List <string>());
            }
        }