summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-05-14 01:05:39 +0200
committerCarl Hetherington <cth@carlh.net>2025-05-24 00:43:55 +0200
commit46a8db8e9473586da43d779fc614208136260132 (patch)
tree8bd6e1c29735596edc6a122a1092d405dd2680a3
parentbe5d332f9492865456befc0992520191b8b57769 (diff)
Fix lib i18n code for Windows and maybe Linux.
-rw-r--r--src/lib/util.cc22
-rw-r--r--src/wx/wx_util.cc13
2 files changed, 30 insertions, 5 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 8b487e482..cab361e78 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -557,7 +557,16 @@ void
dcpomatic_setup_gettext_i18n(string lang)
{
#ifdef DCPOMATIC_LINUX
- lang += ".UTF8";
+ if (!lang.empty()) {
+ lang += ".utf8";
+ }
+#endif
+
+#ifdef DCPOMATIC_WINDOWS
+ /* gettext will not look up the user's preferred language using the Win32
+ * APIs unless this is set.
+ */
+ putenv("GETTEXT_MUI=1");
#endif
if (!lang.empty()) {
@@ -568,17 +577,24 @@ dcpomatic_setup_gettext_i18n(string lang)
putenv(strdup(s.c_str()));
s = String::compose("LANG=%1", lang);
putenv(strdup(s.c_str()));
- s = String::compose("LC_ALL=%1", lang);
- putenv(strdup(s.c_str()));
}
+#ifdef DCPOMATIC_WINDOWS
+ /* setlocale(LC_ALL, "") works on Windows in a simple standalone program but
+ * not in these tests for some reason. Using .UTF8 instead makes it work.
+ */
+ setlocale(LC_ALL, ".UTF8");
+#else
setlocale(LC_ALL, "");
+#endif
+
textdomain("libdcpomatic2");
bindtextdomain("libdcpomatic2", mo_path().string().c_str());
bind_textdomain_codeset("libdcpomatic2", "UTF8");
}
+
/** Compute a digest of the first and last `size' bytes of a set of files. */
string
digest_head_tail(vector<boost::filesystem::path> files, boost::uintmax_t size)
diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc
index e4229c1b7..e261a527e 100644
--- a/src/wx/wx_util.cc
+++ b/src/wx/wx_util.cc
@@ -468,11 +468,20 @@ dcpomatic_setup_i18n()
}
}
+ auto add_source_tree_prefixes = []() {
+ wxFileTranslationsLoader::AddCatalogLookupPathPrefix(char_to_wx("build/src/wx/mo"));
+ wxFileTranslationsLoader::AddCatalogLookupPathPrefix(char_to_wx("build/src/tools/mo"));
+ };
+
+
#ifdef DCPOMATIC_DEBUG
- wxFileTranslationsLoader::AddCatalogLookupPathPrefix(char_to_wx("build/src/wx/mo"));
- wxFileTranslationsLoader::AddCatalogLookupPathPrefix(char_to_wx("build/src/tools/mo"));
+ add_source_tree_prefixes();
#endif
+ if (running_tests) {
+ add_source_tree_prefixes();
+ }
+
translations->AddStdCatalog();
translations->AddCatalog(char_to_wx("libdcpomatic2-wx"));
translations->AddCatalog(char_to_wx("dcpomatic2"));