示例#1
0
        public void InjectIntoData_AfterImpliedDefs()
        {
            if (!this.dataIsLoaded)
            {
                this.LoadData();
            }
            int num = this.loadErrors.Count;

            foreach (DefInjectionPackage current in this.defInjections)
            {
                try
                {
                    current.InjectIntoDefs(true);
                    num += current.loadErrors.Count;
                }
                catch (Exception arg)
                {
                    Log.Error("Critical error while injecting translations into defs: " + arg, false);
                }
            }
            BackstoryTranslationUtility.LoadAndInjectBackstoryData(this.FolderPaths, this.backstoriesLoadErrors);
            num += this.backstoriesLoadErrors.Count;
            if (num != 0)
            {
                this.anyError = true;
                Log.Warning(string.Concat(new object[]
                {
                    "Translation data for language ",
                    LanguageDatabase.activeLanguage.FriendlyNameEnglish,
                    " has ",
                    num,
                    " errors. Generate translation report for more info."
                }), false);
            }
        }
        public void InjectIntoData_AfterImpliedDefs()
        {
            if (!dataIsLoaded)
            {
                LoadData();
            }
            int num = loadErrors.Count;

            foreach (DefInjectionPackage defInjection in defInjections)
            {
                try
                {
                    defInjection.InjectIntoDefs(errorOnDefNotFound: true);
                    num += defInjection.loadErrors.Count;
                }
                catch (Exception arg)
                {
                    Log.Error("Critical error while injecting translations into defs: " + arg);
                }
            }
            BackstoryTranslationUtility.LoadAndInjectBackstoryData(AllDirectories, backstoriesLoadErrors);
            num += backstoriesLoadErrors.Count;
            if (num != 0)
            {
                anyError = true;
                Log.Warning("Translation data for language " + LanguageDatabase.activeLanguage.FriendlyNameEnglish + " has " + num + " errors. Generate translation report for more info.");
            }
        }
 public static void LoadAndInjectBackstoryData(IEnumerable <string> folderPaths, List <string> loadErrors)
 {
     foreach (XElement xelement in BackstoryTranslationUtility.BackstoryTranslationElements(folderPaths, loadErrors))
     {
         string text = "[unknown]";
         try
         {
             text = xelement.Name.ToString();
             string    value  = xelement.Element("title").Value;
             string    text2  = (xelement.Element("titleFemale") == null) ? null : xelement.Element("titleFemale").Value;
             string    value2 = xelement.Element("titleShort").Value;
             string    text3  = (xelement.Element("titleShortFemale") == null) ? null : xelement.Element("titleShortFemale").Value;
             string    value3 = xelement.Element("desc").Value;
             Backstory backstory;
             if (!BackstoryDatabase.TryGetWithIdentifier(text, out backstory, false))
             {
                 throw new Exception("Backstory not found matching identifier " + text);
             }
             if (value == backstory.title && text2 == backstory.titleFemale && value2 == backstory.titleShort && text3 == backstory.titleShortFemale && value3 == backstory.baseDesc)
             {
                 throw new Exception("Backstory translation exactly matches default data: " + text);
             }
             if (value != null)
             {
                 backstory.SetTitle(value, backstory.titleFemale);
             }
             if (text2 != null)
             {
                 backstory.SetTitle(backstory.title, text2);
             }
             if (value2 != null)
             {
                 backstory.SetTitleShort(value2, backstory.titleShortFemale);
             }
             if (text3 != null)
             {
                 backstory.SetTitleShort(backstory.titleShort, text3);
             }
             if (value3 != null)
             {
                 backstory.baseDesc = value3;
             }
         }
         catch (Exception ex)
         {
             loadErrors.Add(string.Concat(new object[]
             {
                 "Couldn't load backstory ",
                 text,
                 ": ",
                 ex,
                 "\nFull XML text:\n\n",
                 xelement.ToString()
             }));
         }
     }
 }
 public void InjectIntoData()
 {
     if (!this.dataIsLoaded)
     {
         this.LoadData();
     }
     foreach (DefInjectionPackage defInjection in this.defInjections)
     {
         defInjection.InjectIntoDefs();
     }
     BackstoryTranslationUtility.LoadAndInjectBackstoryData(this);
 }
        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()
             }));
         }
     }
 }
        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);
        }
        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);
        }
