From 04b11732f8041a87e6c10264636490422c266441 Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Thu, 11 Jul 2024 10:39:36 +0100 Subject: [PATCH] Fix French loc for converted Seleucid and Mayra empires (#2068) #minor --- ImperatorToCK3/CK3/Titles/Title.cs | 60 +++++++++++++++---- .../Outputter/LocalizationOutputter.cs | 2 +- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/ImperatorToCK3/CK3/Titles/Title.cs b/ImperatorToCK3/CK3/Titles/Title.cs index 501814ff2..b4b859753 100644 --- a/ImperatorToCK3/CK3/Titles/Title.cs +++ b/ImperatorToCK3/CK3/Titles/Title.cs @@ -365,10 +365,16 @@ internal void RemoveDeFactoLiegeReferences(string liegeName) { var modifiedPrylocBlockToReturn = new LocBlock(pryLocKey, pryLocBlock); const string pryNameKey = "PRY"; modifiedPrylocBlockToReturn.ModifyForEveryLanguage( - irLocDB.GetLocBlockForKey(pryNameKey) ?? new LocBlock(pryNameKey, ConverterGlobals.PrimaryLanguage) { + otherBlock: irLocDB.GetLocBlockForKey(pryNameKey) ?? new LocBlock(pryNameKey, ConverterGlobals.PrimaryLanguage) { [ConverterGlobals.PrimaryLanguage] = "Antigonid Kingdom" }, - (loc, modifyingLoc, _) => loc?.Replace($"${pryNameKey}$", modifyingLoc)); + (loc, modifyingLoc, language) => { + var locToReturn = loc?.Replace($"${pryNameKey}$", modifyingLoc); + if (locToReturn is not null && locToReturn.Contains("[GetCountry(")) { + locToReturn = irLocDB.GetLocBlockForKey("get_pry_name_fallback")?[language]; + } + return locToReturn; + }); return modifiedPrylocBlockToReturn; case "PRY_DYN": return irLocDB.GetLocBlockForKey("get_pry_name_fallback"); @@ -382,10 +388,16 @@ internal void RemoveDeFactoLiegeReferences(string liegeName) { var modifiedSelLocBlockToReturn = new LocBlock(selLocKey, selLocBlock); const string selNameKey = "SEL"; modifiedSelLocBlockToReturn.ModifyForEveryLanguage( - irLocDB.GetLocBlockForKey(selNameKey) ?? new LocBlock(selNameKey, ConverterGlobals.PrimaryLanguage) { + otherBlock: irLocDB.GetLocBlockForKey(selNameKey) ?? new LocBlock(selNameKey, ConverterGlobals.PrimaryLanguage) { [ConverterGlobals.PrimaryLanguage] = "Seleukid Empire" }, - (loc, modifyingLoc, _) => loc?.Replace($"${selNameKey}$", modifyingLoc)); + (loc, modifyingLoc, language) => { + var locToReturn = loc?.Replace($"${selNameKey}$", modifyingLoc); + if (locToReturn is not null && locToReturn.Contains("[GetCountry(")) { + locToReturn = irLocDB.GetLocBlockForKey("get_sel_name_fallback")?[language]; + } + return locToReturn; + }); return modifiedSelLocBlockToReturn; case "SEL_DYN": return irLocDB.GetLocBlockForKey("get_sel_name_fallback"); @@ -399,10 +411,16 @@ internal void RemoveDeFactoLiegeReferences(string liegeName) { var modifiedMryLocBlockToReturn = new LocBlock(mryLocKey, mryLocBlock); const string mryNameKey = "MRY"; modifiedMryLocBlockToReturn.ModifyForEveryLanguage( - irLocDB.GetLocBlockForKey(mryNameKey) ?? new LocBlock(mryNameKey, ConverterGlobals.PrimaryLanguage) { + otherBlock: irLocDB.GetLocBlockForKey(mryNameKey) ?? new LocBlock(mryNameKey, ConverterGlobals.PrimaryLanguage) { [ConverterGlobals.PrimaryLanguage] = "Maurya" }, - (loc, modifyingLoc, _) => loc?.Replace($"${mryNameKey}$", modifyingLoc)); + (loc, modifyingLoc, language) => { + var locToReturn = loc?.Replace($"${mryNameKey}$", modifyingLoc); + if (locToReturn is not null && locToReturn.Contains("[GetCountry(")) { + locToReturn = irLocDB.GetLocBlockForKey("get_mry_name_fallback")?[language]; + } + return locToReturn; + }); return modifiedMryLocBlockToReturn; case "MRY_DYN": return irLocDB.GetLocBlockForKey("get_mry_name_fallback"); @@ -731,10 +749,16 @@ private void TrySetAdjectiveLoc(LocDB irLocDB, CountryCollection imperatorCountr const string pryAdjKey = "PRY_ADJ"; validatedAdj = new LocBlock(pryAdjLocBlock.Id, pryAdjLocBlock); validatedAdj.ModifyForEveryLanguage( - irLocDB.GetLocBlockForKey(pryAdjKey) ?? new LocBlock(pryAdjKey, ConverterGlobals.PrimaryLanguage) { + otherBlock: irLocDB.GetLocBlockForKey(pryAdjKey) ?? new LocBlock(pryAdjKey, ConverterGlobals.PrimaryLanguage) { [ConverterGlobals.PrimaryLanguage] = "Antigonid" }, - (loc, modifyingLoc, _) => loc?.Replace($"${pryAdjKey}$", modifyingLoc)); + (loc, modifyingLoc, language) => { + var locToReturn = loc?.Replace($"${pryAdjKey}$", modifyingLoc); + if (locToReturn is not null && locToReturn.Contains("[GetCountry(")) { + locToReturn = irLocDB.GetLocBlockForKey("get_pry_adj_fallback")?[language]; + } + return locToReturn; + }); } else { validatedAdj = pryAdjLocBlock; } @@ -749,10 +773,16 @@ private void TrySetAdjectiveLoc(LocDB irLocDB, CountryCollection imperatorCountr const string selAdjKey = "SEL_ADJ"; validatedAdj = new LocBlock(selAdjLocBlock.Id, selAdjLocBlock); validatedAdj.ModifyForEveryLanguage( - irLocDB.GetLocBlockForKey(selAdjKey) ?? new LocBlock(selAdjKey, ConverterGlobals.PrimaryLanguage) { + otherBlock: irLocDB.GetLocBlockForKey(selAdjKey) ?? new LocBlock(selAdjKey, ConverterGlobals.PrimaryLanguage) { [ConverterGlobals.PrimaryLanguage] = "Seleukid" }, - (loc, modifyingLoc, _) => loc?.Replace($"${selAdjKey}$", modifyingLoc)); + (loc, modifyingLoc, language) => { + var locToReturn = loc?.Replace($"${selAdjKey}$", modifyingLoc); + if (locToReturn is not null && locToReturn.Contains("[GetCountry(")) { + locToReturn = irLocDB.GetLocBlockForKey("get_sel_adj_fallback")?[language]; + } + return locToReturn; + }); } else { validatedAdj = selAdjLocBlock; } @@ -767,10 +797,16 @@ private void TrySetAdjectiveLoc(LocDB irLocDB, CountryCollection imperatorCountr const string mryAdjKey = "MRY_ADJ"; validatedAdj = new LocBlock(mryAdjLocBlock.Id, mryAdjLocBlock); validatedAdj.ModifyForEveryLanguage( - irLocDB.GetLocBlockForKey(mryAdjKey) ?? new LocBlock(mryAdjKey, ConverterGlobals.PrimaryLanguage) { + otherBlock: irLocDB.GetLocBlockForKey(mryAdjKey) ?? new LocBlock(mryAdjKey, ConverterGlobals.PrimaryLanguage) { [ConverterGlobals.PrimaryLanguage] = "Mauryan" }, - (loc, modifyingLoc, _) => loc?.Replace($"${mryAdjKey}$", modifyingLoc)); + (loc, modifyingLoc, language) => { + var locToReturn = loc?.Replace($"${mryAdjKey}$", modifyingLoc); + if (locToReturn is not null && locToReturn.Contains("[GetCountry(")) { + locToReturn = irLocDB.GetLocBlockForKey("get_mry_adj_fallback")?[language]; + } + return locToReturn; + }); } else { validatedAdj = mryAdjLocBlock; } diff --git a/ImperatorToCK3/Outputter/LocalizationOutputter.cs b/ImperatorToCK3/Outputter/LocalizationOutputter.cs index 881ddd3c1..eb6273ea0 100644 --- a/ImperatorToCK3/Outputter/LocalizationOutputter.cs +++ b/ImperatorToCK3/Outputter/LocalizationOutputter.cs @@ -44,7 +44,7 @@ private static void OutputFallbackLocForMissingSecondaryLanguageLoc(string baseL languageToLocLinesDict[language] = []; } - var allLocKeys = ck3LocDB.Select(locBlock => locBlock.Id).ToHashSet(); + var allLocKeys = ck3LocDB.Select(locBlock => locBlock.Id).Distinct().ToArray(); foreach (var locKey in allLocKeys) { if (!ck3LocDB.HasKeyLocForLanguage(locKey, ConverterGlobals.PrimaryLanguage)) {