summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-08-31 23:23:49 +0100
committerCarl Hetherington <cth@carlh.net>2014-08-31 23:23:49 +0100
commit80b87ba861708eb2366e77c044fb8e52400b2d09 (patch)
tree914a5803f09f7f6e199216c487b5ef6ffb7b523c /src/lib/util.cc
parent14ad1435f0c389d3b549160750c681e2a65bc6dc (diff)
Fix i18n of strings from src/lib/po on OS X. There were two bugs;
firstly, the path to the .mo files was wrong (the code assumed that OSX was like Linux). Secondly, the string passed into putenv() must not be freed by the caller (as its docs say). It appears that you get away with not doing this on Linux and Windows.
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index d96001d13..5f1d589d6 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -397,35 +397,42 @@ mo_path ()
}
#endif
+#ifdef DCPOMATIC_OSX
+boost::filesystem::path
+mo_path ()
+{
+ return "DCP-o-matic.app/Contents/Resources";
+}
+#endif
+
void
dcpomatic_setup_gettext_i18n (string lang)
{
-#ifdef DCPOMATIC_POSIX
+#ifdef DCPOMATIC_LINUX
lang += ".UTF8";
#endif
if (!lang.empty ()) {
- /* Override our environment language; this is essential on
- Windows.
+ /* Override our environment language. Note that the caller must not
+ free the string passed into putenv().
*/
- char cmd[64];
- snprintf (cmd, sizeof(cmd), "LANGUAGE=%s", lang.c_str ());
- putenv (cmd);
- snprintf (cmd, sizeof(cmd), "LANG=%s", lang.c_str ());
- putenv (cmd);
- snprintf (cmd, sizeof(cmd), "LC_ALL=%s", lang.c_str ());
- putenv (cmd);
+ string s = String::compose ("LANGUAGE=%1", 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 ()));
}
setlocale (LC_ALL, "");
textdomain ("libdcpomatic");
-#ifdef DCPOMATIC_WINDOWS
+#if defined(DCPOMATIC_WINDOWS) || defined(DCPOMATIC_OSX)
bindtextdomain ("libdcpomatic", mo_path().string().c_str());
bind_textdomain_codeset ("libdcpomatic", "UTF8");
#endif
-#ifdef DCPOMATIC_POSIX
+#ifdef DCPOMATIC_LINUX
bindtextdomain ("libdcpomatic", POSIX_LOCALE_PREFIX);
#endif
}