mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-26 23:00:50 +00:00
backported 2007-04-09T22:15:43Z!elias@pschernig.at from trunk
(setlocale now tries .utf8 versions and other alternates)
This commit is contained in:
parent
733c50bc06
commit
0cd9b7d061
@ -1,4 +1,5 @@
|
||||
[locale]
|
||||
name="Deutsch"
|
||||
locale=de_DE
|
||||
alternates=de_LI, de_LU, de_CH, de_AT
|
||||
[/locale]
|
||||
|
@ -105,7 +105,8 @@ bool load_language_list()
|
||||
config::const_child_itors langs = cfg.child_range("locale");
|
||||
for(;langs.first != langs.second; ++langs.first) {
|
||||
known_languages.push_back(
|
||||
language_def((**langs.first)["locale"], (**langs.first)["name"], (**langs.first)["dir"]));
|
||||
language_def((**langs.first)["locale"], (**langs.first)["name"], (**langs.first)["dir"],
|
||||
(**langs.first)["alternates"]));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -116,7 +117,8 @@ std::vector<language_def> get_languages()
|
||||
return known_languages;
|
||||
}
|
||||
|
||||
static void wesnoth_setlocale(int category, std::string const &slocale)
|
||||
static void wesnoth_setlocale(int category, std::string const &slocale,
|
||||
std::vector<std::string> const *alternates)
|
||||
{
|
||||
char const *locale = slocale.c_str();
|
||||
// FIXME: ideally we should check LANGUAGE and on first invocation
|
||||
@ -171,12 +173,29 @@ static void wesnoth_setlocale(int category, std::string const &slocale)
|
||||
locale = xlocale.c_str();
|
||||
}
|
||||
#endif
|
||||
char* res = setlocale (category, locale);
|
||||
|
||||
char *res = NULL;
|
||||
char const *try_loc = locale;
|
||||
std::vector<std::string>::const_iterator i;
|
||||
if (alternates) i = alternates->begin();
|
||||
while (true) {
|
||||
res = setlocale(category, try_loc);
|
||||
if (res) break;
|
||||
std::string utf8 = std::string(try_loc) + std::string(".utf8");
|
||||
try_loc = utf8.c_str();
|
||||
res = setlocale(category, try_loc);
|
||||
if (res) break;
|
||||
if (!alternates) break;
|
||||
if (i == alternates->end()) break;
|
||||
try_loc = i->c_str();
|
||||
i++;
|
||||
}
|
||||
|
||||
if (res == NULL)
|
||||
std::cerr << "WARNING: setlocale() failed for "
|
||||
<< locale << ".\n";
|
||||
else
|
||||
std::cerr << "set locale to " << locale << "\n";
|
||||
std::cerr << "set locale to " << try_loc << "\n";
|
||||
}
|
||||
|
||||
bool set_language(const language_def& locale)
|
||||
@ -190,7 +209,9 @@ bool set_language(const language_def& locale)
|
||||
config cfg;
|
||||
|
||||
current_language = locale;
|
||||
wesnoth_setlocale(LC_MESSAGES, locale.localename);
|
||||
|
||||
wesnoth_setlocale(LC_MESSAGES, locale.localename, &locale.alternates);
|
||||
wesnoth_setlocale(LC_COLLATE, locale.localename, &locale.alternates);
|
||||
|
||||
// fill string_table (should be moved somwhere else some day)
|
||||
try {
|
||||
@ -232,7 +253,7 @@ const language_def& get_locale()
|
||||
|
||||
const std::string& prefs_locale = preferences::language();
|
||||
if(prefs_locale.empty() == false) {
|
||||
wesnoth_setlocale(LC_MESSAGES, prefs_locale);
|
||||
wesnoth_setlocale(LC_MESSAGES, prefs_locale, NULL);
|
||||
for(std::vector<language_def>::const_iterator i = known_languages.begin();
|
||||
i != known_languages.end(); ++i) {
|
||||
if (prefs_locale == i->localename)
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define LANGUAGE_HPP_INCLUDED
|
||||
|
||||
#include "tstring.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@ -28,10 +29,14 @@ class config;
|
||||
struct language_def
|
||||
{
|
||||
language_def() {}
|
||||
language_def(const std::string& name, const t_string& lang, const std::string& dir) :
|
||||
language_def(const std::string& name, const t_string& lang, const std::string& dir,
|
||||
const std::string &salternates = "") :
|
||||
localename(name), language(lang), rtl(dir == "rtl")
|
||||
{}
|
||||
{
|
||||
alternates = utils::split(salternates);
|
||||
}
|
||||
std::string localename;
|
||||
std::vector<std::string> alternates;
|
||||
t_string language;
|
||||
bool rtl; // A right to left language? (e.g: Hebrew)
|
||||
bool operator== (const language_def&) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user