NDEVR
API Documentation
Translator

Provides language translation services for the application. More...

Inheritance diagram for Translator:
[legend]
Collaboration diagram for Translator:
[legend]

Public Member Functions

 Translator ()
 Constructs a default Translator with no language loaded.
 Translator (const File &settings_file)
 Constructs a Translator from a settings file on disk.
 Translator (const StringView &translation_id)
 Constructs a Translator for the specified translation identifier.
 Translator (const Translator &translator)
 Copy constructor.
File activeTranslatorFile () const
 Returns the file path of the currently active translator file.
virtual void append (String &append, const String &text_string) const
 Appends a translated version of the given text string.
virtual void append (String &append, const UUID &id, const String &default_text) const
 Appends a translated string looked up by UUID, falling back to a default.
String commonCharacters () const
 Returns a string containing the most common characters for this language.
virtual String convertNumber (const String &number_string, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits) const
 Converts a numeric string into a locale-appropriate formatted string.
void copyFrom (const Translator &trans, bool use_existing_ini_file)
 Copies translation settings from another Translator.
void copyTranslationsFrom (const Translator &trans)
 Copies only the translated string entries from another Translator.
void getINI (INIFactory &factory) override
 Populates or reads translation data from the given INI factory.
const Stringid () const
 Returns the identifier of this translation.
bool isLeftToRight () const
 Returns whether this language reads left-to-right.
const Stringname () const
 Returns the human-readable name of this language.
Translatoroperator= (const Translator &translation)
 Assignment operator.
void saveTranslation (File location=File())
 Saves the current translation data to a file.
void setID (const StringView &id)
 Sets the translation identifier.
void setName (const StringView &name)
 Sets the human-readable language name.
const Dictionary< UUID, String > & translatedStrings () const
 Returns the dictionary of all translated strings keyed by UUID.
INIFactorytranslationINI () const
 Returns a reference to the INI factory managing translation entries.
File translatorFile (bool user_file) const
 Returns the file path for the translator data file.
Public Member Functions inherited from INIInterface
 INIInterface ()
 Constructs an INIInterface with no default INI file.
 INIInterface (const File &default_ini)
 Constructs an INIInterface with the specified default INI file.
virtual ~INIInterface ()
 Virtual destructor for safe polymorphic cleanup.
virtual void finishReadingINI (INIFactory &)
 Called after reading an INI file.
virtual void prepareForINI (INIFactory &)
 Called before reading or writing an INI file.
virtual bool readINIOptions ()
 Reads INI options from the default INI file.
virtual bool readINIOptions (File &ini_file)
 Reads INI options from the specified INI file.
virtual bool saveINIOptions (bool multithead=false)
 Saves INI options to the default INI file.
virtual bool saveINIOptions (File &ini_file, bool multithead=false)
 Saves INI options to the specified INI file.
void setDefaultINIFile (const File &file)
 Sets the default INI file path used for reading and writing options.
virtual void writeToLog (const StringView &title, LogPtr log, uint01 log_level=2U)
 Writes the current INI options to the specified log with a title.
virtual void writeToLog (LogPtr log, uint01 log_level=2U)
 Writes the current INI options to the specified log.

Static Public Member Functions

static UUID DefaultFastID (const StringView &text_string)
 Computes a UUID for the given text string using a fast hashing method.
static UUID DefaultID (const StringView &text_string)
 Computes a default UUID for the given text string.
static String DefaultReadableLabel (const StringView &text_string)
 Generates a default human-readable label from a text string.
static String DefaultReadableLabel (const UUID &text_string)
 Generates a default human-readable label from a UUID.
static Dictionary< String, TranslatorGetAvailableTranslations (File folder=File())
 Discovers all available translation files in the given folder.
static TranslatorMainTranslator ()
 Returns the application's main Translator instance.
static TranslatorMainTranslator (const StringView &language)
 Returns the main Translator for a specific language.
static void SetMainTranslator (Translator *translator)
 Sets the application's main Translator instance.

Static Public Attributes

static Resource< Translator * > main_translator
 The global main translator resource.
