TranslationUnit#

class TranslationUnit#

Class holding a source string and its translation in a language.

This class is a container for a source text and its translation in the language corresponding to the currently selected locale, including plural forms if any. The source text is a string in “engineering English”, known as a “master string” or “default translation”.

When the translation may depend on an integer (a number of “items” of any kind), instances of this class will have _hasPlural = true and their _sourceText member should use an indeterminate form such as “Found %1 file(s)”. Corresponding plural forms in proper English locales (as opposed to “engineering English”) will then be “Found %1 file” and “Found %1 files”; they will be chosen according to the number passed to FGTranslate::setCardinalNumber().

Public Functions

std::string getSourceText() const#

Return the source text of the object, i.e. the “engineering English” form.

void setSourceText(std::string text)#

Set the source text of the object, i.e. the “engineering English” form.

std::string getTargetText(int pluralFormIndex = 0) const#

Get the target text (translated string) associated to pluralFormIndex.

std::size_t getNumberOfTargetTexts() const#

Return the number of target texts (plural forms) present in the object.

void setTargetText(int pluralFormIndex, std::string text)#

Set the target text for the specified plural form.

void setTargetTexts(std::vector<std::string> texts)#

Set all target texts at once.

bool getPluralStatus() const#

Return the plural status of a translation unit.

The size of _targetTexts depends on whether the <trans-unit> in the XLIFF translation file contains a <target> element and on the plural status of the TranslationUnit (if its plural status is true and the string has been translated, the size of _targetTexts should correspond to the return value of LanguageInfo::getNumberOfPluralForms() for the selected language).

Returns:

True if the translated string is declared as having plural forms in the default translation

void setPluralStatus(int hasPlural)#

Set the plural status of a translation unit.

Parameters:

hasPlural – true if the translation unit has plural forms

std::string getTranslation() const#

Get the target text of a non-plural translation unit.

This function is for translatable strings without plural forms (i.e., those defined without has-plural="true" in the default translation.).

The return value is the first target text, unless it is empty (string not translated) or the translation unit has no target text (fgfs &#8212;language=default); in the latter two cases, the return value is the source text.

Returns:

The requested translation (in the selected language)

std::string getTranslation(intType cardinalNumber) const#

Get the target text of a translation unit that has plural forms.

This function is for translatable strings that have plural forms (i.e., those defined with has-plural="true" in the default translation). The selected form depends on the cardinalNumber argument.

Parameters:

cardinalNumber – an integer corresponding to a number of “things” (concrete or abstract)

Returns:

The requested translation (in the selected language)

Public Static Functions

static void setupGhost()#

Set up a Nasal type that wraps TranslationUnit.