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.

Offer zh-TW and pick it for a Traditional Chinese OS

Louis061f739e30f1
diff --git a/src/Filee.App/Services/AppLanguages.cs b/src/Filee.App/Services/AppLanguages.cs
index 5ad47237..646c89ff 100644
--- a/src/Filee.App/Services/AppLanguages.cs
+++ b/src/Filee.App/Services/AppLanguages.cs
@@ -13,10 +13,26 @@ internal static class AppLanguages
("ja", "日本語"),
("ko", "한국어"),
("zh-CN", "简体中文"),
+ ("zh-TW", "繁體中文"),
("pl", "Polski"),
("hi", "हिन्दी"),
("ru", "Русский"),
("ar", "العربية"),
("pt-BR", "Português (Brasil)"),
];
+
+ /// <summary>
+ /// True for a Chinese culture name written in Traditional characters: "zh-TW", "zh-HK", "zh-Hant-TW", "zh-CHT" …
+ /// An explicit script wins over the region (macOS has "zh-Hans-TW", Simplified in Taiwan); a bare "zh" is Simplified.
+ /// </summary>
+ public static bool IsTraditionalChinese(string culture)
+ {
+ var parts = culture.Trim().Replace('_', '-').Split('-');
+ if (!parts[0].Equals("zh", StringComparison.OrdinalIgnoreCase))
+ return false;
+ var rest = parts.Skip(1).ToArray();
+ if (rest.Contains("Hans", StringComparer.OrdinalIgnoreCase))
+ return false;
+ return rest.Intersect(["Hant", "TW", "HK", "MO", "CHT"], StringComparer.OrdinalIgnoreCase).Any();
+ }
}
diff --git a/src/Filee.App/Services/LocalizationService.cs b/src/Filee.App/Services/LocalizationService.cs
index 481557a3..f764cb99 100644
--- a/src/Filee.App/Services/LocalizationService.cs
+++ b/src/Filee.App/Services/LocalizationService.cs
@@ -111,7 +111,7 @@ public sealed class LocalizationService : ILocalizer
if (ui.StartsWith("ko", StringComparison.OrdinalIgnoreCase))
return "ko";
if (ui.StartsWith("zh", StringComparison.OrdinalIgnoreCase))
- return "zh-CN";
+ return AppLanguages.IsTraditionalChinese(ui) ? "zh-TW" : "zh-CN";
if (ui.StartsWith("pl", StringComparison.OrdinalIgnoreCase))
return "pl";
if (ui.StartsWith("es", StringComparison.OrdinalIgnoreCase))
diff --git a/src/Filee.App/Services/SoftPalette.cs b/src/Filee.App/Services/SoftPalette.cs
index 6854ba42..49ea4990 100644
--- a/src/Filee.App/Services/SoftPalette.cs
+++ b/src/Filee.App/Services/SoftPalette.cs
@@ -30,6 +30,12 @@ internal static class SoftPalette
private static readonly (string Embedded, string System) Chinese =
("fonts:Filee#Noto Sans SC", "Microsoft YaHei, PingFang SC");
+ /// <summary>
+ /// Traditional Chinese has no embedded font (two more Noto CJK files would add 11 MB): Windows and macOS always carry
+ /// these. Listed before the embedded Noto Sans SC, whose Han shapes differ, so zh-TW text takes Traditional shapes.
+ /// </summary>
+ private const string TraditionalChineseSystem = "Microsoft JhengHei UI, Microsoft JhengHei, PingFang TC";
+
/// <summary>Accent colour + derived shades. Fluent controls read the System* keys.</summary>
public static void ApplyAccent(IResourceDictionary res, Color accent)
{
@@ -69,8 +75,9 @@ internal static class SoftPalette
language.StartsWith("ja", StringComparison.OrdinalIgnoreCase) ? [Japanese, Korean, Chinese]
: language.StartsWith("zh", StringComparison.OrdinalIgnoreCase) ? [Chinese, Korean, Japanese]
: [Korean, Chinese, Japanese];
+ var traditional = AppLanguages.IsTraditionalChinese(language) ? $"{TraditionalChineseSystem}, " : "";
// Noto Sans comes first: the first face also draws the trimming ellipsis, which Noto Sans Arabic lacks.
- return $"{Latin}, {Arabic}, {Devanagari}, {string.Join(", ", cjk.Select(f => f.Embedded))}, Segoe UI, Nirmala UI, "
+ return $"{Latin}, {Arabic}, {Devanagari}, {traditional}{string.Join(", ", cjk.Select(f => f.Embedded))}, Segoe UI, Nirmala UI, "
+ $"{string.Join(", ", cjk.Select(f => f.System))}, Kohinoor Devanagari, Geeza Pro, sans-serif";
}
@@ -84,7 +91,8 @@ internal static class SoftPalette
language.StartsWith("ja", StringComparison.OrdinalIgnoreCase) ? [Japanese, Korean, Chinese]
: language.StartsWith("zh", StringComparison.OrdinalIgnoreCase) ? [Chinese, Korean, Japanese]
: [Korean, Chinese, Japanese];
- return $"Segoe UI, Nirmala UI, {string.Join(", ", cjk.Select(f => f.System))}, sans-serif";
+ var traditional = AppLanguages.IsTraditionalChinese(language) ? $"{TraditionalChineseSystem}, " : "";
+ return $"Segoe UI, Nirmala UI, {traditional}{string.Join(", ", cjk.Select(f => f.System))}, sans-serif";
}
/// <summary>The resource Soft.axaml's Window style takes <see cref="Visual.FlowDirection"/> from.</summary>
diff --git a/src/Filee.Setup/SetupTexts.cs b/src/Filee.Setup/SetupTexts.cs
index 4f453e45..3854ca3b 100644
--- a/src/Filee.Setup/SetupTexts.cs
+++ b/src/Filee.Setup/SetupTexts.cs
@@ -83,7 +83,10 @@ public sealed class SetupTexts
if (normalized.Equals(code, StringComparison.OrdinalIgnoreCase))
return code;
}
- // "ko-KR" → ko, "zh-Hans-CN" / "zh-TW" → zh-CN (the only Chinese), "es-MX" → es.
+ // "zh-Hant-HK" / "zh-HK" → zh-TW; the primary-language fallback below gives the other Chinese names zh-CN.
+ if (Filee.App.Services.AppLanguages.IsTraditionalChinese(normalized))
+ return "zh-TW";
+ // "ko-KR" → ko, "zh-Hans-CN" → zh-CN, "es-MX" → es.
var primary = normalized.Split('-')[0];
foreach (var (code, _) in Languages)
{
diff --git a/tests/Filee.App.Tests/LocalizationTests.cs b/tests/Filee.App.Tests/LocalizationTests.cs
index 18309a6e..4e15316b 100644
--- a/tests/Filee.App.Tests/LocalizationTests.cs
+++ b/tests/Filee.App.Tests/LocalizationTests.cs
@@ -92,6 +92,16 @@ public partial class LocalizationTests
[InlineData("ar-EG", "ar")]
[InlineData("pt-BR", "pt-BR")]
[InlineData("pt-PT", "pt-BR")]
+ [InlineData("zh-CN", "zh-CN")]
+ [InlineData("zh-Hans-CN", "zh-CN")]
+ [InlineData("zh-SG", "zh-CN")]
+ [InlineData("zh", "zh-CN")]
+ [InlineData("zh-Hans-TW", "zh-CN")] // macOS: Simplified script in the Taiwan region
+ [InlineData("zh-TW", "zh-TW")]
+ [InlineData("zh-Hant-TW", "zh-TW")]
+ [InlineData("zh-HK", "zh-TW")]
+ [InlineData("zh-Hant-HK", "zh-TW")]
+ [InlineData("zh-MO", "zh-TW")]
[InlineData("de-DE", "en")]
[InlineData("", "en")] // Linux without LANG: the invariant culture
public void Auto_follows_the_language_the_user_reads_the_os_in(string os, string expected) =>
@@ -155,6 +165,25 @@ public partial class LocalizationTests
Assert.True(embeddedCjk.Max(families.IndexOf) < systemCjk.Min(families.IndexOf), "embedded fonts before system ones");
}
+ [Fact]
+ public void Traditional_chinese_is_offered_under_its_own_name()
+ {
+ Assert.Contains(("zh-TW", "繁體中文"), LocalizationService.Languages);
+ Assert.Equal("zh-TW", LocalizationService.Resolve("zh-TW"));
+ Assert.Equal("zh-CN", LocalizationService.Resolve("zh-CN"));
+ }
+
+ /// <summary>The embedded Noto Sans SC has Simplified Han shapes: zh-TW lists the system Traditional fonts before it.</summary>
+ [Fact]
+ public void Traditional_chinese_takes_the_system_traditional_fonts_before_the_embedded_simplified_one()
+ {
+ var families = ThemeService.FontFamilies("zh-TW").Split(", ").Select(f => f.Replace("fonts:Filee#", "")).ToList();
+
+ Assert.True(families.IndexOf("Microsoft JhengHei UI") is >= 0 and var windows && windows < families.IndexOf("Noto Sans SC"));
+ Assert.True(families.IndexOf("PingFang TC") is >= 0 and var mac && mac < families.IndexOf("Noto Sans SC"));
+ Assert.DoesNotContain("PingFang TC", ThemeService.FontFamilies("zh-CN"));
+ }
+
private static HashSet<string> Placeholders(string text) =>
PlaceholderPattern().Matches(text).Select(m => m.Value).ToHashSet();
diff --git a/tests/Filee.App.Tests/RenderTests.cs b/tests/Filee.App.Tests/RenderTests.cs
index 9c02f387..02e9674e 100644
--- a/tests/Filee.App.Tests/RenderTests.cs
+++ b/tests/Filee.App.Tests/RenderTests.cs
@@ -31,6 +31,8 @@ public class RenderTests
{ "presets", "en" }, { "theme", "en" }, { "engines", "en" }, { "about", "en" },
{ "general", "ko" }, { "toolbar", "ko" }, { "home", "ko" },
{ "general", "zh-CN" }, { "presets", "zh-CN" }, { "toolbar", "zh-CN" }, { "home", "zh-CN" },
+ { "general", "zh-TW" }, { "presets", "zh-TW" }, { "toolbar", "zh-TW" }, { "home", "zh-TW" },
+ { "triggers", "zh-TW" }, { "engines", "zh-TW" }, { "watch", "zh-TW" },
{ "general", "pl" }, { "toolbar", "pl" }, { "presets", "pl" }, { "home", "pl" },
{ "home", "es" }, { "general", "es" }, { "toolbar", "es" }, { "presets", "es" }, { "engines", "es" },
{ "home", "pt-BR" }, { "general", "pt-BR" }, { "toolbar", "pt-BR" }, { "presets", "pt-BR" }, { "engines", "pt-BR" },
diff --git a/tests/Filee.Setup.Tests/SetupTextsTests.cs b/tests/Filee.Setup.Tests/SetupTextsTests.cs
index 158542a1..13dfa03a 100644
--- a/tests/Filee.Setup.Tests/SetupTextsTests.cs
+++ b/tests/Filee.Setup.Tests/SetupTextsTests.cs
@@ -38,7 +38,13 @@ public partial class SetupTextsTests
[InlineData("zhcn", "en-US", "zh-CN")]
[InlineData("ZH-cn", "en-US", "zh-CN")]
[InlineData("auto", "ko-KR", "ko")]
- [InlineData(null, "zh-TW", "zh-CN")]
+ [InlineData(null, "zh-TW", "zh-TW")]
+ [InlineData(null, "zh-Hant-TW", "zh-TW")]
+ [InlineData(null, "zh-HK", "zh-TW")]
+ [InlineData("zh-TW", "en-US", "zh-TW")]
+ [InlineData(null, "zh-Hans-CN", "zh-CN")]
+ [InlineData(null, "zh-SG", "zh-CN")]
+ [InlineData(null, "zh-Hans-TW", "zh-CN")] // an explicit script wins over the region
[InlineData(null, "es-MX", "es")]
[InlineData(null, "pt-BR", "pt-BR")]
[InlineData(null, "pt-PT", "pt-BR")]