static Dictionary< String, Translator * > translators
 Registry of all loaded translators keyed by language ID.

Protected Member Functions

void ensureLanguageLoaded () const
 Lazily loads the language data from disk if not already loaded.
void init ()
 Initializes internal state for the Translator.

Protected Attributes

String m_common_characters
 A string of commonly used characters in this language.
char m_decimal_sep
 The decimal separator character (typically '.').
bool m_has_loaded_language
 Whether the language data has been loaded from disk.
INIFactory m_language_ini
 The INI factory managing the language translation file.
String m_language_name
 The human-readable name of the language.
bool m_left_to_right
 Whether the language reads left-to-right (typically true).
char m_number_sep
 The thousands separator character (typically ',').
Dictionary< UUID, Stringm_translated_strings
 Cached dictionary of translated strings keyed by UUID.
File m_translation_file
 The file path of the translation data.
String m_translation_id
 The unique identifier for this translation.
Protected Attributes inherited from INIInterface
File m_default_ini
 The default file path used for reading and writing INI options.

Detailed Description

Provides language translation services for the application.


Manages loading, storing, and applying translations from INI-based language files. Supports number formatting, text direction, and lookup of translated strings by UUID. A global main translator instance is available for application-wide use.

See also
TranslatedString, String

Definition at line 60 of file Translator.h.

Constructor & Destructor Documentation

◆ Translator() [1/3]

Translator::Translator ( const StringView & translation_id)

Constructs a Translator for the specified translation identifier.

Parameters
[in]translation_idThe identifier of the language translation to use.

◆ Translator() [2/3]

Translator::Translator ( const File & settings_file)

Constructs a Translator from a settings file on disk.

Parameters
[in]settings_fileThe INI file containing translation data.

◆ Translator() [3/3]

Translator::Translator ( const Translator & translator)

Copy constructor.

Parameters
[in]translatorThe Translator to copy from.

References Translator().

Member Function Documentation

◆ activeTranslatorFile()

File Translator::activeTranslatorFile ( ) const

Returns the file path of the currently active translator file.

Returns
The active translation File.

◆ append() [1/2]

virtual void Translator::append ( String & append,
const String & text_string ) const
virtual

Appends a translated version of the given text string.

Parameters
[in]appendThe string to append the translated text to.
[in]text_stringThe English text to translate and append.

References append().

Referenced by append(), and append().

◆ append() [2/2]

virtual void Translator::append ( String & append,
const UUID & id,
const String & default_text ) const
virtual

Appends a translated string looked up by UUID, falling back to a default.

Parameters
[in]appendThe string to append the translated text to.
[in]idThe UUID identifying the translation entry.
[in]default_textThe fallback text if no translation is found.

References append().

◆ commonCharacters()

String Translator::commonCharacters ( ) const

Returns a string containing the most common characters for this language.

Returns
A String of common characters.

◆ convertNumber()

virtual String Translator::convertNumber ( const String & number_string,
bool add_comma,
uint04 min_decimals,
uint04 max_decimals,
uint04 min_digits ) const
virtual

Converts a numeric string into a locale-appropriate formatted string.

Parameters
[in]number_stringThe raw number string to format.
[in]add_commaWhether to insert thousands separators.
[in]min_decimalsThe minimum number of decimal places to display.
[in]max_decimalsThe maximum number of decimal places to display.
[in]min_digitsThe minimum number of integer digits to display.
Returns
The formatted number string.

◆ copyFrom()

void Translator::copyFrom ( const Translator & trans,
bool use_existing_ini_file )

Copies translation settings from another Translator.

Parameters
[in]transThe source Translator to copy from.
[in]use_existing_ini_fileWhether to reuse the existing INI file rather than replacing it.

References Translator().

◆ copyTranslationsFrom()

void Translator::copyTranslationsFrom ( const Translator & trans)

Copies only the translated string entries from another Translator.

Parameters
[in]transThe source Translator whose translations are copied.

References Translator().

◆ DefaultFastID()

UUID Translator::DefaultFastID ( const StringView & text_string)
static

