diff --git a/src/Main/locale.cxx b/src/Main/locale.cxx index 2a1bb168a..3625aff48 100644 --- a/src/Main/locale.cxx +++ b/src/Main/locale.cxx @@ -170,7 +170,11 @@ FGLocale::selectLanguage(const char *language) languages.insert(languages.begin(), string(language)); } - + _currentLocaleString = removeEncodingPart(languages[0]); + if (_currentLocaleString == "C") { + _currentLocaleString.clear(); + } + _currentLocale = NULL; BOOST_FOREACH(string lang, languages) { SG_LOG(SG_GENERAL, SG_DEBUG, "trying to find locale for " << lang ); @@ -199,6 +203,14 @@ FGLocale::selectLanguage(const char *language) return true; } +// Return the preferred language according to user choice and/or settings +// (e.g., 'fr_FR', or the empty string if nothing could be found). +std::string +FGLocale::getPreferredLanguage() const +{ + return _currentLocaleString; +} + // Load strings for requested resource and locale. // Result is stored below "strings" in the property tree of the given locale. bool diff --git a/src/Main/locale.hxx b/src/Main/locale.hxx index 67afe772d..30ff4ad60 100644 --- a/src/Main/locale.hxx +++ b/src/Main/locale.hxx @@ -42,6 +42,18 @@ public: */ bool selectLanguage (const char* language = NULL); + /** Return the preferred language according to user choice and/or settings. + * + * Examples: 'fr_CA', 'de_DE'... or the empty string if nothing could be + * found. + * + * Note that this is not necessarily the same as the last value passed to + * selectLanguage(), assuming it was non-null and non-empty, because the + * latter may have an encoding specifier, while values returned by + * getPreferredLanguage() never have that. + */ + std::string getPreferredLanguage() const; + /** * Load strings for requested resource, i.e. "menu", "options", "dialogs". * Loads data for current and default locale (the latter is the fallback). @@ -119,10 +131,11 @@ protected: * Obtain user's default language setting. */ string_list getUserLanguage(); - + SGPropertyNode_ptr _intl; SGPropertyNode_ptr _currentLocale; SGPropertyNode_ptr _defaultLocale; + std::string _currentLocaleString; private: /** Return a new string with the character encoding part of the locale