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); }
public static bool SameSimpleGrammarResolverSymbols(string str1, string str2) { LanguageReportGenerator.tmpStr1Symbols.Clear(); LanguageReportGenerator.tmpStr2Symbols.Clear(); LanguageReportGenerator.CalculateSimpleGrammarResolverSymbols(str1, LanguageReportGenerator.tmpStr1Symbols); LanguageReportGenerator.CalculateSimpleGrammarResolverSymbols(str2, LanguageReportGenerator.tmpStr2Symbols); for (int i = 0; i < LanguageReportGenerator.tmpStr1Symbols.Count; i++) { if (!LanguageReportGenerator.tmpStr2Symbols.Contains(LanguageReportGenerator.tmpStr1Symbols[i])) { return(false); } } return(true); }
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); } }
private static void DoSaveTranslationReport() { LoadedLanguage activeLanguage = LanguageDatabase.activeLanguage; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Translation report for " + activeLanguage); if (activeLanguage.defInjections.Any((DefInjectionPackage x) => x.usedOldRepSyntax)) { stringBuilder.AppendLine(); stringBuilder.AppendLine("Consider using <Something.Field.Example.Etc>translation</Something.Field.Example.Etc> def-injection syntax instead of <rep>."); } try { LanguageReportGenerator.AppendGeneralLoadErrors(stringBuilder); } catch (Exception arg) { Log.Error("Error while generating translation report (general load errors): " + arg, false); } try { LanguageReportGenerator.AppendDefInjectionsLoadErros(stringBuilder); } catch (Exception arg2) { Log.Error("Error while generating translation report (def-injections load errors): " + arg2, false); } try { LanguageReportGenerator.AppendBackstoriesLoadErrors(stringBuilder); } catch (Exception arg3) { Log.Error("Error while generating translation report (backstories load errors): " + arg3, false); } try { LanguageReportGenerator.AppendMissingKeyedTranslations(stringBuilder); } catch (Exception arg4) { Log.Error("Error while generating translation report (missing keyed translations): " + arg4, false); } List <string> list = new List <string>(); try { LanguageReportGenerator.AppendMissingDefInjections(stringBuilder, list); } catch (Exception arg5) { Log.Error("Error while generating translation report (missing def-injections): " + arg5, false); } try { LanguageReportGenerator.AppendMissingBackstories(stringBuilder); } catch (Exception arg6) { Log.Error("Error while generating translation report (missing backstories): " + arg6, false); } try { LanguageReportGenerator.AppendUnnecessaryDefInjections(stringBuilder, list); } catch (Exception arg7) { Log.Error("Error while generating translation report (unnecessary def-injections): " + arg7, false); } try { LanguageReportGenerator.AppendRenamedDefInjections(stringBuilder); } catch (Exception arg8) { Log.Error("Error while generating translation report (renamed def-injections): " + arg8, false); } try { LanguageReportGenerator.AppendArgumentCountMismatches(stringBuilder); } catch (Exception arg9) { Log.Error("Error while generating translation report (argument count mismatches): " + arg9, false); } try { LanguageReportGenerator.AppendUnnecessaryKeyedTranslations(stringBuilder); } catch (Exception arg10) { Log.Error("Error while generating translation report (unnecessary keyed translations): " + arg10, false); } try { LanguageReportGenerator.AppendKeyedTranslationsMatchingEnglish(stringBuilder); } catch (Exception arg11) { Log.Error("Error while generating translation report (keyed translations matching English): " + arg11, false); } try { LanguageReportGenerator.AppendBackstoriesMatchingEnglish(stringBuilder); } catch (Exception arg12) { Log.Error("Error while generating translation report (backstories matching English): " + arg12, false); } try { LanguageReportGenerator.AppendDefInjectionsSyntaxSuggestions(stringBuilder); } catch (Exception arg13) { Log.Error("Error while generating translation report (def-injections syntax suggestions): " + arg13, false); } string text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (text.NullOrEmpty()) { text = GenFilePaths.SaveDataFolderPath; } text = Path.Combine(text, "TranslationReport.txt"); File.WriteAllText(text, stringBuilder.ToString()); Messages.Message("MessageTranslationReportSaved".Translate(new object[] { Path.GetFullPath(text) }), MessageTypeDefOf.TaskCompletion, false); }