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/i18n_setup_windows.cc | |
| parent | a8f06a40096a0cbd56c42602f8dc1ce4857af0d8 (diff) | |
Move i18n setup into 3 separate platform files.
Diffstat (limited to 'src/lib/i18n_setup_windows.cc')
| -rw-r--r-- | src/lib/i18n_setup_windows.cc | 69 |
1 files changed, 69 insertions, 0 deletions
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"); +} + |
