summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-05-11 02:15:26 +0200
committerCarl Hetherington <cth@carlh.net>2025-05-11 13:12:21 +0200
commit6249ca3c3f2a9d6861b272281605cfbd8f0e9ecb (patch)
tree2b278da0a8f249ebac35cfcc86672186fc2cb84a
parent0dccb03a2ab9f015e4aa8cbe588d2ad0fcc6f087 (diff)
Simplify language setup.
-rw-r--r--src/lib/util.cc16
-rw-r--r--src/wx/wx_util.cc61
2 files changed, 36 insertions, 41 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 7dd2db83e..784178c08 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -551,13 +551,27 @@ dcpomatic_setup_gettext_i18n(string lang)
*/
string s = String::compose("LANGUAGE=%1", lang);
putenv(strdup(s.c_str()));
+#ifdef DCPOMATIC_WINDOWS
+ /* On Windows this ensures that gettext i18n (for src/lib) works for the
+ * "forced" language. On macOS doing this sets the number format to the
+ * forced language, which means it disagrees with wxWidgets.
+ */
s = String::compose("LANG=%1", lang);
putenv(strdup(s.c_str()));
- s = String::compose("LC_ALL=%1", lang);
+#endif
+#ifdef DCPOMATIC_LINUX
+ s = String::compose("LC_NUMERIC=%1", lang);
putenv(strdup(s.c_str()));
+#endif
}
+#ifndef DCPOMATIC_WINDOWS
+ /* On Windows this seems to take us from the configured locale back to C,
+ * which is never what we want. On macOS/Linux this has the opposite effect,
+ * of making the configured language be applied to printf() etc.
+ */
setlocale(LC_ALL, "");
+#endif
textdomain("libdcpomatic2");
#if defined(DCPOMATIC_WINDOWS) || defined(DCPOMATIC_OSX)
diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc
index ec9f178c3..4aa197345 100644
--- a/src/wx/wx_util.cc
+++ b/src/wx/wx_util.cc
@@ -484,53 +484,34 @@ dcpomatic_setup_i18n()
#else
void
-dcpomatic_setup_i18n ()
+dcpomatic_setup_i18n()
{
- int language = wxLANGUAGE_DEFAULT;
-
- auto config_lang = Config::instance()->language ();
- if (config_lang && !config_lang->empty ()) {
- auto const li = wxLocale::FindLanguageInfo (std_to_wx (config_lang.get ()));
- if (li) {
- language = li->Language;
- }
- }
-
- wxLocale* locale = nullptr;
- if (wxLocale::IsAvailable (language)) {
- locale = new wxLocale (language, wxLOCALE_LOAD_DEFAULT);
-
-#ifdef DCPOMATIC_WINDOWS
- locale->AddCatalogLookupPathPrefix (std_to_wx (mo_path().string()));
- locale->AddCatalog(char_to_wx("wxstd-3.1"));
-#endif
+ /* Use the user's preference for decimal point etc. */
+ wxUILocale::UseDefault();
-#ifdef DCPOMATIC_LINUX
- locale->AddCatalogLookupPathPrefix(std_to_wx(LINUX_LOCALE_PREFIX));
+ /* Tell wxWidgets where to find our .mo files */
+ wxFileTranslationsLoader::AddCatalogLookupPathPrefix(std_to_wx(mo_path().string()));
- /* We have to include the wxWidgets .mo in our distribution,
- so we rename it to avoid clashes with any other installation
- of wxWidgets.
- */
- locale->AddCatalog(char_to_wx("dcpomatic2-wxstd"));
+ auto translations = new wxTranslations();
+ wxTranslations::Set(translations);
- /* Fedora 29 (at least) installs wxstd3.mo instead of wxstd.mo */
- locale->AddCatalog(char_to_wx("wxstd3"));
-#endif
+ /* Force language if required */
+ if (auto config_lang = Config::instance()->language()) {
+ translations->SetLanguage(std_to_wx(*config_lang));
+ }
- locale->AddCatalog(char_to_wx("wxstd"));
- locale->AddCatalog(char_to_wx("libdcpomatic2-wx"));
- locale->AddCatalog(char_to_wx("dcpomatic2"));
+ /* Set up wxWidgets catalogs */
+ translations->AddAvailableCatalog(char_to_wx("wxstd"));
+ translations->AddAvailableCatalog(char_to_wx("wxstd3"));
+ translations->AddAvailableCatalog(char_to_wx("wxstd-3.2"));
+ translations->AddAvailableCatalog(char_to_wx("dcpomatic2-wxstd"));
- if (!locale->IsOk()) {
- delete locale;
- locale = new wxLocale (wxLANGUAGE_ENGLISH);
- }
- }
+ /* Set up DCP-o-matic catalogs */
+ translations->AddAvailableCatalog(char_to_wx("libdcpomatic2-wx"));
+ translations->AddAvailableCatalog(char_to_wx("dcpomatic2"));
- if (locale) {
- dcpomatic_setup_gettext_i18n (wx_to_std (locale->GetCanonicalName ()));
- }
+ /* Set up C library and gettext i18n */
+ dcpomatic_setup_gettext_i18n(wx_to_std(translations->GetBestTranslation(char_to_wx("dcpomatic2"))));
}
#endif