X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Flocale.cxx;h=1d30dfed0f3d086cd972d7ea1dfce642dd4358b6;hb=d127f7709f7ac64fbbc537131bfd02bb29bc1ebe;hp=ae4cedf076e529932965cb4e82f4e4f815ab6792;hpb=b91175d47a39348ae8798b484dd43819796d4c67;p=flightgear.git diff --git a/src/Main/locale.cxx b/src/Main/locale.cxx index ae4cedf07..1d30dfed0 100644 --- a/src/Main/locale.cxx +++ b/src/Main/locale.cxx @@ -18,10 +18,16 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +#ifdef HAVE_CONFIG_H +# include +#endif + #ifdef HAVE_WINDOWS_H #include #endif +#include + #include #include @@ -53,9 +59,10 @@ FGLocale::~FGLocale() * * This software comes with no warranty. Use at your own risk. */ -const char* +string_list FGLocale::getUserLanguage() { + string_list result; static char locale[100] = {0}; if (GetLocaleInfo(LOCALE_USER_DEFAULT, @@ -68,23 +75,55 @@ FGLocale::getUserLanguage() if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, locale+i, (int)(sizeof(locale)-i))) - return locale; - + { + result.push_back(locale); + return result; + } + locale[--i] = 0; SG_LOG(SG_GENERAL, SG_WARN, "Failed to detected locale's country setting."); - return locale; + result.push_back(locale); + return result; } - return NULL; + return result; +} +#elif __APPLE__ + +// determine locale / langauge on Mac +#include + +string_list +FGLocale::getUserLanguage() +{ + string_list result; + CFArrayRef langs = CFLocaleCopyPreferredLanguages(); + + char buffer[64]; + for (int i=0; i")); - } - - // Use plain C locale if nothing is available. - if ((language == NULL)||(language[0]==0)) - { + string_list languages = getUserLanguage(); + if (languages.empty()) { + // Use plain C locale if nothing is available. SG_LOG(SG_GENERAL, SG_WARN, "Unable to detect system language" ); - language = "C"; + languages.push_back("C"); + } + + // if we were passed a language option, try it first + if ((language != NULL) && (strlen(language) > 0)) { + languages.insert(languages.begin(), string(language)); } - SGPropertyNode *locale = findLocaleNode(language); + + SGPropertyNode *locale = NULL; + BOOST_FOREACH(string lang, languages) { + locale = findLocaleNode(lang); + if (locale) { + break; + } + } + if (!locale) { SG_LOG(SG_GENERAL, SG_ALERT, @@ -161,6 +206,10 @@ FGLocale::selectLanguage(const char *language) } _currentLocale = locale; + + // load resource for system messages (translations for fgfs internal messages) + loadResource("sys"); + return true; } @@ -264,14 +313,14 @@ FGLocale::getLocalizedStrings(const char* id, const char* resource) if (_currentLocale) { simgear::PropertyList s = getLocalizedStrings(_currentLocale, id, resource); - if (s.size()) + if (! s.empty()) return s; } if (_defaultLocale) { simgear::PropertyList s = getLocalizedStrings(_defaultLocale, id, resource); - if (s.size()) + if (! s.empty()) return s; } }