Fix i18n of strings from src/lib/po on OS X. There were two bugs;
authorCarl Hetherington <cth@carlh.net>
Sun, 31 Aug 2014 22:23:49 +0000 (23:23 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 31 Aug 2014 22:23:49 +0000 (23:23 +0100)
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.

ChangeLog
src/lib/util.cc

index e668225977d9c86550dae51bfb917ad395ffa83f..99558f508b4895aba17f0526c326485619b5786d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2014-08-31  Carl Hetherington  <cth@carlh.net>
 
+       * Fix lack of i18n of strings from src/lib/po on OS X.
+
        * Give a hint when content and container aspect ratios are not
        the same (#392).
 
index d96001d13916fcf3eda519c625ce0d68f15b512a..5f1d589d669d92f53cbf29d381f06f97fa4438a5 100644 (file)
@@ -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
 }