NDEVR
API Documentation
TranslatedString

Any text displayed to the user should be defined as a TranslatedString which allows the program to look up a translation, if available. More...

Public Member Functions

 TranslatedString ()
 Constructs an empty TranslatedString with no translation or English text.
 TranslatedString (const StringView &raw_string)
 Constructs a TranslatedString from a raw string, computing a translation ID from the content.
 TranslatedString (const TranslatedString &translation)
 Copy constructor.
 TranslatedString (const UUID &translation_id, const StringView &english)
 Constructs a TranslatedString with an explicit translation ID and English text.
 TranslatedString (TranslatedString &&translation) noexcept
 Move constructor.
 ~TranslatedString ()
 Destructor.
bool canReplaceInTranslation (const StringView &id) const
 Checks whether the given identifier exists as a replaceable placeholder in this translation.
const StringenglishDefine () const
 Returns the original English definition string.
String englishTranslation () const
 Returns the English translation of this string.
bool hasReplacements () const
 Checks whether this string has any placeholder replacements applied.
String internalValue () const
 Returns the internal representation of this translated string, including replacement markers.
bool isEmpty () const
 Checks whether this translated string is empty (has no English text or translation).
bool isTranslatable () const
 Checks whether this string has a translation ID and can be translated.
bool operator!= (const TranslatedString &translation) const
 Inequality comparison operator.
bool operator< (const TranslatedString &value) const
 Less-than comparison operator, compares by English translation.
TranslatedStringoperator= (const TranslatedString &translation) noexcept
 Copy assignment operator.
TranslatedStringoperator= (TranslatedString &&translation) noexcept
 Move assignment operator.
bool operator== (const TranslatedString &translation) const
 Equality comparison operator.
bool operator> (const TranslatedString &value) const
 Greater-than comparison operator, compares by English translation.
const String readableID () const
 Returns a human-readable identifier for this translated string, useful for debugging.
TranslatedStringreplace (const StringView &sub_string, const StringView &replacement)
 Replaces occurrences of a placeholder substring with a raw string replacement.
TranslatedStringreplace (const StringView &sub_string, const TranslatedString &replacement)
 Replaces occurrences of a placeholder substring with a translated replacement.
void replaceVals (String &value) const
 Applies all stored replacement values to the given string, substituting placeholders.
void retranslate ()
 Forces a retranslation of the cached translated string using the current language setting.
StringView translation () const
 Returns the translated string for the current application language.
String translation (const String &language) const
 Returns the translation of this string for a specific language.
const UUIDtranslationID () const
 Returns the UUID that identifies this translatable string in the translation database.

Static Public Member Functions

static void AppendTranslated (const StringView &raw_string, String &string)
 Appends the translated version of a raw string to an existing string.
static TranslatedString DirectString (const StringView &sub_string)
 If a string does not have a translation (EG: reading from an already translated string) this operation ensures no translation will be attempted when calling translate on the resulting object.

Detailed Description

Any text displayed to the user should be defined as a TranslatedString which allows the program to look up a translation, if available.


See also
String, Translator

Definition at line 15 of file TranslatedString.h.

Constructor & Destructor Documentation

◆ ~TranslatedString()

TranslatedString::~TranslatedString ( )

Destructor.

Cleans up any replacement strings owned by this object.

◆ TranslatedString() [1/4]

TranslatedString::TranslatedString ( const TranslatedString & translation)

Copy constructor.

Creates a TranslatedString from another.

Parameters
[in]translationThe TranslatedString to copy.

References TranslatedString(), and translation().

◆ TranslatedString() [2/4]

TranslatedString::TranslatedString ( TranslatedString && translation)
noexcept

Move constructor.

Transfers ownership from another TranslatedString.

Parameters
[in]translationThe TranslatedString to move from.

References TranslatedString(), and translation().

◆ TranslatedString() [3/4]

TranslatedString::TranslatedString ( const StringView & raw_string)
explicit

Constructs a TranslatedString from a raw string, computing a translation ID from the content.

Parameters
[in]raw_stringThe raw English string to use as the basis for translation.

◆ TranslatedString() [4/4]

TranslatedString::TranslatedString ( const UUID & translation_id,
const StringView & english )

Constructs a TranslatedString with an explicit translation ID and English text.

Parameters
[in]translation_idThe UUID identifying the translation entry.
[in]englishThe English text for this translatable string.

Member Function Documentation

◆ AppendTranslated()

void TranslatedString::AppendTranslated ( const StringView & raw_string,
String & string )
static

Appends the translated version of a raw string to an existing string.

Parameters
[in]raw_stringThe raw string to translate and append.
[in]stringThe target string to append the translation to.

◆ canReplaceInTranslation()

bool TranslatedString::canReplaceInTranslation ( const StringView & id) const

