FlightGear next
TranslationUnit Class Reference

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

#include <TranslationUnit.hxx>

Public Types

using intType = flightgear::LanguageInfo::intType
 

Public Member Functions

 TranslationUnit (const std::string sourceText={}, const std::vector< std::string > targetTexts={}, bool hasPlural=false)
 
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.
 
void setPluralStatus (int hasPlural)
 Set the plural status of a translation unit.
 
std::string getTranslation () const
 Get the target text of a non-plural translation unit.
 
std::string getTranslation (intType cardinalNumber) const
 Get the target text of a translation unit that has plural forms.
 

Static Public Member Functions

static void setupGhost ()
 Set up a Nasal type that wraps TranslationUnit.
 

Detailed Description

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().

Definition at line 33 of file TranslationUnit.hxx.

Member Typedef Documentation

◆ intType

Constructor & Destructor Documentation

◆ TranslationUnit()

TranslationUnit::TranslationUnit ( const std::string sourceText = {},
const std::vector< std::string > targetTexts = {},
bool hasPlural = false )
explicit

Definition at line 27 of file TranslationUnit.cxx.

Member Function Documentation

◆ getNumberOfTargetTexts()

std::size_t TranslationUnit::getNumberOfTargetTexts ( ) const

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

Definition at line 54 of file TranslationUnit.cxx.

◆ getPluralStatus()

bool TranslationUnit::getPluralStatus ( ) const

Return the plural status of a translation unit.

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

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).

Definition at line 73 of file TranslationUnit.cxx.

◆ getSourceText()

std::string TranslationUnit::getSourceText ( ) const

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

Definition at line 35 of file TranslationUnit.cxx.

◆ getTargetText()

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

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

Definition at line 45 of file TranslationUnit.cxx.

◆ getTranslation() [1/2]

std::string TranslationUnit::getTranslation ( ) const

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

Returns
The requested translation (in the selected language)

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 –language=default); in the latter two cases, the return value is the source text.

Definition at line 83 of file TranslationUnit.cxx.

◆ getTranslation() [2/2]

std::string TranslationUnit::getTranslation ( intType cardinalNumber) const

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

Parameters
cardinalNumberan integer correponding to a number of “things” (concrete or abstract)
Returns
The requested translation (in the selected language)

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.

Definition at line 101 of file TranslationUnit.cxx.

◆ setPluralStatus()

void TranslationUnit::setPluralStatus ( int hasPlural)

Set the plural status of a translation unit.

Parameters
hasPluraltrue if the translation unit has plural forms

Definition at line 78 of file TranslationUnit.cxx.

◆ setSourceText()

void TranslationUnit::setSourceText ( std::string text)

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

Definition at line 40 of file TranslationUnit.cxx.

◆ setTargetText()

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

Set the target text for the specified plural form.

Definition at line 59 of file TranslationUnit.cxx.

◆ setTargetTexts()

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

Set all target texts at once.

Definition at line 68 of file TranslationUnit.cxx.

◆ setupGhost()

void TranslationUnit::setupGhost ( )
static

Set up a Nasal type that wraps TranslationUnit.

Definition at line 184 of file TranslationUnit.cxx.


The documentation for this class was generated from the following files: