Skip to content

Fix revolt localization when an unlocalized name is used as base #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading