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.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
macOS: Filee follows the system language when started from Finder
KnifeLemona8715f55777c
diff --git a/installer/macos/Info.plist b/installer/macos/Info.plistindex 49eca65a..6b069a3f 100644--- a/installer/macos/Info.plist+++ b/installer/macos/Info.plist@@ -3,6 +3,7 @@<plist version="1.0"><dict><key>CFBundleDevelopmentRegion</key><string>en</string>+ <key>CFBundleLocalizations</key><array><string>en</string><string>ko</string><string>zh-Hans</string></array><key>CFBundleIdentifier</key><string>com.filee.app</string><key>CFBundleName</key><string>Filee</string><key>CFBundleDisplayName</key><string>Filee</string>diff --git a/src/Filee.App/Services/LocalizationService.cs b/src/Filee.App/Services/LocalizationService.csindex cf6a9a2f..f09685a0 100644--- a/src/Filee.App/Services/LocalizationService.cs+++ b/src/Filee.App/Services/LocalizationService.cs@@ -91,7 +91,8 @@ public sealed class LocalizationService : ILocalizerLanguages.Any(l => l.Code.Equals(setting, StringComparison.OrdinalIgnoreCase)))return Languages.First(l => l.Code.Equals(setting, StringComparison.OrdinalIgnoreCase)).Code;- var ui = CultureInfo.InstalledUICulture.Name;+ // 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;if (ui.StartsWith("ko", StringComparison.OrdinalIgnoreCase))return "ko";if (ui.StartsWith("zh", StringComparison.OrdinalIgnoreCase))diff --git a/src/Filee.Platform.MacOS/MacOSLocale.cs b/src/Filee.Platform.MacOS/MacOSLocale.csnew file mode 100644index 00000000..1b8edf27--- /dev/null+++ b/src/Filee.Platform.MacOS/MacOSLocale.cs@@ -0,0 +1,54 @@+// The user's language on macOS. An app started from Finder gets no LANG variable, so .NET's InstalledUICulture is+// the invariant culture there; macOS keeps the language list (System Settings > General > Language & Region) in+// AppleLanguages, which CFLocaleCopyPreferredLanguages returns, unfiltered by the app's own localizations.++using System.Runtime.InteropServices;+using System.Text;++namespace Filee.Platform.MacOS;++public static class MacOSLocale+{+ private const string CoreFoundation = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";+ private const uint Utf8 = 0x08000100;++ /// <summary>The first language the user prefers, e.g. "ko-KR" or "zh-Hans-CN"; null when macOS gives none.</summary>+ public static string? PreferredLanguage()+ {+ if (!OperatingSystem.IsMacOS())+ return null;+ var languages = CFLocaleCopyPreferredLanguages();+ if (languages == 0)+ return null;+ try+ {+ if (CFArrayGetCount(languages) == 0)+ return null;+ var first = CFArrayGetValueAtIndex(languages, 0);+ var buffer = new byte[128];+ return CFStringGetCString(first, buffer, buffer.Length, Utf8)+ ? Encoding.UTF8.GetString(buffer, 0, Array.IndexOf(buffer, (byte)0) is var end and >= 0 ? end : buffer.Length)+ : null;+ }+ finally+ {+ CFRelease(languages);+ }+ }++ [DllImport(CoreFoundation)]+ private static extern nint CFLocaleCopyPreferredLanguages();++ [DllImport(CoreFoundation)]+ private static extern nint CFArrayGetCount(nint array);++ [DllImport(CoreFoundation)]+ private static extern nint CFArrayGetValueAtIndex(nint array, nint index);++ [DllImport(CoreFoundation)]+ [return: MarshalAs(UnmanagedType.I1)]+ private static extern bool CFStringGetCString(nint value, [Out] byte[] buffer, nint size, uint encoding);++ [DllImport(CoreFoundation)]+ private static extern void CFRelease(nint value);+}