Computes a UUID for the given text string using a fast hashing method.

Parameters
[in]text_stringThe text to generate a UUID from.
Returns
The computed UUID.

◆ DefaultID()

UUID Translator::DefaultID ( const StringView & text_string)
static

Computes a default UUID for the given text string.

Parameters
[in]text_stringThe text to generate a UUID from.
Returns
The computed UUID.

◆ DefaultReadableLabel() [1/2]

String Translator::DefaultReadableLabel ( const StringView & text_string)
static

Generates a default human-readable label from a text string.

Parameters
[in]text_stringThe raw text to convert to a readable label.
Returns
The formatted readable label.

Referenced by TranslationTools::addOption(), TranslationTools::setupFile(), and QCustomTranslator::translate().

◆ DefaultReadableLabel() [2/2]

String Translator::DefaultReadableLabel ( const UUID & text_string)
static

Generates a default human-readable label from a UUID.

Parameters
[in]text_stringThe UUID to convert to a readable label.
Returns
The formatted readable label.

◆ GetAvailableTranslations()

Dictionary< String, Translator > Translator::GetAvailableTranslations ( File folder = File())
static

Discovers all available translation files in the given folder.

Parameters
[in]folderThe folder to search. If empty, uses the default location.
Returns
A Dictionary mapping language identifiers to Translator instances.

◆ getINI()

void Translator::getINI ( INIFactory & factory)
overridevirtual

Populates or reads translation data from the given INI factory.

Parameters
[in]factoryThe INI factory used for serialization.

Implements INIInterface.

◆ id()

const String & Translator::id ( ) const
inline

Returns the identifier of this translation.

Returns
A const reference to the translation ID string.

Definition at line 142 of file Translator.h.

References m_translation_id.

◆ isLeftToRight()

bool Translator::isLeftToRight ( ) const

Returns whether this language reads left-to-right.

Returns
True if the language is left-to-right, false otherwise.

◆ MainTranslator() [1/2]

Translator * Translator::MainTranslator ( )
static

Returns the application's main Translator instance.

Returns
A pointer to the main Translator.

References Translator().

◆ MainTranslator() [2/2]

Translator * Translator::MainTranslator ( const StringView & language)
static

Returns the main Translator for a specific language.

Parameters
[in]languageThe language identifier to look up.
Returns
A pointer to the Translator for the specified language.

References Translator().

◆ name()

const String & Translator::name ( ) const
inline

Returns the human-readable name of this language.

Returns
A const reference to the language name string.

Definition at line 147 of file Translator.h.

References m_language_name.

Referenced by setName().

◆ operator=()

Translator & Translator::operator= ( const Translator & translation)

Assignment operator.

Parameters
[in]translationThe Translator to assign from.
Returns
A reference to this Translator.

References Translator().

◆ saveTranslation()

void Translator::saveTranslation ( File location = File())

Saves the current translation data to a file.

Parameters
[in]locationThe file to save to. If empty, uses the default location.

◆ setID()

void Translator::setID ( const StringView & id)

Sets the translation identifier.

Parameters
[in]idThe new translation ID.

◆ SetMainTranslator()

void Translator::SetMainTranslator ( Translator * translator)
static

Sets the application's main Translator instance.

Parameters
[in]translatorA pointer to the Translator to use as the main translator.

References Translator().

◆ setName()

void Translator::setName ( const StringView & name)

Sets the human-readable language name.

Parameters
[in]nameThe new language name.

References name().

◆ translatedStrings()

const Dictionary< UUID, String > & Translator::translatedStrings ( ) const

Returns the dictionary of all translated strings keyed by UUID.

Returns
A const reference to the translated strings dictionary.

◆ translationINI()

INIFactory & Translator::translationINI ( ) const

Returns a reference to the INI factory managing translation entries.

Returns
A reference to the internal INIFactory.

◆ translatorFile()

File Translator::translatorFile ( bool user_file) const

Returns the file path for the translator data file.

Parameters
[in]user_fileWhether to return the user-specific file rather than the system file.
Returns
The translation File.

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