diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-05-25 22:36:02 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-05-27 09:36:37 +0200 |
| commit | 0563f2ddab7839dbe3c18ef176900f6205c8b3f6 (patch) | |
| tree | 2549dc941ad56dcf62b1020ad467f96a6b23b5d6 | |
| parent | 5661c34574fdac778dba0e3c3503f5792c41bb3c (diff) | |
Fix macOS i18n to always use the user's macOS-configured locale (#3036).
| -rw-r--r-- | src/lib/i18n_setup_osx.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/lib/i18n_setup_osx.cc b/src/lib/i18n_setup_osx.cc index 7a7c63ce8..d7dce4f0e 100644 --- a/src/lib/i18n_setup_osx.cc +++ b/src/lib/i18n_setup_osx.cc @@ -24,6 +24,7 @@ #include <fmt/format.h> #include <boost/filesystem.hpp> #include <libintl.h> +#include <CoreFoundation/CoreFoundation.h> using std::string; @@ -47,11 +48,26 @@ dcpomatic::setup_i18n(string forced_language) putenv(strdup(s.c_str())); s = fmt::format("LANG={}", forced_language); putenv(strdup(s.c_str())); - s = fmt::format("LC_ALL={}", forced_language); - putenv(strdup(s.c_str())); } + auto get_locale_value = [](CFLocaleKey key) { + CFLocaleRef cflocale = CFLocaleCopyCurrent(); + auto value = (CFStringRef) CFLocaleGetValue(cflocale, key); + char buffer[64]; + CFStringGetCString(value, buffer, sizeof(buffer), kCFStringEncodingUTF8); + CFRelease(cflocale); + return string(buffer); + }; + + /* We want to keep using the user's macOS-configured locale, partly because this feels + * like the right thing to do but mostly because that's what the wxWidgets side will do, + * and we must agree. + */ + auto lc = fmt::format("LC_ALL={}_{}", get_locale_value(kCFLocaleLanguageCode), get_locale_value(kCFLocaleCountryCode)); + putenv(strdup(lc.c_str())); + setlocale(LC_ALL, ""); + textdomain("libdcpomatic2"); bindtextdomain("libdcpomatic2", mo_path().string().c_str()); |
