Add method FGLocale::getPreferredLanguage()
This function returns the preferred "locale"[1] according to user choice and/or settings (i.e., it is influenced by --language if passed, otherwise by current locale/system settings). The return value never has an encoding part. It is the empty string if nothing could be found, otherwise should look like fr_BE or it_IT. [1] "language" term used in the function name for consistency with the existing and related FGLocale::selectLanguage().
This commit is contained in:
parent
1bf3aee5df
commit
905e1973eb
2 changed files with 27 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue