Skip to content

Commit

Permalink
Prevent a lot of cases of character name loc redefinition (#1931) #patch
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored May 3, 2024
1 parent 6f5f56a commit 6b196ee
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
3 changes: 2 additions & 1 deletion ImperatorToCK3.UnitTests/CK3/Characters/CK3CharacterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public Character Build() {
deathReasonMapper,
DNAFactory,
new Date(867, 1, 1),
config
config,
unlocalizedImperatorNames: new HashSet<string>()
);
return character;
}
Expand Down
4 changes: 3 additions & 1 deletion ImperatorToCK3.UnitTests/CK3/Dynasties/DynastyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Xunit;
using Character = ImperatorToCK3.CK3.Characters.Character;
using System;
using System.Collections.Generic;
using CharacterCollection = ImperatorToCK3.Imperator.Characters.CharacterCollection;

// ReSharper disable StringLiteralTypo
Expand Down Expand Up @@ -86,7 +87,8 @@ public Character Build() {
deathReasonMapper,
new DNAFactory(IRModFS, ck3ModFS),
new Date(867, 1, 1),
config
config,
unlocalizedImperatorNames: new HashSet<string>()
);
return character;
}
Expand Down
4 changes: 3 additions & 1 deletion ImperatorToCK3/CK3/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ public Character(
DeathReasonMapper deathReasonMapper,
DNAFactory dnaFactory,
Date dateOnConversion,
Configuration config
Configuration config,
ISet<string> unlocalizedImperatorNames
) {
this.characters = characters;

Expand Down Expand Up @@ -341,6 +342,7 @@ Configuration config
if (matchedLocBlock is not null) {
Localizations.Add(name, matchedLocBlock);
} else { // fallback: use unlocalized name as displayed name
unlocalizedImperatorNames.Add(name);
var locBlock = new LocBlock(name, ConverterGlobals.PrimaryLanguage) {
[ConverterGlobals.PrimaryLanguage] = nameLoc
};
Expand Down
14 changes: 10 additions & 4 deletions ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using ImperatorToCK3.Mappers.Religion;
using ImperatorToCK3.Mappers.Trait;
using ImperatorToCK3.Mappers.UnitType;
using Open.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
Expand All @@ -38,6 +39,8 @@ Configuration config
) {
Logger.Info("Importing Imperator Characters...");

var unlocalizedImperatorNames = new ConcurrentHashSet<string>();

Parallel.ForEach(impWorld.Characters, irCharacter => {
ImportImperatorCharacter(
irCharacter,
Expand All @@ -51,9 +54,11 @@ Configuration config
deathReasonMapper,
dnaFactory,
conversionDate,
config
config,
unlocalizedImperatorNames
);
});
Logger.Warn("Found unlocalized Imperator names: " + string.Join(", ", unlocalizedImperatorNames));
Logger.Info($"Imported {impWorld.Characters.Count} characters.");

LinkMothersAndFathers();
Expand Down Expand Up @@ -83,8 +88,8 @@ private void ImportImperatorCharacter(
DeathReasonMapper deathReasonMapper,
DNAFactory dnaFactory,
Date endDate,
Configuration config
) {
Configuration config,
ISet<string> unlocalizedImperatorNames) {
// Create a new CK3 character.
var newCharacter = new Character(
irCharacter,
Expand All @@ -99,7 +104,8 @@ Configuration config
deathReasonMapper,
dnaFactory,
endDate,
config
config,
unlocalizedImperatorNames
);
irCharacter.CK3Character = newCharacter;
AddOrReplace(newCharacter);
Expand Down
15 changes: 1 addition & 14 deletions ImperatorToCK3/Outputter/LocalizationOutputter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

namespace ImperatorToCK3.Outputter;
public static class LocalizationOutputter {
public static void OutputLocalization(ModFilesystem irModFS, string outputName, World ck3World) {
public static void OutputLocalization(string outputName, World ck3World) {
var outputPath = Path.Combine("output", outputName);
var baseLocDir = Path.Join(outputPath, "localization");
var baseReplaceLocDir = Path.Join(baseLocDir, "replace");

CopyCharacterAndFamilyNamesLocalization(irModFS, outputPath);

foreach (var language in ConverterGlobals.SupportedLanguages) {
var locFilePath = Path.Join(baseReplaceLocDir, language, $"converter_l_{language}.yml");
using var locWriter = FileOpeningHelper.OpenWriteWithRetries(locFilePath, encoding: System.Text.Encoding.UTF8);
Expand Down Expand Up @@ -63,17 +61,6 @@ public static void OutputLocalization(ModFilesystem irModFS, string outputName,
OutputFallbackLocForMissingSecondaryLanguageLoc(baseLocDir, ck3World.ModFS);
}

private static void CopyCharacterAndFamilyNamesLocalization(ModFilesystem irModFS, string outputPath) {
foreach (var languageName in ConverterGlobals.SupportedLanguages) {
var locFileLocation = irModFS.GetActualFileLocation($"localization/{languageName}/character_names_l_{languageName}.yml");
if (locFileLocation is not null) {
SystemUtils.TryCopyFile(locFileLocation,
Path.Combine(outputPath, $"localization/{languageName}/IMPERATOR_character_names_l_{languageName}.yml")
);
}
}
}

private static void OutputFallbackLocForMissingSecondaryLanguageLoc(string baseLocDir, ModFilesystem ck3ModFS) {
var primaryLanguage = ConverterGlobals.PrimaryLanguage;
var secondaryLanguages = ConverterGlobals.SecondaryLanguages;
Expand Down
4 changes: 1 addition & 3 deletions ImperatorToCK3/Outputter/WorldOutputter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public static void OutputWorld(World ck3World, Imperator.World imperatorWorld, C
Logger.IncrementProgress();

Logger.Info("Writing Localization...");
LocalizationOutputter.OutputLocalization(
imperatorWorld.ModFS,
outputName,
LocalizationOutputter.OutputLocalization(outputName,
ck3World
);
Logger.IncrementProgress();
Expand Down

0 comments on commit 6b196ee

Please sign in to comment.