1
0
Fork 0

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:
Florent Rougon 2017-04-26 21:56:37 +02:00
parent 1bf3aee5df
commit 905e1973eb
2 changed files with 27 additions and 2 deletions

View file

@ -170,6 +170,10 @@ 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) {
@ -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

View file

@ -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).
@ -123,6 +135,7 @@ protected:
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