Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
translation_manager.h
Go to the documentation of this file.
1#ifndef TRANSLATION_MANAGER_H
2#define TRANSLATION_MANAGER_H
3
4#include <QJsonObject>
5#include <QMutex>
6#include <QObject>
7
15class TranslationManager final : public QObject {
16 Q_OBJECT
17
18public:
24 bool Initialize(const QString &language_code);
25
31
42 QString Translate(const QString &key, const QString &default_value = QString()) const;
43
48 QString GetCurrentLanguage() const;
49
50private:
55 explicit TranslationManager(QObject *parent = nullptr) : QObject(parent) {
56 }
57
60
63
69 bool LoadTranslations(const QString &language_code);
70
74 static QMutex mutex_;
76 QJsonObject translations_;
80 bool initialized_ = false;
81};
82
83#endif // TRANSLATION_MANAGER_H
TranslationManager & operator=(const TranslationManager &)=delete
Removed assignment constructor.
static TranslationManager * GetInstance()
Returns an instance of the TranslationManager singleton.
Definition translation_manager.cpp:26
static QMutex mutex_
Mutex to protect instance creation in a multithreaded environment.
Definition translation_manager.h:74
bool Initialize(const QString &language_code)
Initializes the translation manager by loading the appropriate language file.
Definition translation_manager.cpp:6
bool initialized_
A flag indicating whether the manager has been initialized.
Definition translation_manager.h:80
QString GetCurrentLanguage() const
Returns the currently loaded language code.
Definition translation_manager.cpp:69
bool LoadTranslations(const QString &language_code)
Loads translations from a JSON file for the specified language code.
Definition translation_manager.cpp:73
QString Translate(const QString &key, const QString &default_value=QString()) const
Retrieves the translated string for the specified key.
Definition translation_manager.cpp:34
QString current_language_code_
Currently loaded language code.
Definition translation_manager.h:78
static TranslationManager * instance_
Static singleton instance.
Definition translation_manager.h:72
TranslationManager(const TranslationManager &)=delete
Removed copy constructor.
TranslationManager(QObject *parent=nullptr)
Private constructor to enforce the singleton pattern.
Definition translation_manager.h:55
QJsonObject translations_
It stores the loaded translations as a JSON object.
Definition translation_manager.h:76