示例#10
0
        private static void AppendMissingBackstories(StringBuilder sb)
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;

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

            foreach (string item in BackstoryTranslationUtility.MissingBackstoryTranslations(activeLanguage))
            {
                num++;
                stringBuilder.AppendLine(item);
            }
            sb.AppendLine();
            sb.AppendLine("========== Backstory translations missing (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
示例#11
0
        private static void AppendBackstoriesMatchingEnglish(StringBuilder sb)
        {
            LoadedLanguage activeLanguage  = LanguageDatabase.activeLanguage;
            LoadedLanguage defaultLanguage = LanguageDatabase.defaultLanguage;

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

            foreach (string current in BackstoryTranslationUtility.BackstoryTranslationsMatchingEnglish(activeLanguage))
            {
                num++;
                stringBuilder.AppendLine(current);
            }
            sb.AppendLine();
            sb.AppendLine("========== Backstory translations matching English (maybe ok) (" + num + ") ==========");
            sb.Append(stringBuilder);
        }
        public static IEnumerable <string> MissingBackstoryTranslations(LoadedLanguage lang)
        {
            List <string> neededTranslations = (from kvp in BackstoryDatabase.allBackstories
                                                select kvp.Key).ToList <string>();

            foreach (XElement element in BackstoryTranslationUtility.BackstoryTranslationElements(lang))
            {
                string identifier = element.Name.ToString();
                if (neededTranslations.Contains(identifier))
                {
                    neededTranslations.Remove(identifier);
                }
                else
                {
                    yield return("Translation doesn't correspond to any backstory: " + identifier);
                }
                string title      = element.Element("title").Value;
                string titleShort = element.Element("titleShort").Value;
                string desc       = element.Element("desc").Value;
                if (title.NullOrEmpty())
                {
                    yield return(identifier + ".title missing");
                }
                if (titleShort.NullOrEmpty())
                {
                    yield return(identifier + ".titleShort missing");
                }
                if (desc.NullOrEmpty())
                {
                    yield return(identifier + ".desc missing");
                }
            }
            foreach (string tra in neededTranslations)
            {
                yield return("Missing backstory: " + tra);
            }
        }
        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);
            }
        }
 public static void LoadAndInjectBackstoryData(IEnumerable <string> folderPaths, List <string> loadErrors)
 {
     foreach (XElement current in BackstoryTranslationUtility.BackstoryTranslationElements(folderPaths, loadErrors))
     {
         string text = "[unknown]";
         try
         {
             text = current.Name.ToString();
             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");
             Backstory backstory;
             if (!BackstoryDatabase.TryGetWithIdentifier(text, out backstory, false))
             {
                 throw new Exception("Backstory not found matching identifier " + text);
             }
             if (text2 == backstory.title && text3 == backstory.titleFemale && text4 == backstory.titleShort && text5 == backstory.titleShortFemale && text6 == backstory.baseDesc)
             {
                 throw new Exception("Backstory translation exactly matches default data: " + text);
             }
             if (text2 != null)
             {
                 backstory.SetTitle(text2, backstory.titleFemale);
                 backstory.titleTranslated = true;
             }
             if (text3 != null)
             {
                 backstory.SetTitle(backstory.title, text3);
                 backstory.titleFemaleTranslated = true;
             }
             if (text4 != null)
             {
                 backstory.SetTitleShort(text4, backstory.titleShortFemale);
                 backstory.titleShortTranslated = true;
             }
             if (text5 != null)
             {
                 backstory.SetTitleShort(backstory.titleShort, text5);
                 backstory.titleShortFemaleTranslated = true;
             }
             if (text6 != null)
             {
                 backstory.baseDesc       = text6;
                 backstory.descTranslated = true;
             }
         }
         catch (Exception ex)
         {
             loadErrors.Add(string.Concat(new string[]
             {
                 "Couldn't load backstory ",
                 text,
                 ": ",
                 ex.Message,
                 "\nFull XML text:\n\n",
                 current.ToString()
             }));
         }
     }
 }
        public static List <string> MissingBackstoryTranslations(LoadedLanguage lang)
        {
            List <KeyValuePair <string, Backstory> > list = BackstoryDatabase.allBackstories.ToList <KeyValuePair <string, Backstory> >();
            List <string> list2 = new List <string>();

            foreach (XElement current in BackstoryTranslationUtility.BackstoryTranslationElements(lang.FolderPaths, null))
            {
                try
                {
                    string text = current.Name.ToString();
                    string modifiedIdentifier = BackstoryDatabase.GetIdentifierClosestMatch(text, false);
                    bool   flag = list.Any((KeyValuePair <string, Backstory> x) => x.Key == modifiedIdentifier);
                    KeyValuePair <string, Backstory> 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 = 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())
                        {
                            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(new object[]
                    {
                        "Exception reading ",
                        current.Name,
                        ": ",
                        ex.Message
                    }));
                }
            }
            foreach (KeyValuePair <string, Backstory> current2 in list)
            {
                list2.Add("Missing backstory: " + current2.Key);
            }
            return(list2);
        }