FGLocale#

class FGLocale#

Public Functions

bool selectLanguage(const std::string &language = {})#

Select the locale’s primary language according to user-level, system-level language settings and the language argument.

Once this function returns, getLanguageId() is safe to call.

Parameters:

language – locale specification such as fr, fr_FR or fr_FR.UTF-8; it takes precedence over system settings (pass an empty value if you want it to be ignored). The special value ‘default’ causes FlightGear to use the “default translation” (see above).

std::string getLanguageId() const#

Return the value of _languageId, which uniquely identifies the language for the LanguageInfo class (handling of plural forms…).

Returns:

“default” for the default translation; else, the string value of the /sim/intl/locale[n]/language-id node where /sim/intl/locale[n] corresponds to the selected locale

std::string getPreferredLanguage() const#

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-empty, because the latter may have an encoding specifier, while values returned by getPreferredLanguage() never have that.

See also

getLanguageId()

std::string getLocalizedStringWithIndex(const std::string &id, const std::string &context, int index) const#

Obtain a single translation with the given identifier, context and index.

std::string getLocalizedString(const std::string &id, const std::string &resource, const std::string &defaultValue = {})#

Obtain a single string matching the given id, with fallback. Selected context refers to “menu”, “options”, “dialog” etc.

Due to these conditions, this only makes sense when some translatable “strings” have been defined as empty elements (so that their “source text” is empty).

Parameters:

defaultValue – returned if the requested translation is missing or empty and the default translation (source text) is empty.

std::vector<std::string> getLocalizedStrings(const std::string &id, const std::string &resource)#

Obtain a list of translations that share the same tag name (id stem).

Parameters:
  • id – name of the tag in the default translation XML file

  • resource – a string such as “menu”, “options”, “sys”, etc.

Returns:

A vector of translated strings

std::size_t getLocalizedStringCount(const std::string &id, const std::string &context) const#

Return the number of strings with a given id in the specified context

Parameters:

context – a string such as “menu”, “options”, “sys”, etc.

std::string getDefaultFont(const char *fallbackFont)#

Obtain default font for current locale.

std::string localizedPrintf(const char *id, const char *resource, ...)#

Obtain a message string, from a localized resource ID, and use it as a printf format string.

void clear()#

reset all data in the locale. This is needed to allow the launcher to use the code, without disturbing the main behaviour. Afteer calling this you can do selectLangauge again without problems.

SGPropertyNode_ptr selectLanguageNode(SGPropertyNode *langs) const#

Given a node with children corresponding to different language / locale codes, select one based on the user preferred language.

Public Static Functions

static void utf8toLatin1(std::string &s)#

Simple UTF8 to Latin1 encoder.