diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-05-25 14:22:30 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-05-27 09:36:37 +0200 |
| commit | 5661c34574fdac778dba0e3c3503f5792c41bb3c (patch) | |
| tree | bd1022ef2dae2abe880714123bfebdb868edc91b /src/lib | |
| parent | a8f06a40096a0cbd56c42602f8dc1ce4857af0d8 (diff) | |
Move i18n setup into 3 separate platform files.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/i18n_setup.h | 32 | ||||
| -rw-r--r-- | src/lib/i18n_setup_linux.cc | 60 | ||||
| -rw-r--r-- | src/lib/i18n_setup_osx.cc | 60 | ||||
| -rw-r--r-- | src/lib/i18n_setup_windows.cc | 69 | ||||
| -rw-r--r-- | src/lib/util.cc | 53 | ||||
| -rw-r--r-- | src/lib/util.h | 4 | ||||
| -rw-r--r-- | src/lib/wscript | 6 |
7 files changed, 224 insertions, 60 deletions
diff --git a/src/lib/i18n_setup.h b/src/lib/i18n_setup.h new file mode 100644 index 000000000..8bb3af152 --- /dev/null +++ b/src/lib/i18n_setup.h @@ -0,0 +1,32 @@ +/* + Copyright (C) 2025 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include <boost/filesystem.hpp> +#include <string> + + +namespace dcpomatic { + +boost::filesystem::path mo_path(); +void setup_i18n(std::string forced_language); + +} + diff --git a/src/lib/i18n_setup_linux.cc b/src/lib/i18n_setup_linux.cc new file mode 100644 index 000000000..21e7f2d61 --- /dev/null +++ b/src/lib/i18n_setup_linux.cc @@ -0,0 +1,60 @@ +/* + Copyright (C) 2025 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "i18n_setup.h" +#include <fmt/format.h> +#include <boost/filesystem.hpp> +#include <libintl.h> + + +using std::string; + + +boost::filesystem::path +dcpomatic::mo_path() +{ + return LINUX_LOCALE_PREFIX; +} + + +void +dcpomatic::setup_i18n(string forced_language) +{ + forced_language += ".UTF8"; + + if (!forced_language.empty()) { + /* Override our environment forced_languageuage. Note that the caller must not + free the string passed into putenv(). + */ + string s = fmt::format("LANGUAGE={}", forced_language); + putenv(strdup(s.c_str())); + s = fmt::format("LANG={}", forced_language); + putenv(strdup(s.c_str())); + s = fmt::format("LC_ALL={}", forced_language); + putenv(strdup(s.c_str())); + } + + setlocale(LC_ALL, ""); + textdomain("libdcpomatic2"); + + bindtextdomain("libdcpomatic2", mo_path().string().c_str()); +} + diff --git a/src/lib/i18n_setup_osx.cc b/src/lib/i18n_setup_osx.cc new file mode 100644 index 000000000..7a7c63ce8 --- /dev/null +++ b/src/lib/i18n_setup_osx.cc @@ -0,0 +1,60 @@ +/* + Copyright (C) 2025 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "i18n_setup.h" +#include "variant.h" +#include <fmt/format.h> +#include <boost/filesystem.hpp> +#include <libintl.h> + + +using std::string; + + +boost::filesystem::path +dcpomatic::mo_path() +{ + return variant::dcpomatic_app() + "/Contents/Resources"; +} + + +void +dcpomatic::setup_i18n(string forced_language) +{ + if (!forced_language.empty()) { + /* Override our environment forced_languageuage. Note that the caller must not + free the string passed into putenv(). + */ + string s = fmt::format("LANGUAGE={}", forced_language); + putenv(strdup(s.c_str())); + s = fmt::format("LANG={}", forced_language); + putenv(strdup(s.c_str())); + s = fmt::format("LC_ALL={}", forced_language); + putenv(strdup(s.c_str())); + } + + setlocale(LC_ALL, ""); + textdomain("libdcpomatic2"); + + bindtextdomain("libdcpomatic2", mo_path().string().c_str()); + bind_textdomain_codeset("libdcpomatic2", "UTF8"); +} + diff --git a/src/lib/i18n_setup_windows.cc b/src/lib/i18n_setup_windows.cc new file mode 100644 index 000000000..7833972b6 --- /dev/null +++ b/src/lib/i18n_setup_windows.cc @@ -0,0 +1,69 @@ +/* + Copyright (C) 2025 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#define UNICODE 1 + + +#include "i18n_setup.h" +#include <fmt/format.h> +#include <boost/filesystem.hpp> +#include <windows.h> +#include <libintl.h> + + +using std::string; + + +boost::filesystem::path +dcpomatic::mo_path() +{ + wchar_t buffer[512]; + GetModuleFileName(0, buffer, 512 * sizeof(wchar_t)); + boost::filesystem::path p(buffer); + p = p.parent_path(); + p = p.parent_path(); + p /= "locale"; + return p; +} + + +void +dcpomatic::setup_i18n(string forced_language) +{ + if (!forced_language.empty()) { + /* Override our environment language. Note that the caller must not + free the string passed into putenv(). + */ + auto s = fmt::format("LANGUAGE={}", forced_language); + putenv(strdup(s.c_str())); + s = fmt::format("LANG={}", forced_language); + putenv(strdup(s.c_str())); + s = fmt::format("LC_ALL={}", forced_language); + putenv(strdup(s.c_str())); + } + + setlocale(LC_ALL, ""); + textdomain("libdcpomatic2"); + + bindtextdomain("libdcpomatic2", mo_path().string().c_str()); + bind_textdomain_codeset("libdcpomatic2", "UTF8"); +} + diff --git a/src/lib/util.cc b/src/lib/util.cc index ac562afc1..eeab9f2d6 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -512,59 +512,6 @@ LIBDCP_ENABLE_WARNINGS capture_ffmpeg_logs(); } -#ifdef DCPOMATIC_WINDOWS -boost::filesystem::path -mo_path() -{ - wchar_t buffer[512]; - GetModuleFileName(0, buffer, 512 * sizeof(wchar_t)); - boost::filesystem::path p(buffer); - p = p.parent_path(); - p = p.parent_path(); - p /= "locale"; - return p; -} -#endif - -#ifdef DCPOMATIC_OSX -boost::filesystem::path -mo_path() -{ - return variant::dcpomatic_app() + "/Contents/Resources"; -} -#endif - -void -dcpomatic_setup_gettext_i18n(string lang) -{ -#ifdef DCPOMATIC_LINUX - lang += ".UTF8"; -#endif - - if (!lang.empty()) { - /* Override our environment language. Note that the caller must not - free the string passed into putenv(). - */ - 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("libdcpomatic2"); - -#if defined(DCPOMATIC_WINDOWS) || defined(DCPOMATIC_OSX) - bindtextdomain("libdcpomatic2", mo_path().string().c_str()); - bind_textdomain_codeset("libdcpomatic2", "UTF8"); -#endif - -#ifdef DCPOMATIC_LINUX - bindtextdomain("libdcpomatic2", LINUX_LOCALE_PREFIX); -#endif -} /** Compute a digest of the first and last `size' bytes of a set of files. */ string diff --git a/src/lib/util.h b/src/lib/util.h index 80ba4a1f6..79ac87db1 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -66,7 +66,6 @@ extern std::string seconds_to_approximate_hms(int); extern double seconds(struct timeval); extern void dcpomatic_setup(); extern void dcpomatic_setup_path_encoding(); -extern void dcpomatic_setup_gettext_i18n(std::string); extern std::string digest_head_tail(std::vector<boost::filesystem::path>, boost::uintmax_t size); extern std::string simple_digest(std::vector<boost::filesystem::path> paths); extern void ensure_ui_thread(); @@ -75,9 +74,6 @@ extern std::string short_audio_channel_name(int); extern bool valid_image_file(boost::filesystem::path); extern bool valid_sound_file(boost::filesystem::path); extern bool valid_j2k_file(boost::filesystem::path); -#ifdef DCPOMATIC_WINDOWS -extern boost::filesystem::path mo_path(); -#endif extern std::string tidy_for_filename(std::string); extern dcp::Size fit_ratio_within(float ratio, dcp::Size); extern void set_backtrace_file(boost::filesystem::path); diff --git a/src/lib/wscript b/src/lib/wscript index dafd655fe..ea6994eb1 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -272,11 +272,11 @@ def build(bld): if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32: obj.uselib += ' WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE SETUPAPI OLE32 UUID' - obj.source += ' cross_windows.cc' + obj.source += ' cross_windows.cc i18n_setup_windows.cc' if bld.env.TARGET_OSX: - obj.source += ' cross_osx.cc cross_unix.cc' + obj.source += ' cross_osx.cc cross_unix.cc i18n_setup_osx.cc' if bld.env.TARGET_LINUX: - obj.source += ' cross_linux.cc cross_unix.cc' + obj.source += ' cross_linux.cc cross_unix.cc i18n_setup_linux.cc' if bld.env.STATIC_DCPOMATIC: obj.uselib += ' XMLPP' |
