Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

"Auto" language follows the user's display language, not Windows' install language

flexeykinDeve89db5fe98e0
diff --git a/src/Filee.App/Services/LocalizationService.cs b/src/Filee.App/Services/LocalizationService.cs
index 47771f13..a9f7cada 100644
--- a/src/Filee.App/Services/LocalizationService.cs
+++ b/src/Filee.App/Services/LocalizationService.cs
@@ -86,15 +86,26 @@ public sealed class LocalizationService : ILocalizer
public static string LeftToRight(string text) =>
CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? "\u200E" + text + "\u200E" : text;
+ /// <summary>
+ /// The language the user reads the OS in, taken before <see cref="SetLanguage"/> makes Filee's own the current one.
+ /// Not InstalledUICulture: that is the language Windows was installed in, which stays Polish when the user switches
+ /// the display language to English (or Russian, …) later.
+ /// </summary>
+ private static readonly string UserLanguage = CultureInfo.CurrentUICulture.Name;
+
/// <summary>Maps "auto" / a culture name to one of the shipped languages.</summary>
- public static string Resolve(string setting)
+ public static string Resolve(string setting) =>
+ // macOS gives an app started from Finder no LANG: its language list comes from the system instead.
+ Resolve(setting, () => Filee.Platform.MacOS.MacOSLocale.PreferredLanguage() ?? UserLanguage);
+
+ /// <summary>Maps "auto" (the OS language <paramref name="osLanguage"/> gives) / a culture name to a shipped language.</summary>
+ internal static string Resolve(string setting, Func<string> osLanguage)
{
if (!string.Equals(setting, "auto", StringComparison.OrdinalIgnoreCase) &&
Languages.Any(l => l.Code.Equals(setting, StringComparison.OrdinalIgnoreCase)))
return Languages.First(l => l.Code.Equals(setting, StringComparison.OrdinalIgnoreCase)).Code;
- // macOS gives an app started from Finder no LANG: its language list comes from the system instead.
- var ui = Filee.Platform.MacOS.MacOSLocale.PreferredLanguage() ?? CultureInfo.InstalledUICulture.Name;
+ var ui = osLanguage();
if (ui.StartsWith("ja", StringComparison.OrdinalIgnoreCase))
return "ja";
if (ui.StartsWith("ko", StringComparison.OrdinalIgnoreCase))
diff --git a/tests/Filee.App.Tests/LocalizationTests.cs b/tests/Filee.App.Tests/LocalizationTests.cs
index 77cba377..461968d0 100644
--- a/tests/Filee.App.Tests/LocalizationTests.cs
+++ b/tests/Filee.App.Tests/LocalizationTests.cs
@@ -85,6 +85,33 @@ public partial class LocalizationTests
Assert.Equal("ru", LocalizationService.Resolve("RU"));
}
+ [Theory]
+ [InlineData("ru-RU", "ru")]
+ [InlineData("en-US", "en")]
+ [InlineData("pl-PL", "pl")]
+ [InlineData("ar-EG", "ar")]
+ [InlineData("de-DE", "en")]
+ public void Auto_follows_the_language_the_user_reads_the_os_in(string os, string expected) =>
+ Assert.Equal(expected, LocalizationService.Resolve("auto", () => os));
+
+ [Fact]
+ public void Auto_is_not_the_language_filee_switched_to()
+ {
+ // Filee sets the current UI culture to the language it shows; "auto" must still mean the user's own.
+ var before = LocalizationService.Resolve("auto");
+ var shown = before == "ko" ? "ja" : "ko";
+ var culture = System.Globalization.CultureInfo.CurrentUICulture;
+ try
+ {
+ System.Globalization.CultureInfo.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(shown);
+ Assert.Equal(before, LocalizationService.Resolve("auto"));
+ }
+ finally
+ {
+ System.Globalization.CultureInfo.CurrentUICulture = culture;
+ }
+ }
+
[Fact]
public void Japanese_is_offered_under_its_own_name()
{