private static void AppendKeyedTranslationsMatchingEnglish(StringBuilder sb)
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;
            StringBuilder  stringBuilder   = new StringBuilder();
            int            num             = 0;

            foreach (KeyValuePair <string, string> keyValuePair in activeLanguage.keyedReplacements)
            {
                string b;
                if (defaultLanguage.TryGetTextFromKey(keyValuePair.Key, out b) && keyValuePair.Value == b)
                {
                    num++;
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        keyValuePair.Key,
                        " '",
                        keyValuePair.Value.Replace("\n", "\\n"),
                        "' (",
                        activeLanguage.GetKeySourceFileAndLine(keyValuePair.Key),
                        ")"
                    }));
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Keyed translations matching English (maybe ok) (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
        private static void AppendRenamedDefInjections(StringBuilder sb)
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();
            int            num            = 0;

            foreach (DefInjectionPackage defInjectionPackage in activeLanguage.defInjections)
            {
                foreach (Pair <string, string> pair in defInjectionPackage.autoFixedBackCompatKeys)
                {
                    string text = pair.First.Split(new char[]
                    {
                        '.'
                    })[0];
                    string text2 = pair.Second.Split(new char[]
                    {
                        '.'
                    })[0];
                    num++;
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        "Def has been renamed: ",
                        text,
                        " -> ",
                        text2,
                        ", translation ",
                        pair.First,
                        " should be renamed as well."
                    }));
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Def-injected translations using old, renamed defs (fixed automatically but can break in the next RimWorld version) (" + num + ") =========");
            sb.Append(stringBuilder);
        }
Esempio n. 3
0
        public static IEnumerable <string> FolderPaths(Verse.LoadedLanguage lang)
        {
            foreach (ModContentPack mod in LoadedModManager.RunningMods)
            {
                string        langDirPath = Path.Combine(mod.RootDir, "Languages");
                string        myDirPath   = Path.Combine(langDirPath, lang.folderName);
                DirectoryInfo myDir       = new DirectoryInfo(myDirPath);
                if (myDir.Exists)
                {
                    yield return(myDirPath);

                    continue;
                }
                //---
                myDirPath = myDirPath.Remove(myDirPath.Length - SKLangFallbackMod.LangPostfix.Length);
                myDir     = new DirectoryInfo(myDirPath);
                //Log.Warning(myDirPath);
                if (myDir.Exists)
                {
                    Log.Warning("Translation " + mod.Name + " fallback to " + myDirPath);
                    yield return(myDirPath);

                    continue;
                }
                //Log.Warning("Translation " + mod.Name + "not found");
                //---
            }
            yield break;
        }
