27 #include <boost/scoped_array.hpp>
31 #if !defined(_MSC_VER) && !defined(__MINGW32__)
32 extern "C" int _putenv(
const char*);
40 #define DBG_G LOG_STREAM(debug, lg::general())
41 #define LOG_G LOG_STREAM(info, lg::general())
42 #define WRN_G LOG_STREAM(warn, lg::general())
43 #define ERR_G LOG_STREAM(err, lg::general())
47 std::vector<config> languages_;
75 const utils::string_map::const_iterator
i = strings_.find(key);
76 if(i != strings_.end()) {
84 empty_string =
"UNTLB " + key;
112 lang[
"alternates"], lang[
"sort_name"]));
127 std::vector<std::string>
const *alternates)
139 unsetenv (
"LANGUAGE");
160 std::vector<std::string>::const_iterator
i;
161 if (alternates) i = alternates->begin();
166 std::string::size_type
pos = locale.find(
'@');
167 if (pos != std::string::npos) {
169 extra = locale.substr(pos);
176 char const *encoding[] = {
".utf-8",
".UTF-8",
"" };
177 for (
int j = 0; j != 3; ++j)
179 locale = lang + encoding[j] + extra;
180 res = std::setlocale(category, locale.c_str());
182 LOG_G <<
"Set locale to '" << locale <<
"' result: '" << res <<
"'.\n";
187 if (!alternates || i == alternates->end())
break;
192 WRN_G <<
"setlocale() failed for '" << slocale <<
"'." << std::endl;
194 if (category == LC_TIME) {
207 DBG_G <<
"Numeric locale: " << std::setlocale(LC_NUMERIC,
nullptr) <<
'\n';
208 DBG_G <<
"Full locale: " << std::setlocale(LC_ALL,
nullptr) <<
'\n';
219 current_language = locale;
230 DBG_G <<
"Loading strings\n";
233 LOG_G <<
"There are " << languages_.size() <<
" [language] blocks\n";
234 if (complain && languages_.empty()) {
235 std::cerr <<
"No [language] block found\n";
238 for (
const config &lang : languages_) {
239 DBG_G <<
"[language]\n";
241 DBG_G << j.first <<
"=\"" << j.second <<
"\"\n";
242 strings_[j.first] = j.second;
244 DBG_G <<
"[/language]\n";
260 if(prefs_locale.empty() ==
false) {
264 if (prefs_locale ==
i->localename)
267 LOG_G <<
"'" << prefs_locale <<
"' locale not found in known array; defaulting to system locale\n";
272 const char*
const locale = getenv(
"LANG");
278 if(locale !=
nullptr && strlen(locale) >= 2) {
283 res[0] = tolower(locale[0]);
284 res[1] = tolower(locale[1]);
289 LOG_G <<
"locale could not be determined; defaulting to system locale\n";
305 if (location.empty()) {
308 WRN_G <<
"no location found for '" << path <<
"', skipping textdomain" << std::endl;
320 languages_.push_back(
l);
bool & time_locale_correct()
child_itors child_range(const std::string &key)
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...
const t_string & operator[](const std::string &key) const
attribute_map::value_type attribute
const language_def & get_locale()
bool operator==(const language_def &) const
void set_language(const std::string &slocale, const std::vector< std::string > *alternates)
static const std::string empty_string
GLuint GLenum GLenum transform
static language_list known_languages
GLsizei const char ** path
std::map< std::string, t_string > string_map
bool current_language_rtl()
static void add_textdomain(const std::string &name, const std::string &path)
std::string get_intl_dir()
GLboolean GLboolean GLboolean GLboolean a
void init_textdomains(const config &cfg)
Initializes the list of textdomains from a configuration object.
Encapsulates the map of the game.
static void wesnoth_setlocale(int category, std::string const &slocale, std::vector< std::string > const *alternates)
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir=std::string())
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
language_list get_languages()
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
static int sort(lua_State *L)
GLuint const GLchar * name
void set_language(const language_def &locale)
std::istream * preprocess_file(std::string const &fname, preproc_map *defines)
symbol_table string_table
Standard logging facilities (interface).
bool init_strings(const config &cfg)
Initializes certain English strings.
A config object defines a single node in a WML file, with access to child nodes.
bool load_strings(bool complain)
GLsizei const GLcharARB ** string
std::vector< std::string > alternates