コード例 #1
0
            public LanguageData(string strLanguage)
            {
                string strFilePath = Path.Combine(Application.StartupPath, "lang", strLanguage + ".xml");

                if (File.Exists(strFilePath))
                {
                    XmlDocument objLanguageDocument = new XmlDocument();
                    objLanguageDocument.Load(strFilePath);
                    if (objLanguageDocument != null)
                    {
                        foreach (XmlNode objNode in objLanguageDocument.SelectNodes("/chummer/strings/string"))
                        {
                            // Look for the English version of the found string. If it has been found, replace the English contents with the contents from this file.
                            // If the string was not found, then someone has inserted a Key that should not exist and is ignored.
                            string strKey  = objNode["key"]?.InnerText;
                            string strText = objNode["text"]?.InnerText;
                            if (!string.IsNullOrEmpty(strKey) && !string.IsNullOrEmpty(strText))
                            {
                                if (TranslatedStrings.ContainsKey(strKey))
                                {
                                    TranslatedStrings[strKey] = strText.Replace("\\n", "\n");
                                }
                                else
                                {
                                    TranslatedStrings.Add(strKey, strText.Replace("\\n", "\n"));
                                }
                            }
                        }
                    }
                    else
                    {
                        IsLoaded = false;
                    }
                }
                else
                {
                    IsLoaded = false;
                }

                // Check to see if the data translation file for the selected language exists.
                string strDataPath = Path.Combine(Application.StartupPath, "lang", strLanguage + "_data.xml");

                if (File.Exists(strDataPath))
                {
                    DataDocument.Load(strDataPath);
                }
                else
                {
                    IsLoaded = false;
                }
            }