Esempio n. 4
0
        private static void AppendRenamedDefInjections(StringBuilder sb)
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();
            int            num            = 0;

            foreach (DefInjectionPackage defInjection in activeLanguage.defInjections)
            {
                foreach (KeyValuePair <string, DefInjectionPackage.DefInjection> injection in defInjection.injections)
                {
                    if (!(injection.Value.path == injection.Value.nonBackCompatiblePath))
                    {
                        string text  = injection.Value.nonBackCompatiblePath.Split('.')[0];
                        string text2 = injection.Value.path.Split('.')[0];
                        if (text != text2)
                        {
                            stringBuilder.AppendLine("Def has been renamed: " + text + " -> " + text2 + ", translation " + injection.Value.nonBackCompatiblePath + " should be renamed as well.");
                        }
                        else
                        {
                            stringBuilder.AppendLine("Translation " + injection.Value.nonBackCompatiblePath + " should be renamed to " + injection.Value.path);
                        }
                        num++;
                    }
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Def-injected translations using old, renamed defs (fixed automatically but can break in the next RimWorld version) (" + num + ") =========");
            sb.Append(stringBuilder);
        }
        private static string GetLanguageCoreModFolderPath(LoadedLanguage language)
        {
            ModContentPack modContentPack = LoadedModManager.RunningMods.FirstOrDefault((ModContentPack x) => x.IsCoreMod);
            string         path           = Path.Combine(modContentPack.RootDir, "Languages");

            return(Path.Combine(path, language.folderName));
        }
        private static void AppendMissingKeyedTranslations(StringBuilder sb)
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;
            StringBuilder  stringBuilder   = new StringBuilder();
            int            num             = 0;

            foreach (KeyValuePair <string, string> keyValuePair in defaultLanguage.keyedReplacements)
            {
                if (!activeLanguage.HaveTextForKey(keyValuePair.Key))
                {
                    num++;
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        keyValuePair.Key,
                        " '",
                        keyValuePair.Value.Replace("\n", "\\n"),
                        "' (",
                        defaultLanguage.GetKeySourceFileAndLine(keyValuePair.Key),
                        ")"
                    }));
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Missing keyed translations (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
Esempio n. 7
0
        public static List <string> MissingBackstoryTranslations(LoadedLanguage lang)
        {
            List <KeyValuePair <string, Backstory> > list = BackstoryDatabase.allBackstories.ToList();
            List <string> list2 = new List <string>();
            string        modifiedIdentifier;
            KeyValuePair <string, Backstory> backstory;

            foreach (XElement item in BackstoryTranslationElements(lang.AllDirectories, null))
            {
                try
                {
                    string text = item.Name.ToString();
                    modifiedIdentifier = BackstoryDatabase.GetIdentifierClosestMatch(text, closestMatchWarning: false);
                    bool flag = list.Any((KeyValuePair <string, Backstory> x) => x.Key == modifiedIdentifier);
                    backstory = list.Find((KeyValuePair <string, Backstory> x) => x.Key == modifiedIdentifier);
                    if (flag)
                    {
                        list.RemoveAt(list.FindIndex((KeyValuePair <string, Backstory> x) => x.Key == backstory.Key));
                        string text2 = GetText(item, "title");
                        string text3 = GetText(item, "titleFemale");
                        string text4 = GetText(item, "titleShort");
                        string text5 = GetText(item, "titleShortFemale");
                        string text6 = GetText(item, "desc");
                        if (text2.NullOrEmpty())
                        {
                            list2.Add(text + ".title missing");
                        }
                        if (flag && !backstory.Value.titleFemale.NullOrEmpty() && text3.NullOrEmpty())
                        {
                            list2.Add(text + ".titleFemale missing");
                        }
                        if (text4.NullOrEmpty())
                        {
                            list2.Add(text + ".titleShort missing");
                        }
                        if (flag && !backstory.Value.titleShortFemale.NullOrEmpty() && text5.NullOrEmpty())
                        {
                            list2.Add(text + ".titleShortFemale missing");
                        }
                        if (text6.NullOrEmpty())
                        {
                            list2.Add(text + ".desc missing");
                        }
                    }
                    else
                    {
                        list2.Add("Translation doesn't correspond to any backstory: " + text);
                    }
                }
                catch (Exception ex)
                {
                    list2.Add(string.Concat("Exception reading ", item.Name, ": ", ex.Message));
                }
            }
            foreach (KeyValuePair <string, Backstory> item2 in list)
            {
                list2.Add("Missing backstory: " + item2.Key);
            }
            return(list2);
        }
Esempio n. 8
0
 public static void LoadAllMetadata()
 {
     foreach (ModContentPack modContentPack in LoadedModManager.RunningMods)
     {
         string        path          = Path.Combine(modContentPack.RootDir, "Languages");
         DirectoryInfo directoryInfo = new DirectoryInfo(path);
         if (directoryInfo.Exists)
         {
             foreach (DirectoryInfo langDir in directoryInfo.GetDirectories("*", SearchOption.TopDirectoryOnly))
             {
                 LanguageDatabase.LoadLanguageMetadataFrom(langDir);
             }
         }
     }
     LanguageDatabase.defaultLanguage = LanguageDatabase.languages.FirstOrDefault((LoadedLanguage la) => la.folderName == LanguageDatabase.DefaultLangFolderName);
     LanguageDatabase.activeLanguage  = LanguageDatabase.languages.FirstOrDefault((LoadedLanguage la) => la.folderName == Prefs.LangFolderName);
     if (LanguageDatabase.activeLanguage == null)
     {
         Prefs.LangFolderName            = LanguageDatabase.DefaultLangFolderName;
         LanguageDatabase.activeLanguage = LanguageDatabase.languages.FirstOrDefault((LoadedLanguage la) => la.folderName == Prefs.LangFolderName);
     }
     if (LanguageDatabase.activeLanguage == null || LanguageDatabase.defaultLanguage == null)
     {
         Log.Error("No default language found!", false);
         LanguageDatabase.defaultLanguage = LanguageDatabase.languages[0];
         LanguageDatabase.activeLanguage  = LanguageDatabase.languages[0];
     }
 }
        public static void CleanupTranslationFiles()
        {
            LoadedLanguage curLang = LanguageDatabase.activeLanguage;
            LoadedLanguage english = LanguageDatabase.defaultLanguage;

            if (curLang == english)
            {
                return;
            }
            IEnumerable <ModMetaData> activeModsInLoadOrder = ModsConfig.ActiveModsInLoadOrder;

            if (activeModsInLoadOrder.Count <ModMetaData>() != 1 || !activeModsInLoadOrder.First <ModMetaData>().IsCoreMod)
            {
                Messages.Message("MessageDisableModsBeforeCleaningTranslationFiles".Translate(), MessageTypeDefOf.RejectInput, false);
                return;
            }
            LongEventHandler.QueueLongEvent(delegate
            {
                if (curLang.anyKeyedReplacementsXmlParseError || curLang.anyDefInjectionsXmlParseError)
                {
                    string value = curLang.lastKeyedReplacementsXmlParseErrorInFile ?? curLang.lastDefInjectionsXmlParseErrorInFile;
                    Messages.Message("MessageCantCleanupTranslationFilesBeucaseOfXmlError".Translate(value), MessageTypeDefOf.RejectInput, false);
                    return;
                }
                english.LoadData();
                curLang.LoadData();
                Dialog_MessageBox dialog_MessageBox = Dialog_MessageBox.CreateConfirmation("ConfirmCleanupTranslationFiles".Translate(curLang.FriendlyNameNative), delegate
                {
                    LongEventHandler.QueueLongEvent(new Action(TranslationFilesCleaner.DoCleanupTranslationFiles), "CleaningTranslationFiles".Translate(), true, null);
                }, true, null);
                dialog_MessageBox.buttonAText = "ConfirmCleanupTranslationFiles_Confirm".Translate();
                Find.WindowStack.Add(dialog_MessageBox);
            }, null, false, null);
        }
Esempio n. 10
0
 public static void LoadAllMetadata()
 {
     foreach (ModContentPack runningMod in LoadedModManager.RunningMods)
     {
         string        path          = Path.Combine(runningMod.RootDir, "Languages");
         DirectoryInfo directoryInfo = new DirectoryInfo(path);
         if (directoryInfo.Exists)
         {
             DirectoryInfo[] directories = directoryInfo.GetDirectories("*", SearchOption.TopDirectoryOnly);
             foreach (DirectoryInfo langDir in directories)
             {
                 LoadLanguageMetadataFrom(langDir);
             }
         }
     }
     defaultLanguage = languages.FirstOrDefault((LoadedLanguage la) => la.folderName == DefaultLangFolderName);
     activeLanguage  = languages.FirstOrDefault((LoadedLanguage la) => la.folderName == Prefs.LangFolderName);
     if (activeLanguage == null)
     {
         Prefs.LangFolderName = DefaultLangFolderName;
         activeLanguage       = languages.FirstOrDefault((LoadedLanguage la) => la.folderName == Prefs.LangFolderName);
     }
     if (activeLanguage == null || defaultLanguage == null)
     {
         Log.Error("No default language found!");
         defaultLanguage = languages[0];
         activeLanguage  = languages[0];
     }
 }
Esempio n. 11
0
        private static void AppendArgumentCountMismatches(StringBuilder sb)
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;

            if (activeLanguage == defaultLanguage)
            {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = 0;

            foreach (string text in defaultLanguage.keyedReplacements.Keys.Intersect(activeLanguage.keyedReplacements.Keys))
            {
                if (!activeLanguage.keyedReplacements[text].isPlaceholder)
                {
                    int num2 = LanguageReportGenerator.CountParametersInString(defaultLanguage.keyedReplacements[text].value);
                    int num3 = LanguageReportGenerator.CountParametersInString(activeLanguage.keyedReplacements[text].value);
                    if (num2 != num3)
                    {
                        num++;
                        stringBuilder.AppendLine(string.Format("{0} ({1})\n  - '{2}'\n  - '{3}'", new object[]
                        {
                            text,
                            activeLanguage.GetKeySourceFileAndLine(text),
                            defaultLanguage.keyedReplacements[text].value.Replace("\n", "\\n"),
                            activeLanguage.keyedReplacements[text].value.Replace("\n", "\\n")
                        }));
                    }
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Argument count mismatches (may or may not be incorrect) (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
Esempio n. 12
0
        private static void AppendMissingKeyedTranslations(StringBuilder sb)
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;

            if (activeLanguage == defaultLanguage)
            {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = 0;

            foreach (KeyValuePair <string, LoadedLanguage.KeyedReplacement> keyedReplacement in defaultLanguage.keyedReplacements)
            {
                if (!activeLanguage.HaveTextForKey(keyedReplacement.Key))
                {
                    string text = keyedReplacement.Key + " '" + keyedReplacement.Value.value.Replace("\n", "\\n") + "' (English file: " + defaultLanguage.GetKeySourceFileAndLine(keyedReplacement.Key) + ")";
                    if (activeLanguage.HaveTextForKey(keyedReplacement.Key, allowPlaceholders: true))
                    {
                        text = text + " (placeholder exists in " + activeLanguage.GetKeySourceFileAndLine(keyedReplacement.Key) + ")";
                    }
                    num++;
                    stringBuilder.AppendLine(text);
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Missing keyed translations (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
Esempio n. 13
0
        private static void AppendUnnecessaryKeyedTranslations(StringBuilder sb)
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;

            if (activeLanguage == defaultLanguage)
            {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = 0;

            foreach (KeyValuePair <string, LoadedLanguage.KeyedReplacement> keyValuePair in activeLanguage.keyedReplacements)
            {
                if (!defaultLanguage.HaveTextForKey(keyValuePair.Key, false))
                {
                    num++;
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        keyValuePair.Key,
                        " '",
                        keyValuePair.Value.value.Replace("\n", "\\n"),
                        "' (",
                        activeLanguage.GetKeySourceFileAndLine(keyValuePair.Key),
                        ")"
                    }));
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Unnecessary keyed translations (will never be used) (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
 private static IEnumerable <XElement> BackstoryTranslationElements(LoadedLanguage lang)
 {
     foreach (string folderPath in lang.FolderPaths)
     {
         string   localFolderPath = folderPath;
         FileInfo fi = new FileInfo(Path.Combine(localFolderPath.ToString(), "Backstories/Backstories.xml"));
         if (!fi.Exists)
         {
             break;
         }
         XDocument doc;
         try
         {
             doc = XDocument.Load(fi.FullName);
         }
         catch (Exception ex)
         {
             Log.Warning(string.Concat(new object[]
             {
                 "Exception loading backstory translation data from file ",
                 fi,
                 ": ",
                 ex
             }));
             break;
         }
         foreach (XElement element in doc.Root.Elements())
         {
             yield return(element);
         }
     }
 }
Esempio n. 15
0
        public void LoadFrom(Tuple <VirtualDirectory, ModContentPack, string> dir, LoadedLanguage lang)
        {
            VirtualDirectory directory = dir.Item1.GetDirectory("WordInfo").GetDirectory("Gender");

            TryLoadFromFile(directory.GetFile("Male.txt"), Gender.Male, dir, lang);
            TryLoadFromFile(directory.GetFile("Female.txt"), Gender.Female, dir, lang);
            TryLoadFromFile(directory.GetFile("Neuter.txt"), Gender.None, dir, lang);
        }
Esempio n. 16
0
 public static void SelectLanguage(LoadedLanguage lang)
 {
     Prefs.LangFolderName = lang.folderName;
     LongEventHandler.QueueLongEvent(delegate()
     {
         PlayDataLoader.ClearAllPlayData();
         PlayDataLoader.LoadAllPlayData(false);
     }, "LoadingLongEvent", true, null);
 }
Esempio n. 17
0
 public static bool Prefix(Verse.LoadedLanguage __instance, ref IEnumerable <string> __result)
 {
     if (!__instance.folderName.EndsWith(SKLangFallbackMod.LangPostfix))
     {
         return(true);
     }
     __result = FolderPaths(__instance);
     return(false);
 }
Esempio n. 18
0
        private static LoadedLanguage LoadLanguageMetadataFrom(DirectoryInfo langDir)
        {
            LoadedLanguage loadedLanguage = languages.FirstOrDefault((LoadedLanguage lib) => lib.folderName == langDir.Name);

            if (loadedLanguage == null)
            {
                loadedLanguage = new LoadedLanguage(langDir.ToString());
                languages.Add(loadedLanguage);
            }
            loadedLanguage?.TryLoadMetadataFrom(langDir.ToString());
            return(loadedLanguage);
        }
Esempio n. 19
0
        private static LoadedLanguage InitLanguageMetadataFrom(VirtualDirectory langDir)
        {
            LoadedLanguage loadedLanguage = languages.FirstOrDefault((LoadedLanguage lib) => lib.folderName == langDir.Name || lib.LegacyFolderName == langDir.Name);

            if (loadedLanguage == null)
            {
                loadedLanguage = new LoadedLanguage(langDir.Name);
                languages.Add(loadedLanguage);
            }
            loadedLanguage?.InitMetadata(langDir);
            return(loadedLanguage);
        }
        public static List <string> BackstoryTranslationsMatchingEnglish(LoadedLanguage lang)
        {
            List <string> list = new List <string>();

            foreach (XElement current in BackstoryTranslationUtility.BackstoryTranslationElements(lang.FolderPaths, null))
            {
                try
                {
                    string    text = current.Name.ToString();
                    Backstory backstory;
                    if (BackstoryDatabase.allBackstories.TryGetValue(BackstoryDatabase.GetIdentifierClosestMatch(text, true), out backstory))
                    {
                        string text2 = BackstoryTranslationUtility.GetText(current, "title");
                        string text3 = BackstoryTranslationUtility.GetText(current, "titleFemale");
                        string text4 = BackstoryTranslationUtility.GetText(current, "titleShort");
                        string text5 = BackstoryTranslationUtility.GetText(current, "titleShortFemale");
                        string text6 = BackstoryTranslationUtility.GetText(current, "desc");
                        if (!text2.NullOrEmpty() && text2 == backstory.untranslatedTitle)
                        {
                            list.Add(text + ".title '" + text2.Replace("\n", "\\n") + "'");
                        }
                        if (!text3.NullOrEmpty() && text3 == backstory.untranslatedTitleFemale)
                        {
                            list.Add(text + ".titleFemale '" + text3.Replace("\n", "\\n") + "'");
                        }
                        if (!text4.NullOrEmpty() && text4 == backstory.untranslatedTitleShort)
                        {
                            list.Add(text + ".titleShort '" + text4.Replace("\n", "\\n") + "'");
                        }
                        if (!text5.NullOrEmpty() && text5 == backstory.untranslatedTitleShortFemale)
                        {
                            list.Add(text + ".titleShortFemale '" + text5.Replace("\n", "\\n") + "'");
                        }
                        if (!text6.NullOrEmpty() && text6 == backstory.untranslatedDesc)
                        {
                            list.Add(text + ".desc '" + text6.Replace("\n", "\\n") + "'");
                        }
                    }
                }
                catch (Exception ex)
                {
                    list.Add(string.Concat(new object[]
                    {
                        "Exception reading ",
                        current.Name,
                        ": ",
                        ex.Message
                    }));
                }
            }
            return(list);
        }
        public static IEnumerable <string> MissingBackstoryTranslations(LoadedLanguage lang)
        {
            List <string> neededTranslations = (from kvp in BackstoryDatabase.allBackstories
                                                select kvp.Key).ToList();

            foreach (XElement item in BackstoryTranslationUtility.BackstoryTranslationElements(lang))
            {
                string identifier = item.Name.ToString();
                if (neededTranslations.Contains(identifier))
                {
                    neededTranslations.Remove(identifier);
                    string title      = item.Element("title").Value;
                    string titleShort = item.Element("titleShort").Value;
                    string desc       = item.Element("desc").Value;
                    if (title.NullOrEmpty())
                    {
                        yield return(identifier + ".title missing");

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                    if (titleShort.NullOrEmpty())
                    {
                        yield return(identifier + ".titleShort missing");

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                    if (desc.NullOrEmpty())
                    {
                        yield return(identifier + ".desc missing");

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                    continue;
                }
                yield return("Translation doesn't correspond to any backstory: " + identifier);

                /*Error: Unable to find new state assignment for yield return*/;
            }
            using (List <string> .Enumerator enumerator2 = neededTranslations.GetEnumerator())
            {
                if (enumerator2.MoveNext())
                {
                    string tra = enumerator2.Current;
                    yield return("Missing backstory: " + tra);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_02fa:
            /*Error near IL_02fb: Unexpected return in MoveNext()*/;
        }
 public static void LoadAndInjectBackstoryData(LoadedLanguage lang)
 {
     foreach (XElement current in BackstoryTranslationUtility.BackstoryTranslationElements(lang))
     {
         string text = "[unknown]";
         try
         {
             text = current.Name.ToString();
             string    value  = current.Element("title").Value;
             string    value2 = current.Element("titleShort").Value;
             string    value3 = current.Element("desc").Value;
             Backstory backstory;
             if (!BackstoryDatabase.TryGetWithIdentifier(text, out backstory))
             {
                 throw new Exception("Backstory not found matching identifier " + text);
             }
             if (value == backstory.Title && value2 == backstory.TitleShort && value3 == backstory.baseDesc)
             {
                 Log.Error("Backstory translation exactly matches default data: " + text);
             }
             else
             {
                 if (value != null)
                 {
                     backstory.SetTitle(value);
                 }
                 if (value2 != null)
                 {
                     backstory.SetTitleShort(value2);
                 }
                 if (value3 != null)
                 {
                     backstory.baseDesc = value3;
                 }
             }
         }
         catch (Exception ex)
         {
             Log.Warning(string.Concat(new object[]
             {
                 "Couldn't load backstory ",
                 text,
                 ": ",
                 ex,
                 "\nFull XML text:\n\n",
                 current.ToString()
             }));
         }
     }
 }
Esempio n. 23
0
        public static void SaveTranslationReport()
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;

            if (activeLanguage == defaultLanguage && !defaultLanguage.anyError)
            {
                Messages.Message("Please activate a non-English language to scan.", MessageTypeDefOf.RejectInput, historical: false);
                return;
            }
            activeLanguage.LoadData();
            defaultLanguage.LoadData();
            LongEventHandler.QueueLongEvent(DoSaveTranslationReport, "GeneratingTranslationReport", doAsynchronously: true, null);
        }
        private static void AppendMissingBackstories(StringBuilder sb)
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();
            int            num            = 0;

            foreach (string value in BackstoryTranslationUtility.MissingBackstoryTranslations(activeLanguage))
            {
                num++;
                stringBuilder.AppendLine(value);
            }
            sb.AppendLine();
            sb.AppendLine("========== Backstory translations missing (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
Esempio n. 25
0
        private static void AppendGeneralLoadErrors(StringBuilder sb)
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();
            int            num            = 0;

            foreach (string loadError in activeLanguage.loadErrors)
            {
                num++;
                stringBuilder.AppendLine(loadError);
            }
            sb.AppendLine();
            sb.AppendLine("========== General load errors (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
        private static void AppendBackstoriesMatchingEnglish(StringBuilder sb)
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();
            int            num            = 0;

            foreach (string value in BackstoryTranslationUtility.BackstoryTranslationsMatchingEnglish(activeLanguage))
            {
                num++;
                stringBuilder.AppendLine(value);
            }
            sb.AppendLine();
            sb.AppendLine("========== Backstory translations matching English (maybe ok) (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
Esempio n. 27
0
        private static void AppendBackstoriesLoadErrors(StringBuilder sb)
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();
            int            num            = 0;

            foreach (string backstoriesLoadError in activeLanguage.backstoriesLoadErrors)
            {
                num++;
                stringBuilder.AppendLine(backstoriesLoadError);
            }
            sb.AppendLine();
            sb.AppendLine("========== Backstories load errors (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
Esempio n. 28
0
        public static List <string> BackstoryTranslationsMatchingEnglish(LoadedLanguage lang)
        {
            List <string> list = new List <string>();

            foreach (XElement item in BackstoryTranslationElements(lang.AllDirectories, null))
            {
                try
                {
                    string text = item.Name.ToString();
                    if (BackstoryDatabase.allBackstories.TryGetValue(BackstoryDatabase.GetIdentifierClosestMatch(text), out var value))
                    {
                        string text2 = GetText(item, "title");
                        string text3 = GetText(item, "titleFemale");
                        string text4 = GetText(item, "titleShort");
                        string text5 = GetText(item, "titleShortFemale");
                        string text6 = GetText(item, "desc");
                        if (!text2.NullOrEmpty() && text2 == value.untranslatedTitle)
                        {
                            list.Add(text + ".title '" + text2.Replace("\n", "\\n") + "'");
                        }
                        if (!text3.NullOrEmpty() && text3 == value.untranslatedTitleFemale)
                        {
                            list.Add(text + ".titleFemale '" + text3.Replace("\n", "\\n") + "'");
                        }
                        if (!text4.NullOrEmpty() && text4 == value.untranslatedTitleShort)
                        {
                            list.Add(text + ".titleShort '" + text4.Replace("\n", "\\n") + "'");
                        }
                        if (!text5.NullOrEmpty() && text5 == value.untranslatedTitleShortFemale)
                        {
                            list.Add(text + ".titleShortFemale '" + text5.Replace("\n", "\\n") + "'");
                        }
                        if (!text6.NullOrEmpty() && text6 == value.untranslatedDesc)
                        {
                            list.Add(text + ".desc '" + text6.Replace("\n", "\\n") + "'");
                        }
                    }
                }
                catch (Exception ex)
                {
                    list.Add(string.Concat("Exception reading ", item.Name, ": ", ex.Message));
                }
            }
            return(list);
        }
Esempio n. 29
0
        private static void AppendRenamedDefInjections(StringBuilder sb)
        {
            LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage;
            StringBuilder  stringBuilder  = new StringBuilder();
            int            num            = 0;

            foreach (DefInjectionPackage current in activeLanguage.defInjections)
            {
                foreach (KeyValuePair <string, DefInjectionPackage.DefInjection> current2 in current.injections)
                {
                    if (!(current2.Value.path == current2.Value.nonBackCompatiblePath))
                    {
                        string text = current2.Value.nonBackCompatiblePath.Split(new char[]
                        {
                            '.'
                        })[0];
                        string text2 = current2.Value.path.Split(new char[]
                        {
                            '.'
                        })[0];
                        if (text != text2)
                        {
                            stringBuilder.AppendLine(string.Concat(new string[]
                            {
                                "Def has been renamed: ",
                                text,
                                " -> ",
                                text2,
                                ", translation ",
                                current2.Value.nonBackCompatiblePath,
                                " should be renamed as well."
                            }));
                        }
                        else
                        {
                            stringBuilder.AppendLine("Translation " + current2.Value.nonBackCompatiblePath + " should be renamed to " + current2.Value.path);
                        }
                        num++;
                    }
                }
            }
            sb.AppendLine();
            sb.AppendLine("========== Def-injected translations using old, renamed defs (fixed automatically but can break in the next RimWorld version) (" + num + ") =========");
            sb.Append(stringBuilder);
        }
Esempio n. 30
0
 public static void InitAllMetadata()
 {
     foreach (ModContentPack runningMod in LoadedModManager.RunningMods)
     {
         HashSet <string> hashSet = new HashSet <string>();
         foreach (string item2 in runningMod.foldersToLoadDescendingOrder)
         {
             string text = Path.Combine(item2, "Languages");
             if (new DirectoryInfo(text).Exists)
             {
                 foreach (VirtualDirectory directory in AbstractFilesystem.GetDirectories(text, "*", SearchOption.TopDirectoryOnly))
                 {
                     if (!directory.FullPath.StartsWith(text))
                     {
                         Log.Error("Failed to get a relative path for a file: " + directory.FullPath + ", located in " + text);
                     }
                     else
                     {
                         string item = directory.FullPath.Substring(text.Length);
                         if (!hashSet.Contains(item))
                         {
                             InitLanguageMetadataFrom(directory);
                             hashSet.Add(item);
                         }
                     }
                 }
             }
         }
     }
     languages.SortBy((LoadedLanguage l) => l.folderName);
     defaultLanguage = languages.FirstOrDefault((LoadedLanguage la) => la.folderName == DefaultLangFolderName);
     activeLanguage  = languages.FirstOrDefault((LoadedLanguage la) => la.folderName == Prefs.LangFolderName);
     if (activeLanguage == null)
     {
         Prefs.LangFolderName = DefaultLangFolderName;
         activeLanguage       = languages.FirstOrDefault((LoadedLanguage la) => la.folderName == Prefs.LangFolderName);
     }
     if (activeLanguage == null || defaultLanguage == null)
     {
         Log.Error("No default language found!");
         defaultLanguage = languages[0];
         activeLanguage  = languages[0];
     }
     activeLanguage.LoadMetadata();
 }