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); }
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); }
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, false); return; } activeLanguage.LoadData(); defaultLanguage.LoadData(); if (LanguageReportGenerator.< > f__mg$cache0 == null) { LanguageReportGenerator.< > f__mg$cache0 = new Action(LanguageReportGenerator.DoSaveTranslationReport); } LongEventHandler.QueueLongEvent(LanguageReportGenerator.< > f__mg$cache0, "GeneratingTranslationReport", true, null); }
public static void CleanupTranslationFiles() { LoadedLanguage curLang = LanguageDatabase.activeLanguage; LoadedLanguage english = LanguageDatabase.defaultLanguage; if (curLang == english) { return; } IEnumerable <ModMetaData> activeModsInLoadOrder = ModsConfig.ActiveModsInLoadOrder; if (!activeModsInLoadOrder.Any((ModMetaData x) => x.IsCoreMod) || activeModsInLoadOrder.Any((ModMetaData x) => !x.Official)) { Messages.Message("MessageDisableModsBeforeCleaningTranslationFiles".Translate(), MessageTypeDefOf.RejectInput, historical: false); return; } if (LanguageDatabase.activeLanguage.AllDirectories.Any((Tuple <VirtualDirectory, ModContentPack, string> x) => x.Item1 is TarDirectory)) { Messages.Message("MessageUnpackBeforeCleaningTranslationFiles".Translate(), MessageTypeDefOf.RejectInput, historical: false); return; } LongEventHandler.QueueLongEvent(delegate { if (curLang.anyKeyedReplacementsXmlParseError || curLang.anyDefInjectionsXmlParseError) { string value = curLang.lastKeyedReplacementsXmlParseErrorInFile ?? curLang.lastDefInjectionsXmlParseErrorInFile; Messages.Message("MessageCantCleanupTranslationFilesBeucaseOfXmlError".Translate(value), MessageTypeDefOf.RejectInput, historical: false); } else { english.LoadData(); curLang.LoadData(); Dialog_MessageBox dialog_MessageBox = Dialog_MessageBox.CreateConfirmation("ConfirmCleanupTranslationFiles".Translate(curLang.FriendlyNameNative), delegate { LongEventHandler.QueueLongEvent(DoCleanupTranslationFiles, "CleaningTranslationFiles".Translate(), doAsynchronously: true, null); }, destructive: true); dialog_MessageBox.buttonAText = "ConfirmCleanupTranslationFiles_Confirm".Translate(); Find.WindowStack.Add(dialog_MessageBox); } }, null, doAsynchronously: false, null); }
public static void OutputTranslationReport() { LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage; LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage; if (activeLanguage == defaultLanguage) { Messages.Message("Please activate a non-English language to scan.", MessageTypeDefOf.RejectInput); } else { activeLanguage.LoadData(); defaultLanguage.LoadData(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Translation report for " + activeLanguage); stringBuilder.AppendLine(); stringBuilder.AppendLine("========== Argument count mismatches ========="); foreach (string item in defaultLanguage.keyedReplacements.Keys.Intersect(activeLanguage.keyedReplacements.Keys)) { int num = LanguageReportGenerator.CountParametersInString(defaultLanguage.keyedReplacements[item]); int num2 = LanguageReportGenerator.CountParametersInString(activeLanguage.keyedReplacements[item]); if (num != num2) { stringBuilder.AppendLine(string.Format("{0} - '{1}' compared to '{2}'", item, defaultLanguage.keyedReplacements[item], activeLanguage.keyedReplacements[item])); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("========== Missing keyed translations ========="); foreach (KeyValuePair <string, string> keyedReplacement in defaultLanguage.keyedReplacements) { if (!activeLanguage.HaveTextForKey(keyedReplacement.Key)) { stringBuilder.AppendLine(keyedReplacement.Key + " - '" + keyedReplacement.Value + "'"); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("========== Unnecessary keyed translations (will never be used) ========="); foreach (KeyValuePair <string, string> keyedReplacement2 in activeLanguage.keyedReplacements) { if (!defaultLanguage.HaveTextForKey(keyedReplacement2.Key)) { stringBuilder.AppendLine(keyedReplacement2.Key + " - '" + keyedReplacement2.Value + "'"); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("========== Def-injected translations missing ========="); stringBuilder.AppendLine("Note: This does NOT return any kind of sub-fields. So if there's a list of strings, or a sub-member of the def with a string in it or something, they won't be reported here."); foreach (DefInjectionPackage defInjection in activeLanguage.defInjections) { foreach (string item2 in defInjection.MissingInjections()) { stringBuilder.AppendLine(defInjection.defType.Name + ": " + item2); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("========== Backstory translations missing ========="); foreach (string item3 in BackstoryTranslationUtility.MissingBackstoryTranslations(activeLanguage)) { stringBuilder.AppendLine(item3); } Log.Message(stringBuilder.ToString()); Messages.Message("Translation report about " + activeLanguage.ToString() + " written to console. Hit ` to see it.", MessageTypeDefOf.NeutralEvent); } }