Skip to content

Commit

Permalink
Output English loc as fallback for keys unlocalized in secondary lang…
Browse files Browse the repository at this point in the history
…uages (#1454)
  • Loading branch information
IhateTrains authored Aug 6, 2023
1 parent bfa2df7 commit ec9b13d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ImperatorToCK3/ImperatorToCK3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.2.0" />
<PackageReference Include="NAudio" Version="2.1.0" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="PGCG.commonItems" Version="8.1.6" />
<PackageReference Include="PGCG.commonItems" Version="8.2.0" />
<PackageReference Include="PGCG.commonItems.SourceGenerators" Version="1.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
</ItemGroup>
Expand Down
48 changes: 48 additions & 0 deletions ImperatorToCK3/Outputter/LocalizationOutputter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using commonItems;
using commonItems.Localization;
using commonItems.Mods;
using ImperatorToCK3.CK3;
using System.Collections.Generic;
Expand Down Expand Up @@ -67,5 +68,52 @@ public static void OutputLocalization(ModFilesystem irModFS, string outputName,
}
}
}

OutputFallbackLockForMissingSecondaryLanguageLoc(baseLocDir, ck3World.ModFS);
}

private static void OutputFallbackLockForMissingSecondaryLanguageLoc(string baseLocDir, ModFilesystem ck3ModFS) {
var primaryLanguage = ConverterGlobals.PrimaryLanguage;
var secondaryLanguages = ConverterGlobals.SecondaryLanguages;

var ck3LocDB = new LocDB(primaryLanguage, secondaryLanguages);
ck3LocDB.ScrapeLocalizations(ck3ModFS);

var languageToLocLinesDict = new Dictionary<string, List<string>>();
foreach (var language in secondaryLanguages) {
languageToLocLinesDict[language] = new List<string>();
}

foreach (var locBlock in ck3LocDB) {
if (!locBlock.HasLocForLanguage(primaryLanguage)) {
continue;
}

foreach (var secondaryLanguage in secondaryLanguages) {
if (locBlock.HasLocForLanguage(secondaryLanguage)) {
continue;
}

languageToLocLinesDict[secondaryLanguage].Add(locBlock.GetYmlLocLineForLanguage(primaryLanguage));
}
}

foreach (var language in secondaryLanguages) {
var linesToOutput = languageToLocLinesDict[language];
if (linesToOutput.Count == 0) {
continue;
}

Logger.Debug($"Outputting {linesToOutput.Count} fallback loc lines for {language}...");

var locFilePath = Path.Combine(baseLocDir, $"{language}/irtock3_fallback_loc_l_{language}.yml");
using var locFileStream = File.OpenWrite(locFilePath);
using var locWriter = new StreamWriter(locFileStream, System.Text.Encoding.UTF8);

locWriter.WriteLine($"l_{language}:");
foreach (var line in linesToOutput) {
locWriter.WriteLine(line);
}
}
}
}

0 comments on commit ec9b13d

Please sign in to comment.