Skip to content

Commit

Permalink
Fix revolt localization when an unlocalized name is used as base (#2163
Browse files Browse the repository at this point in the history
…) #patch

Example:
```
			country_name={
				name="CIVILWAR_FACTION_NAME"
				adjective="CIVILWAR_FACTION_ADJECTIVE"
				base={
					name="Tamilakam"
				}
			}
```
  • Loading branch information
IhateTrains authored Sep 9, 2024
1 parent 90f6310 commit 0cb6eb0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
27 changes: 27 additions & 0 deletions ImperatorToCK3.UnitTests/Imperator/Countries/CountryNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,31 @@ public void ProvinceNameCanBeUsedForRevoltTagNameAndAdjective() {
Assert.Equal("Nikonia Revolt", countryName.GetNameLocBlock(locDB, [])!["english"]);
Assert.Equal("Nikonia", countryName.GetAdjectiveLocBlock(locDB, [])!["english"]);
}

[Fact]
public void RawBaseNameCanBeUsedForRevoltTagNameAndAdjective() {
var reader = new BufferedReader(
"""
name="CIVILWAR_FACTION_NAME"
adjective="CIVILWAR_FACTION_ADJECTIVE"
base={
name="Tamilakam"
}
""");
var countryName = CountryName.Parse(reader);

var locDB = new LocDB("english", "french");
var civilWarLocBlock = locDB.AddLocBlock("CIVILWAR_FACTION_NAME");
civilWarLocBlock["english"] = "$ADJ$ Revolt";
civilWarLocBlock["french"] = "Rébellion $ADJ$";
var civilWarAdjLocBlock = locDB.AddLocBlock("CIVILWAR_FACTION_ADJECTIVE");
civilWarAdjLocBlock["english"] = "$ADJ$";
civilWarAdjLocBlock["french"] = "$ADJ$";

Assert.Equal("Tamilakam Revolt", countryName.GetNameLocBlock(locDB, [])!["english"]);
Assert.Equal("Tamilakam", countryName.GetAdjectiveLocBlock(locDB, [])!["english"]);

Assert.Equal("Rébellion Tamilakam", countryName.GetNameLocBlock(locDB, [])!["french"]);
Assert.Equal("Tamilakam", countryName.GetAdjectiveLocBlock(locDB, [])!["french"]);
}
}
18 changes: 17 additions & 1 deletion ImperatorToCK3/Imperator/Countries/CountryName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ public object Clone() {
var baseAdjLoc = BaseName.GetAdjectiveLocBlock(irLocDB, imperatorCountries) ??
BaseName.GetNameLocBlock(irLocDB, imperatorCountries);
if (baseAdjLoc is null) {
return directNameLocMatch;
// If the base name only has an unlocalized name, use it.
baseAdjLoc = new LocBlock(BaseName.Name, ConverterGlobals.PrimaryLanguage) {
[ConverterGlobals.PrimaryLanguage] = BaseName.Name,
};
foreach (var language in ConverterGlobals.SecondaryLanguages) {
baseAdjLoc[language] = BaseName.Name;
}
}

var locBlockToReturn = new LocBlock(Name, directNameLocMatch);
Expand Down Expand Up @@ -86,6 +92,16 @@ private LocBlock GetCompositeNameLocBlock(string[] nameParts, LocDB irLocDB) {
// If the BaseName only has a name and no adjective, use the name.
var baseAdjLoc = BaseName?.GetAdjectiveLocBlock(irLocDB, imperatorCountries) ??
BaseName?.GetNameLocBlock(irLocDB, imperatorCountries);
// If neither localized adjective nor name is found, use the unlocalized name.
if (baseAdjLoc is null && BaseName is not null) {
baseAdjLoc = new LocBlock(BaseName.Name, ConverterGlobals.PrimaryLanguage) {
[ConverterGlobals.PrimaryLanguage] = BaseName.Name,
};
foreach (var language in ConverterGlobals.SecondaryLanguages) {
baseAdjLoc[language] = BaseName.Name;
}
}

if (baseAdjLoc is not null) {
var locBlockToReturn = new LocBlock(adjKey, directAdjLocMatch);
locBlockToReturn.ModifyForEveryLanguage(baseAdjLoc, (orig, modifying, language) => {
Expand Down

0 comments on commit 0cb6eb0

Please sign in to comment.