Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
TranslationManager Class Referencefinal

Manages the loading and delivery of translations for applications. More...

#include <translation_manager.h>

Inheritance diagram for TranslationManager:
Collaboration diagram for TranslationManager:

Public Member Functions

QString GetCurrentLanguage () const
 Returns the currently loaded language code.
 
bool Initialize (const QString &language_code)
 Initializes the translation manager by loading the appropriate language file.
 
QString Translate (const QString &key, const QString &default_value=QString()) const
 Retrieves the translated string for the specified key.
 

Static Public Member Functions

static TranslationManagerGetInstance ()
 Returns an instance of the TranslationManager singleton.
 

Private Member Functions

bool LoadTranslations (const QString &language_code)
 Loads translations from a JSON file for the specified language code.
 
TranslationManageroperator= (const TranslationManager &)=delete
 Removed assignment constructor.
 
 TranslationManager (const TranslationManager &)=delete
 Removed copy constructor.
 
 TranslationManager (QObject *parent=nullptr)
 Private constructor to enforce the singleton pattern.
 

Private Attributes

QString current_language_code_
 Currently loaded language code.
 
bool initialized_ = false
 A flag indicating whether the manager has been initialized.
 
QJsonObject translations_
 It stores the loaded translations as a JSON object.
 

Static Private Attributes

static TranslationManagerinstance_ = nullptr
 Static singleton instance.
 
static QMutex mutex_
 Mutex to protect instance creation in a multithreaded environment.
 

Detailed Description

Manages the loading and delivery of translations for applications.

The class implements the singleton pattern and is responsible for loading the corresponding JSON file with translations based on the selected language and providing a method to retrieve the translated strings.

Constructor & Destructor Documentation

◆ TranslationManager() [1/2]

TranslationManager::TranslationManager ( QObject * parent = nullptr)
inlineexplicitprivate

Private constructor to enforce the singleton pattern.

Parameters
parentOptional QObject parent.
Here is the caller graph for this function:

◆ TranslationManager() [2/2]

TranslationManager::TranslationManager ( const TranslationManager & )
privatedelete

Removed copy constructor.

Here is the call graph for this function:

Member Function Documentation

◆ GetCurrentLanguage()

QString TranslationManager::GetCurrentLanguage ( ) const

Returns the currently loaded language code.

Returns
Language code (e.g. "en", "pl").

◆ GetInstance()

TranslationManager * TranslationManager::GetInstance ( )
static

Returns an instance of the TranslationManager singleton.

Returns
A pointer to an instance of TranslationManager.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Initialize()

bool TranslationManager::Initialize ( const QString & language_code)

Initializes the translation manager by loading the appropriate language file.

Parameters
language_codeLanguage code (e.g., "en", "pl").
Returns
True if the initialization and loading of translations was successful, false otherwise.
Here is the call graph for this function:

◆ LoadTranslations()

bool TranslationManager::LoadTranslations ( const QString & language_code)
private

Loads translations from a JSON file for the specified language code.

Parameters
language_codeLanguage code to be loaded.
Returns
True if loading is successful, false otherwise.
Here is the caller graph for this function:

◆ operator=()

TranslationManager & TranslationManager::operator= ( const TranslationManager & )
privatedelete

Removed assignment constructor.

Here is the call graph for this function:

◆ Translate()

QString TranslationManager::Translate ( const QString & key,
const QString & default_value = QString() ) const

Retrieves the translated string for the specified key.

The key should have the format “Class.Widget.Property” or similar, corresponding to the structure in the JSON file.

Parameters
keyTranslation key.
default_valueThe value returned if the key is not found.
Returns
Translated string or default_value.
Here is the caller graph for this function:

Member Data Documentation

◆ current_language_code_

QString TranslationManager::current_language_code_
private

Currently loaded language code.

◆ initialized_

bool TranslationManager::initialized_ = false
private

A flag indicating whether the manager has been initialized.

◆ instance_

TranslationManager * TranslationManager::instance_ = nullptr
staticprivate

Static singleton instance.

◆ mutex_

QMutex TranslationManager::mutex_
staticprivate

Mutex to protect instance creation in a multithreaded environment.

◆ translations_

QJsonObject TranslationManager::translations_
private

It stores the loaded translations as a JSON object.


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