Checks whether the given identifier exists as a replaceable placeholder in this translation.

Parameters
[in]idThe placeholder identifier to search for.
Returns
True if the placeholder can be replaced in this translation.

◆ englishDefine()

const String & TranslatedString::englishDefine ( ) const

Returns the original English definition string.

Returns
A const reference to the English string.

◆ englishTranslation()

String TranslatedString::englishTranslation ( ) const

◆ hasReplacements()

bool TranslatedString::hasReplacements ( ) const

Checks whether this string has any placeholder replacements applied.

Returns
True if one or more replacements have been registered.

◆ internalValue()

String TranslatedString::internalValue ( ) const

Returns the internal representation of this translated string, including replacement markers.

Returns
The internal string value.

◆ isEmpty()

bool TranslatedString::isEmpty ( ) const

Checks whether this translated string is empty (has no English text or translation).

Returns
True if the string contains no text.

◆ isTranslatable()

bool TranslatedString::isTranslatable ( ) const

Checks whether this string has a translation ID and can be translated.

Returns
True if a translation lookup can be performed for this string.

◆ operator!=()

bool TranslatedString::operator!= ( const TranslatedString & translation) const

Inequality comparison operator.

Parameters
[in]translationThe TranslatedString to compare against.
Returns
True if the two TranslatedStrings are not equal.

References TranslatedString(), and translation().

◆ operator<()

bool TranslatedString::operator< ( const TranslatedString & value) const

Less-than comparison operator, compares by English translation.

Parameters
[in]valueThe TranslatedString to compare against.
Returns
True if this string is less than the other.

References TranslatedString().

◆ operator=() [1/2]

TranslatedString & TranslatedString::operator= ( const TranslatedString & translation)
noexcept

Copy assignment operator.

Parameters
[in]translationThe TranslatedString to copy.
Returns
A reference to this TranslatedString.

References TranslatedString(), and translation().

◆ operator=() [2/2]

TranslatedString & TranslatedString::operator= ( TranslatedString && translation)
noexcept

Move assignment operator.

Parameters
[in]translationThe TranslatedString to move from.
Returns
A reference to this TranslatedString.

References TranslatedString(), and translation().

◆ operator==()

bool TranslatedString::operator== ( const TranslatedString & translation) const

Equality comparison operator.

Parameters
[in]translationThe TranslatedString to compare against.
Returns
True if the two TranslatedStrings are equal.

References TranslatedString(), and translation().

◆ operator>()

bool TranslatedString::operator> ( const TranslatedString & value) const

Greater-than comparison operator, compares by English translation.

Parameters
[in]valueThe TranslatedString to compare against.
Returns
True if this string is greater than the other.

References TranslatedString().

◆ readableID()

const String TranslatedString::readableID ( ) const

Returns a human-readable identifier for this translated string, useful for debugging.

Returns
A readable String representation of the translation ID.

Referenced by GenericOptionGroup::getOption(), GenericOptionGroup::getOption(), and GenericOptionGroup::hasOption().

◆ replace() [1/2]

TranslatedString & TranslatedString::replace ( const StringView & sub_string,
const StringView & replacement )

Replaces occurrences of a placeholder substring with a raw string replacement.

Parameters
[in]sub_stringThe placeholder substring to find.
[in]replacementThe raw string to substitute in place of the placeholder.
Returns
A reference to this TranslatedString after replacement.

References TranslatedString().

◆ replace() [2/2]

TranslatedString & TranslatedString::replace ( const StringView & sub_string,
const TranslatedString & replacement )

Replaces occurrences of a placeholder substring with a translated replacement.

Parameters
[in]sub_stringThe placeholder substring to find.
[in]replacementThe TranslatedString to substitute in place of the placeholder.
Returns
A reference to this TranslatedString after replacement.

References TranslatedString().

Referenced by TimeFormatException::makeMessage().

◆ replaceVals()

void TranslatedString::replaceVals ( String & value) const

Applies all stored replacement values to the given string, substituting placeholders.

Parameters
[in]valueThe string in which to perform placeholder replacements.

◆ translation() [1/2]

StringView TranslatedString::translation ( ) const

Returns the translated string for the current application language.

Returns
A StringView of the translated text, or the English text if no translation is available.

Referenced by TranslatedString(), TranslatedString(), operator!=(), operator=(), operator=(), and operator==().

◆ translation() [2/2]

String TranslatedString::translation ( const String & language) const

Returns the translation of this string for a specific language.

Parameters
[in]languageThe language code to translate into.
Returns
The translated text in the specified language.

◆ translationID()

const UUID & TranslatedString::translationID ( ) const

Returns the UUID that identifies this translatable string in the translation database.

Returns
A const reference to the translation UUID.

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