FlightGear next
|
#include <locale.hxx>
Public Member Functions | |
FGLocale (SGPropertyNode *root) | |
virtual | ~FGLocale () |
bool | selectLanguage (const std::string &language={}) |
Select the locale's primary language according to user-level, system-level language settings and the language argument. | |
std::string | getLanguageId () const |
Return the value of _languageId, which uniquely identifies the language for the LanguageInfo class (handling of plural forms...). | |
std::string | getPreferredLanguage () const |
Return the preferred language according to user choice and/or settings. | |
void | loadAircraftTranslations () |
void | loadAddonTranslations () |
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. | |
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). | |
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. | |
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. | |
std::string | vlocalizedPrintf (const char *id, const char *resource, va_list args) |
void | clear () |
reset all data in the locale. | |
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. | |
Static Public Member Functions | |
static void | utf8toLatin1 (std::string &s) |
Simple UTF8 to Latin1 encoder. | |
Protected Member Functions | |
SGPropertyNode * | findLocaleNode (const std::string &language) |
Find a property node matching the given language. | |
void | loadResourceForDefaultTranslation (const SGPath &xmlFile, const std::string &domain, const std::string &resource) |
Load default strings for the requested resource ("atc", "menu", etc.). | |
void | loadDefaultTranslation (const simgear::Dir &defaultTranslationDir, const std::string &domain) |
Load all default translation files from the specified directory. | |
void | loadCoreResourcesForDefaultTranslation () |
Load the core default translation ('atc', 'menu', 'options', 'sys', etc.). | |
void | loadResourcesFromAircraftOrAddonDir (const SGPath &basePath, const std::string &domain) |
From an add-on or aircraft directory, load the default translation and, if available, the XLIFF file for the current locale. | |
void | loadXLIFFFromAircraftOrAddonDir (const SGPath &basePath, const std::string &domain) |
string_list | getUserLanguages () const |
Obtain user's default language settings. | |
std::string | findLanguageId () const |
Return the appropriate value for _languageId according to _currentLocale. | |
void | loadXLIFF (const SGPath &basePath, SGPropertyNode *localeNode, const std::string &domain) |
Load an XLIFF 1.2 file. | |
Protected Attributes | |
SGPropertyNode_ptr | _intl |
SGPropertyNode_ptr | _currentLocale |
std::string | _languageId |
This is used to fetch linguistic data such as the number of plural forms for the selected locale. | |
SGPropertyNode_ptr | _fallbackLocale |
Proper locale (corresponding to a /sim/intl/locale[n] node, as opposed to the default translation) used when none of the /sim/intl/locale[n]/lang nodes matches the –language value or other user language settings. | |
std::string | _currentLocaleString |
Corresponds to user's language settings, possibly overridden by the –language value. | |
Friends | |
class | FGTranslate |
Definition at line 124 of file locale.hxx.
FGLocale::FGLocale | ( | SGPropertyNode * | root | ) |
Definition at line 48 of file locale.cxx.
|
virtual |
Definition at line 54 of file locale.cxx.
void FGLocale::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.
Definition at line 431 of file locale.cxx.
|
protected |
Return the appropriate value for _languageId according to _currentLocale.
When _currentLocale isn't the empty shared pointer, alert if the /sim/intl/locale[n]/language-id node doesn't exist.
Definition at line 279 of file locale.cxx.
|
protected |
Find a property node matching the given language.
Definition at line 158 of file locale.cxx.
std::string FGLocale::getDefaultFont | ( | const char * | fallbackFont | ) |
Obtain default font for current locale.
Definition at line 556 of file locale.cxx.
std::string FGLocale::getLanguageId | ( | ) | const |
Return the value of _languageId, which uniquely identifies the language for the LanguageInfo class (handling of plural forms...).
Definition at line 305 of file locale.cxx.
std::string FGLocale::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.
defaultValue | returned if the requested translation is missing or empty and the default translation (source text) is empty. |
Due to these conditions, this only makes sense when FlightGear uses the default translation and some translatable “strings” have been defined as empty elements (so that their “source text” is empty).
Definition at line 533 of file locale.cxx.
std::size_t FGLocale::getLocalizedStringCount | ( | const std::string & | id, |
const std::string & | context ) const |
Return the number of strings with a given id in the specified context.
context | a string such as "menu", "options", "sys", etc. |
Definition at line 547 of file locale.cxx.
vector< string > FGLocale::getLocalizedStrings | ( | const std::string & | id, |
const std::string & | resource ) |
Obtain a list of translations that share the same tag name (id stem).
id | name of the tag in the default translation XML file |
resource | a string such as "menu", "options", "sys", etc. |
Definition at line 541 of file locale.cxx.
std::string FGLocale::getLocalizedStringWithIndex | ( | const std::string & | id, |
const std::string & | context, | ||
int | index ) const |
Obtain a single translation with the given identifier, context and index.
Definition at line 525 of file locale.cxx.
std::string FGLocale::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.
Definition at line 450 of file locale.cxx.
|
protected |
Obtain user's default language settings.
Determine locale/language settings on Linux/Unix.
Definition at line 140 of file locale.cxx.
void FGLocale::loadAddonTranslations | ( | ) |
Definition at line 324 of file locale.cxx.
void FGLocale::loadAircraftTranslations | ( | ) |
Definition at line 318 of file locale.cxx.
|
protected |
Load the core default translation ('atc', 'menu', 'options', 'sys', etc.).
Definition at line 310 of file locale.cxx.
|
protected |
Load all default translation files from the specified directory.
defaultTranslationDir | base directory for the XML files |
domain | target domain |
The XML files are looked for in two directories: defaultTranslationDir
and its auto-extracted
subdirectory. Each XML file is loaded as a resource whose name is the SGPath::file_base() of the file so that, e.g., atc.no_translate.xml is loaded as the 'atc' resource.
Definition at line 353 of file locale.cxx.
|
protected |
Load default strings for the requested resource ("atc", "menu", etc.).
To avoid confusing unrelated things, translatable strings from the simulator core (FGData), from an add-on or from the current aircraft are all stored in different domains. There are three kinds of domains:
Definition at line 481 of file locale.cxx.
|
protected |
From an add-on or aircraft directory, load the default translation and, if available, the XLIFF file for the current locale.
Definition at line 339 of file locale.cxx.
|
protected |
Load an XLIFF 1.2 file.
basePath | base for the relative path to XLIFF file that is the string value of node /sim/intl/locale[n]/⟨domain⟩/xliff. |
localeNode | pointer to the /sim/intl/locale[n] node for the current locale |
domain | a string such as 'core' or 'addons/⟨addonId⟩' |
Definition at line 455 of file locale.cxx.
|
protected |
Definition at line 381 of file locale.cxx.
std::string FGLocale::localizedPrintf | ( | const char * | id, |
const char * | resource, | ||
... ) |
Obtain a message string, from a localized resource ID, and use it as a printf format string.
Definition at line 577 of file locale.cxx.
bool FGLocale::selectLanguage | ( | const std::string & | language = {} | ) |
Select the locale's primary language according to user-level, system-level language settings and the language
argument.
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). |
Once this function returns, getLanguageId() is safe to call.
Definition at line 197 of file locale.cxx.
SGPropertyNode_ptr FGLocale::selectLanguageNode | ( | SGPropertyNode * | langs | ) | const |
Given a node with children corresponding to different language / locale codes, select one based on the user preferred language.
Definition at line 660 of file locale.cxx.
|
static |
Simple UTF8 to Latin1 encoder.
Definition at line 597 of file locale.cxx.
std::string FGLocale::vlocalizedPrintf | ( | const char * | id, |
const char * | resource, | ||
va_list | args ) |
Definition at line 586 of file locale.cxx.
|
friend |
Definition at line 358 of file locale.hxx.
|
protected |
Definition at line 302 of file locale.hxx.
|
protected |
Corresponds to user's language settings, possibly overridden by the –language value.
Not sure this is very useful, contrary to _languageId.
Definition at line 324 of file locale.hxx.
|
protected |
Proper locale (corresponding to a /sim/intl/locale[n] node, as opposed to the default translation) used when none of the /sim/intl/locale[n]/lang nodes matches the –language value or other user language settings.
Contrary to the default translation, this is normally proper English with two plural forms.
Definition at line 318 of file locale.hxx.
|
protected |
Definition at line 301 of file locale.hxx.
|
protected |
This is used to fetch linguistic data such as the number of plural forms for the selected locale.
The value is that of the 'language-id' (first and only) child of the _currentLocale node, except for the default locale which is characterized by _currentLocale == nullptr and _languageId == "default".
Definition at line 310 of file locale.hxx.