FlightGear next
|
Class that holds translation units within a resource (“context”) More...
#include <TranslationResource.hxx>
Public Types | |
using | intType = flightgear::LanguageInfo::intType |
Public Member Functions | |
TranslationResource ()=delete | |
TranslationResource (std::string name) noexcept | |
Constructor. | |
void | addTranslationUnit (std::string name, int index, std::string sourceText, bool hasPlural=false) |
Add a translation unit to the TranslationResource. | |
void | setFirstTargetText (std::string name, int index, std::string targetText) |
Set the first target text of a translation unit. | |
void | setTargetTexts (std::string name, int index, std::vector< std::string > targetTexts) |
Set all target texts of a translation unit. | |
std::shared_ptr< TranslationUnit > | translationUnit (const std::string &name, int index=0) const |
Return a shared pointer to a TranslationUnit. | |
std::string | get (const std::string &basicId, int index=0) const |
Get a single translation. | |
std::string | getPlural (intType cardinalNumber, const std::string &basicId, int index=0) const |
Same as get(), but for a string that has plural forms. | |
std::string | getWithDefault (const std::string &basicId, const std::string &defaultValue, int index=0) const |
Get a single translation, with default for missing or empty strings. | |
std::string | getPluralWithDefault (intType cardinalNumber, const std::string &basicId, const std::string &defaultValue, int index=0) const |
Same as getWithDefault(), but for a string that has plural forms. | |
std::vector< std::string > | getAll (const std::string &name) const |
Get translations for all strings with a given element name. | |
std::size_t | getCount (const std::string &name) const |
Get the number of translated strings with the given element name. | |
Static Public Member Functions | |
static void | setupGhost () |
Set up a Nasal type that wraps TranslationResource. | |
Class that holds translation units within a resource (“context”)
This class provides functions for adding TranslationUnit instances to a translation “resource”, modifying these objects and retrieving information from them, in particular obtaining translations associated to a translation “basic id” within the resource.
Definition at line 30 of file TranslationResource.hxx.
Definition at line 33 of file TranslationResource.hxx.
|
delete |
|
explicitnoexcept |
Constructor.
name | resource name (used for error messages) |
Definition at line 25 of file TranslationResource.cxx.
void TranslationResource::addTranslationUnit | ( | std::string | name, |
int | index, | ||
std::string | sourceText, | ||
bool | hasPlural = false ) |
Add a translation unit to the TranslationResource.
name | “basic id” of the translation unit (which corresponds to the element name in the default translation XML file) |
index | zero-based index used to distinguish between elements with the same name within a translation resource |
sourceText | text that the translation unit gives a translation of |
hasPlural | tells whether the translation unit has plural forms (variants chosen based on a “cardinal number”) |
The added TranslationUnit instance has an empty list of target texts.
Definition at line 29 of file TranslationResource.cxx.
string TranslationResource::get | ( | const std::string & | basicId, |
int | index = 0 ) const |
Get a single translation.
basicId | name of the XML element corresponding to the translation to retrieve in the default translation file for the specified resource |
index | index among strings sharing the same basicId |
There may be several elements named basicId in the default translation file for the specified resource; these elements are distinguished by their index.
If there is no translatable string with the specified basicId and index in the TranslationResource
, return an empty string.
Definition at line 75 of file TranslationResource.cxx.
vector< string > TranslationResource::getAll | ( | const std::string & | name | ) | const |
Get translations for all strings with a given element name.
name | element name (aka “basic id”) in the default translation XML file |
Definition at line 139 of file TranslationResource.cxx.
std::size_t TranslationResource::getCount | ( | const std::string & | name | ) | const |
Get the number of translated strings with the given element name.
name | element name (aka “basic id”) in the default translation XML file |
Definition at line 157 of file TranslationResource.cxx.
string TranslationResource::getPlural | ( | intType | cardinalNumber, |
const std::string & | basicId, | ||
int | index = 0 ) const |
string TranslationResource::getPluralWithDefault | ( | intType | cardinalNumber, |
const std::string & | basicId, | ||
const std::string & | defaultValue, | ||
int | index = 0 ) const |
Same as getWithDefault(), but for a string that has plural forms.
cardinalNumber | an integer correponding to a number of “things” (concrete or abstract) |
basicId | same as for getWithDefault() |
defaultValue | same as for getWithDefault() |
index | same as for getWithDefault() |
Definition at line 130 of file TranslationResource.cxx.
string TranslationResource::getWithDefault | ( | const std::string & | basicId, |
const std::string & | defaultValue, | ||
int | index = 0 ) const |
Get a single translation, with default for missing or empty strings.
basicId | same as for get() |
defaultValue | returned if the string can't be found or is declared with an empty source text in the default translation |
index | same as for get() |
Definition at line 122 of file TranslationResource.cxx.
void TranslationResource::setFirstTargetText | ( | std::string | name, |
int | index, | ||
std::string | targetText ) |
Set the first target text of a translation unit.
name | “basic id” of the translation unit to modify |
index | index used to distinguish between translation units that share the same “basic id” (which corresponds to elements having the same name in a default translation XML file) |
targetText | first plural form of the translation associated to name and index (this is the only form for translatable strings that have “no plural form”) |
Definition at line 37 of file TranslationResource.cxx.
void TranslationResource::setTargetTexts | ( | std::string | name, |
int | index, | ||
std::vector< std::string > | targetTexts ) |
Set all target texts of a translation unit.
name | same as in setFirstTargetText() |
index | same as in setFirstTargetText() |
targetTexts | vector of strings which are translations in the order of plural forms for the target language of the translation unit |
Definition at line 52 of file TranslationResource.cxx.
|
static |
Set up a Nasal type that wraps TranslationResource.
Definition at line 246 of file TranslationResource.cxx.
TranslationResource::TranslationUnitRef TranslationResource::translationUnit | ( | const std::string & | name, |
int | index = 0 ) const |
Return a shared pointer to a TranslationUnit.
name | element name (aka “basic id”) in the default translation XML file |
index | zero-based index used to distinguish between elements with the same name in the TranslationResource |
Definition at line 65 of file TranslationResource.cxx.