Manages the loading and delivery of translations for applications.
More...
#include <translation_manager.h>
|
| 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.
|
| |
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.
◆ TranslationManager() [1/2]
| TranslationManager::TranslationManager |
( |
QObject * | parent = nullptr | ) |
|
|
inlineexplicitprivate |
Private constructor to enforce the singleton pattern.
- Parameters
-
| parent | Optional QObject parent. |
◆ TranslationManager() [2/2]
Removed copy constructor.
◆ GetCurrentLanguage()
| QString TranslationManager::GetCurrentLanguage |
( |
| ) |
const |
Returns the currently loaded language code.
- Returns
- Language code (e.g. "en", "pl").
◆ GetInstance()
◆ Initialize()
| bool TranslationManager::Initialize |
( |
const QString & | language_code | ) |
|
Initializes the translation manager by loading the appropriate language file.
- Parameters
-
| language_code | Language code (e.g., "en", "pl"). |
- Returns
- True if the initialization and loading of translations was successful, false otherwise.
◆ LoadTranslations()
| bool TranslationManager::LoadTranslations |
( |
const QString & | language_code | ) |
|
|
private |
Loads translations from a JSON file for the specified language code.
- Parameters
-
| language_code | Language code to be loaded. |
- Returns
- True if loading is successful, false otherwise.
◆ operator=()
Removed assignment constructor.
◆ 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
-
| key | Translation key. |
| default_value | The value returned if the key is not found. |
- Returns
- Translated string or default_value.
◆ 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_
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: