From 6279228a7d80e1bd52db17e506ff34cd3d322c4f Mon Sep 17 00:00:00 2001 From: maj00r Date: Fri, 13 Nov 2026 16:07:04 +0100 Subject: [PATCH] fix: find a scenery's i18n tables whatever the case of their names The i18n folder and its _.json tables are looked up through CaseInsensitivePaths, so on Linux a scenery's texts are translated when the table is named in other letter case than the scenery file. --- StarterNG.Tests/SceneryTranslationsTests.cs | 18 ++++++++++++++++++ .../Sceneries/SceneryTranslations.cs | 11 ++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/StarterNG.Tests/SceneryTranslationsTests.cs b/StarterNG.Tests/SceneryTranslationsTests.cs index a2d422b..308f794 100644 --- a/StarterNG.Tests/SceneryTranslationsTests.cs +++ b/StarterNG.Tests/SceneryTranslationsTests.cs @@ -39,6 +39,24 @@ public class SceneryTranslationsTests Assert.Equal("Polski", scenery.LocalizedDescription(translations)); } + [Fact] + public void The_tables_are_found_whatever_the_case_of_their_names() + { + var files = new InMemoryFileSystem(caseSensitive: true) + .WithFile(TestInstallation.At("scenery", "Braniewo.scn"), "//$d @brief") + .WithFile(Path.Combine(Path.GetFullPath(TestInstallation.At("scenery")), "I18N", "braniewo_en.json"), + """{ "brief": "English" }""") + .WithFile(Path.Combine(Path.GetFullPath(TestInstallation.At("scenery")), "I18N", "BRANIEWO_PL.json"), + """{ "brief": "Polski" }"""); + var installation = new TestInstallation(files); + var scenery = Assert.Single(installation.Sceneries.LoadAll()); + var translations = new SceneryTranslations(files, installation.Log); + + translations.LoadFor(scenery, "Polski"); + + Assert.Equal("Polski", scenery.LocalizedDescription(translations)); + } + [Fact] public void Literal_text_and_unknown_keys_are_left_alone() { diff --git a/StarterNG/Infrastructure/Sceneries/SceneryTranslations.cs b/StarterNG/Infrastructure/Sceneries/SceneryTranslations.cs index efcc73d..c71b786 100644 --- a/StarterNG/Infrastructure/Sceneries/SceneryTranslations.cs +++ b/StarterNG/Infrastructure/Sceneries/SceneryTranslations.cs @@ -14,12 +14,14 @@ public sealed class SceneryTranslations : ISceneryTranslations private const string BaseLanguage = "en"; private readonly IFileSystem _files; + private readonly CaseInsensitivePaths _names; private readonly IDiagnosticsLog _log; private readonly Dictionary _map = new(StringComparer.OrdinalIgnoreCase); public SceneryTranslations(IFileSystem files, IDiagnosticsLog log) { _files = files; + _names = new CaseInsensitivePaths(files); _log = log; } @@ -29,12 +31,11 @@ public sealed class SceneryTranslations : ISceneryTranslations string sceneryDir = Path.GetDirectoryName(Path.GetFullPath(scenery.Path)) ?? "scenery"; string id = Path.GetFileNameWithoutExtension(scenery.Path); - string i18nDir = Path.Combine(sceneryDir, "i18n"); string language = NormalizeLanguage(langCode); - TryLoad(Path.Combine(i18nDir, $"{id}_{BaseLanguage}.json")); + TryLoad(_names.Find(sceneryDir, $"i18n/{id}_{BaseLanguage}.json")); if (!string.Equals(language, BaseLanguage, StringComparison.OrdinalIgnoreCase)) - TryLoad(Path.Combine(i18nDir, $"{id}_{language}.json")); + TryLoad(_names.Find(sceneryDir, $"i18n/{id}_{language}.json")); } public string Translate(string? text) @@ -50,9 +51,9 @@ public sealed class SceneryTranslations : ISceneryTranslations return _map.TryGetValue(key, out string? translated) ? translated : text; } - private void TryLoad(string path) + private void TryLoad(string? path) { - if (!_files.FileExists(path)) + if (path is null) return; try