NDEVR
API Documentation
TranslationTools

Scans source code for translation macros (_t, _td, etc.) and generates .tr translation files for all supported languages. More...

Collaboration diagram for TranslationTools:
[legend]

Public Member Functions

void addOption (INIFactory &translator, const String &s_label, const String &value)
 Adds a translation entry to the INI factory, checking for duplicates in debug builds.
void getFiles (Buffer< File > &files, const File &file)
 Recursively collects source files with matching extensions.
void makeTranslation ()
 Performs the full translation generation process: scans all source files, generates the master English translation, and updates all other language files.
void processString (String &s, Scanner &scan, uint04 start_index, const char *end_seq)
 Extracts a translation string from source code, handling multi-line strings.
void replaceStringVars (String &s)
 Replaces escape sequences in a string with their actual characters.
void setupFile (INIFactory &translator, File file)
 Scans a single source file for translation macros and adds entries to the translator.

Static Public Member Functions

static void convertBrackets (INIFactory &ini)
 Converts square bracket sequences to hash-based placeholders for safe INI storage.
static void convertFromBrackets (INIFactory &ini, const INIFactory &ref)
 Converts hash-based placeholders back to square bracket sequences using a reference.
static void getDirs (Buffer< File > &files, const File &file)
 Recursively collects directories, excluding known non-source directories.

Public Attributes

Buffer< StringViewcomplex_tr = { "_td(\"" ,"_tdq(\"", "_tid(\"" }
 Complex translation macro patterns with label-value pairs.
Buffer< StringViewcomplex_utf8_tr = { "_td(\"" ,"_tdq(\"","_tqo(\"" }
 Complex UTF-8 translation macro patterns.
Buffer< Stringextensions = { String(".h"), String(".hpp"), String(".cpp") }
 File extensions to scan.
Buffer< StringViewqt_tr = { "QApplication::translate(\"", "QCoreApplication::translate(\"" }
 Qt translation function patterns.
Buffer< StringViewsimple_tr = { "_t(\"" ,"_tq(\"","_tqa(\"","_tqs(\"", "_to(\"", "_ti(\"" }
 Simple translation macro patterns.
Buffer< Stringsource_roots = { String("$(NDEVR_SOURCE_DIR)"), String("$(NDEVR_SOURCE_DIR)\\..\\Carlson\\") }
 Root directories to scan for source files.
File translation_folder = File("$(NDEVR_SOURCE_DIR)\\Resources\\Translations\\")
 Directory containing translation files.
StringView utf8 = "utf8(\""
 UTF-8 string literal prefix pattern.

Detailed Description

Scans source code for translation macros (_t, _td, etc.) and generates .tr translation files for all supported languages.

Definition at line 13 of file TranslationTools.h.

Member Function Documentation

◆ addOption()

void TranslationTools::addOption ( INIFactory & translator,
const String & s_label,
const String & value )
inline

Adds a translation entry to the INI factory, checking for duplicates in debug builds.

Parameters
[in]translatorThe INI factory storing translations.
[in]s_labelThe translation key label.
[in]valueThe translation value.

Definition at line 73 of file TranslationTools.h.

References INIFactory::addManagedOption(), Translator::DefaultReadableLabel(), INIFactory::getOption(), and INIFactory::hasOption().

Referenced by setupFile().

◆ convertBrackets()

void TranslationTools::convertBrackets ( INIFactory & ini)
inlinestatic

Converts square bracket sequences to hash-based placeholders for safe INI storage.

Parameters
[in]iniThe INI factory to modify.

Definition at line 219 of file TranslationTools.h.

References INIFactory::extraOptionsRef(), StringView::hash(), StringView::indexOf(), IsValid(), and StringView::substr().

Referenced by makeTranslation().

◆ convertFromBrackets()

void TranslationTools::convertFromBrackets ( INIFactory & ini,
const INIFactory & ref )
inlinestatic

Converts hash-based placeholders back to square bracket sequences using a reference.

Parameters
[in]iniThe INI factory to restore brackets in.
[in]refThe reference INI factory with original bracket values.

Definition at line 237 of file TranslationTools.h.

References INIFactory::extraOptions(), INIFactory::extraOptionsRef(), Dictionary< t_key, t_value, t_hash >::get(), StringView::hash(), String::indexOf(), IsValid(), String::replace(), and String::substr().

Referenced by makeTranslation().

◆ getDirs()

void TranslationTools::getDirs ( Buffer< File > & files,
const File & file )
inlinestatic

Recursively collects directories, excluding known non-source directories.

Parameters
[in]filesThe buffer to accumulate directories into.
[in]fileThe directory to scan.

Definition at line 203 of file TranslationTools.h.

References Buffer< t_type, t_memory_manager >::add(), file, and getDirs().

Referenced by getDirs(), and makeTranslation().

◆ getFiles()

void TranslationTools::getFiles ( Buffer< File > & files,
const File & file )
inline

Recursively collects source files with matching extensions.

Parameters
[in]filesThe buffer to accumulate files into.
[in]fileThe file or directory to scan.

Definition at line 182 of file TranslationTools.h.

References Buffer< t_type, t_memory_manager >::add(), File::e_file_extension, extensions, file, and getFiles().

Referenced by getFiles(), and makeTranslation().

◆ processString()

void TranslationTools::processString ( String & s,
Scanner & scan,
uint04 start_index,
const char * end_seq )
inline

Extracts a translation string from source code, handling multi-line strings.

Parameters
[in]sThe current line (modified in place to contain the extracted string).
[in]scanThe scanner for reading additional lines if needed.
[in]start_indexThe starting index within the string.
[in]end_seqThe end sequence to search for (e.g. "\")").

Definition at line 40 of file TranslationTools.h.

References String::beginsWith(), Scanner::currentLine(), String::indexOf(), IsInvalid(), IsValid(), Scanner::nextLine(), replaceStringVars(), String::substr(), String::trimWhiteSpace(), and utf8.

Referenced by setupFile().

◆ replaceStringVars()

void TranslationTools::replaceStringVars ( String & s)
inline

Replaces escape sequences in a string with their actual characters.

Parameters
[in]sThe string to process in-place.

Definition at line 26 of file TranslationTools.h.

References String::replace().

Referenced by processString(), and setupFile().

◆ setupFile()

void TranslationTools::setupFile ( INIFactory & translator,
File file )
inline

Scans a single source file for translation macros and adds entries to the translator.

Parameters
[in]translatorThe INI factory storing translations.
[in]fileThe source file to scan.

Definition at line 92 of file TranslationTools.h.

References addOption(), complex_tr, StringView::Convert(), Scanner::currentLine(), Translator::DefaultReadableLabel(), file, String::indexOf(), IsValid(), Scanner::nextLine(), processString(), qt_tr, replaceStringVars(), simple_tr, StringView::split(), and String::substr().

Referenced by makeTranslation().


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