30 #if !defined(_MSC_VER) && !defined(__MINGW32__) 31 extern "C" int _putenv(
const char*);
39 #define DBG_G LOG_STREAM(debug, lg::general()) 40 #define LOG_G LOG_STREAM(info, lg::general()) 41 #define WRN_G LOG_STREAM(warn, lg::general()) 42 #define ERR_G LOG_STREAM(err, lg::general()) 46 std::vector<config> languages_;
48 int min_translation_percent = 80;
69 static bool result =
true;
75 const utils::string_map::const_iterator
i = strings_.find(key);
76 if(i != strings_.end()) {
84 empty_string =
"UNTLB " + key;
91 return (*
this)[std::string(key)];
96 return strings_.find(key);
101 return strings_.end();
120 lang[
"locale"], lang[
"name"], lang[
"dir"],
121 lang[
"alternates"], lang[
"sort_name"], lang[
"percent"]);
133 if(all || min_translation_percent == 0) {
139 [](
const language_def& lang) {
return lang.percent >= min_translation_percent; });
145 min_translation_percent =
percent;
150 static const std::map<std::string, std::string> win32_locales_map = {
151 {
"af",
"Afrikaans" },
154 {
"bg",
"Bulgarian" },
163 {
"et",
"Estonian" },
168 {
"ga",
"Irish_Ireland" },
169 {
"gl",
"Galician" },
171 {
"hr",
"Croatian" },
172 {
"hu",
"Hungarian" },
173 {
"id",
"Indonesian" },
174 {
"is",
"Icelandic" },
176 {
"ja",
"Japanese" },
179 {
"lt",
"Lithuanian" },
181 {
"mk",
"Macedonian" },
183 {
"nb",
"Norwegian" },
186 {
"pt",
"Portuguese" },
188 {
"ro",
"Romanian" },
191 {
"sl",
"Slovenian" },
194 {
"tl",
"Filipino" },
196 {
"uk",
"Ukrainian" },
197 {
"vi",
"Vietnamese" },
201 static const std::string& posix_locale_to_win32(
const std::string& posix)
203 auto it = win32_locales_map.find(posix);
204 return it != win32_locales_map.end() ? it->second : posix;
212 std::string locale = slocale;
222 unsetenv (
"LANGUAGE");
231 std::string lang_code{locale, 0, locale.find_first_of(
"_@.")};
232 locale = posix_locale_to_win32(lang_code);
236 std::vector<std::string>::const_iterator
i;
237 if (alternates) i = alternates->begin();
241 std::string lang = locale, extra;
242 std::string::size_type pos = locale.find(
'@');
243 if (pos != std::string::npos) {
245 extra = locale.substr(pos);
252 char const *encoding[] {
".utf-8",
".UTF-8",
"" };
253 for (
int j = 0; j != 3; ++j)
255 locale = lang + encoding[j] + extra;
256 res = std::setlocale(category, locale.c_str());
258 LOG_G <<
"Set locale to '" << locale <<
"' result: '" << res <<
"'.\n";
263 if (!alternates || i == alternates->end())
break;
268 WRN_G <<
"setlocale() failed for '" << slocale <<
"'." << std::endl;
270 if (category == LC_TIME) {
283 DBG_G <<
"Numeric locale: " << std::setlocale(LC_NUMERIC,
nullptr) <<
'\n';
284 DBG_G <<
"Full locale: " << std::setlocale(LC_ALL,
nullptr) <<
'\n';
291 std::string locale_lc;
295 current_language = locale;
306 DBG_G <<
"Loading strings\n";
309 LOG_G <<
"There are " << languages_.size() <<
" [language] blocks\n";
310 if (complain && languages_.empty()) {
311 std::cerr <<
"No [language] block found\n";
314 for (
const config &lang : languages_) {
315 DBG_G <<
"[language]\n";
317 DBG_G << j.first <<
"=\"" << j.second <<
"\"\n";
318 strings_[j.first] = j.second;
320 DBG_G <<
"[/language]\n";
336 if(prefs_locale.empty() ==
false) {
340 if (prefs_locale ==
i->localename)
343 LOG_G <<
"'" << prefs_locale <<
"' locale not found in known array; defaulting to system locale\n";
348 const char*
const locale = getenv(
"LANG");
350 return posix_locale_to_win32(locale);
352 if(locale !=
nullptr && strlen(locale) >= 2) {
356 std::string res(2,
'z');
357 res[0] = tolower(locale[0]);
358 res[1] = tolower(locale[1]);
363 LOG_G <<
"locale could not be determined; defaulting to system locale\n";
371 const std::string &name =
t[
"name"];
372 const std::string &
path =
t[
"path"];
379 if (location.empty()) {
382 WRN_G <<
"no location found for '" << path <<
"', skipping textdomain" << std::endl;
394 languages_.push_back(l);
bool & time_locale_correct()
std::string get_binary_dir_location(const std::string &type, const std::string &filename)
Returns a complete path to the actual directory of a given type or an empty string if the directory i...
std::map< std::string, t_string > string_map
config_array_view child_range(config_key_type key) const
utils::string_map::const_iterator find(const std::string &key) const
Look up the string mappings given in [language] tags.
child_itors child_range(config_key_type key)
attribute_map::value_type attribute
const language_def & get_locale()
void set_language(const std::string &language, const std::vector< std::string > *)
void set_min_translation_percent(int percent)
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
bool operator==(const language_def &) const
static language_list known_languages
bool current_language_rtl()
static void add_textdomain(const std::string &name, const std::string &path)
void read(config &cfg, std::istream &in, abstract_validator *validator)
std::string get_intl_dir()
language_list get_languages(bool all)
Return a list of available translations.
std::unique_ptr< std::istream > scoped_istream
static void wesnoth_setlocale(int category, const std::string &slocale, std::vector< std::string > const *alternates)
bool init_strings(const game_config_view &cfg)
Initializes certain English strings.
utils::string_map::const_iterator end() const
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
const language_def & get_language()
bool load_language_list()
std::vector< language_def > language_list
Declarations for File-IO.
int percent
% of translated text in core po-s
void set_language(const language_def &locale)
symbol_table string_table
const t_string & operator[](const std::string &key) const
Look up the string mappings given in [language] tags.
Standard logging facilities (interface).
A config object defines a single node in a WML file, with access to child nodes.
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines)
Function to use the WML preprocessor on a file.
bool load_strings(bool complain)
std::vector< std::string > alternates