From 80b87ba861708eb2366e77c044fb8e52400b2d09 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 31 Aug 2014 23:23:49 +0100 Subject: 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. --- src/lib/util.cc | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src') 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 } -- cgit v1.2.3