FlightGear next
TranslationResource Class Reference

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

Detailed Description

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.

Member Typedef Documentation

◆ intType

Constructor & Destructor Documentation

◆ TranslationResource() [1/2]

TranslationResource::TranslationResource ( )
delete

◆ TranslationResource() [2/2]

TranslationResource::TranslationResource ( std::string name)
explicitnoexcept

Constructor.

Parameters
nameresource name (used for error messages)

Definition at line 25 of file TranslationResource.cxx.

Member Function Documentation

◆ addTranslationUnit()

void TranslationResource::addTranslationUnit ( std::string name,
int index,
std::string sourceText,
bool hasPlural = false )

Add a translation unit to the TranslationResource.

Parameters
name“basic id” of the translation unit (which corresponds to the element name in the default translation XML file)
indexzero-based index used to distinguish between elements with the same name within a translation resource
sourceTexttext that the translation unit gives a translation of
hasPluraltells 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.

◆ get()

string TranslationResource::get ( const std::string & basicId,
int index = 0 ) const

Get a single translation.

Parameters
basicIdname of the XML element corresponding to the translation to retrieve in the default translation file for the specified resource
indexindex among strings sharing the same basicId
Returns
The translated string

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.

◆ getAll()

vector< string > TranslationResource::getAll ( const std::string & name) const

Get translations for all strings with a given element name.

Parameters
nameelement name (aka “basic id”) in the default translation XML file
Returns
A vector containing the first target text (i.e., first plural form) of each translated string with the specified element name

Definition at line 139 of file TranslationResource.cxx.

◆ getCount()

std::size_t TranslationResource::getCount ( const std::string & name) const

Get the number of translated strings with the given element name.

Parameters
nameelement name (aka “basic id”) in the default translation XML file
Returns
The number of translation units with basic id name in the TranslationResource

Definition at line 157 of file TranslationResource.cxx.

◆ getPlural()

string TranslationResource::getPlural ( intType cardinalNumber,
const std::string & basicId,
int index = 0 ) const

Same as get(), but for a string that has plural forms.

Parameters
cardinalNumberan integer correponding to a number of “things” (concrete or abstract)
basicIdsame as for get()
indexsame as for get()
Returns
The translated string

Definition at line 97 of file TranslationResource.cxx.

◆ getPluralWithDefault()

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.

Parameters
cardinalNumberan integer correponding to a number of “things” (concrete or abstract)
basicIdsame as for getWithDefault()
defaultValuesame as for getWithDefault()
indexsame as for getWithDefault()
Returns
The translated string or default value

Definition at line 130 of file TranslationResource.cxx.

◆ getWithDefault()

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.

Parameters
basicIdsame as for get()
defaultValuereturned if the string can't be found or is declared with an empty source text in the default translation
indexsame as for get()
Returns
The translated string or default value

Definition at line 122 of file TranslationResource.cxx.

◆ setFirstTargetText()

void TranslationResource::setFirstTargetText ( std::string name,
int index,
std::string targetText )

Set the first target text of a translation unit.

Parameters
name“basic id” of the translation unit to modify
indexindex 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)
targetTextfirst 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.

◆ setTargetTexts()

void TranslationResource::setTargetTexts ( std::string name,
int index,
std::vector< std::string > targetTexts )

Set all target texts of a translation unit.

Parameters
namesame as in setFirstTargetText()
indexsame as in setFirstTargetText()
targetTextsvector 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.

◆ setupGhost()

void TranslationResource::setupGhost ( )
static

Set up a Nasal type that wraps TranslationResource.

Definition at line 246 of file TranslationResource.cxx.

◆ translationUnit()

TranslationResource::TranslationUnitRef TranslationResource::translationUnit ( const std::string & name,
int index = 0 ) const

Return a shared pointer to a TranslationUnit.

Parameters
nameelement name (aka “basic id”) in the default translation XML file
indexzero-based index used to distinguish between elements with the same name in the TranslationResource
Returns
a shared pointer to the TranslationUnit with this name and index

Definition at line 65 of file TranslationResource.cxx.


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