-
Notifications
You must be signed in to change notification settings - Fork 2
/
i18n.h
59 lines (46 loc) · 1.93 KB
/
i18n.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef I18N_H
#define I18N_H
#include <QObject>
#include <QJsonObject>
#include <QVariantMap>
#define DEFAULT_LOCALE "en"
class I18n : public QObject
{
Q_OBJECT
Q_PROPERTY(QString systemLocale READ getSystemLocale CONSTANT)
Q_PROPERTY(QString currentLocale MEMBER currentLocale NOTIFY currentLocaleChanged)
Q_PROPERTY(QUrl consoleFont READ getConsoleFont NOTIFY currentLocaleChanged)
Q_PROPERTY(QVariantMap consoleFontMetrics READ getConsoleFontMetrics NOTIFY currentLocaleChanged)
Q_PROPERTY(QUrl titleFont READ getTitleFont NOTIFY currentLocaleChanged)
Q_PROPERTY(QVariantMap titleFontMetrics READ getTitleFontMetrics NOTIFY currentLocaleChanged)
static I18n* instance;
public:
explicit I18n(QObject *parent = nullptr);
static I18n* get() { return instance; }
Q_INVOKABLE QStringList getAvailableLocales() const { return locales; }
Q_INVOKABLE QString t(const QString& key) const;
Q_INVOKABLE QString t(const QString& key, const QVariantMap& variables) const;
const QString& getCurrentLocale() const { return currentLocale; }
QString getSystemLocale() const;
QUrl getConsoleFont() const;
QVariantMap getConsoleFontMetrics() const;
QUrl getTitleFont() const;
QVariantMap getTitleFontMetrics() const;
static QString getSourceForLocale(const QString& locale);
static QString getSourceForLocale(const QString& translationFile, const QString& locale);
signals:
void currentLocaleChanged();
void translationsChanged();
public slots:
void loadCurrentLocale();
private:
QJsonValue getTranslation(const QString& key) const;
QJsonObject getTranslationGroupForKey(const QString& key) const;
QJsonObject getTranslationGroup(const QStringList& path) const;
QUrl getFontPath(const QString& style, const QString& defaultPath) const;
QVariantMap getFontMetrics(const QString& style, QVariantMap defaultMetrics) const;
QString currentLocale;
QStringList locales;
QJsonObject data;
};
#endif // I18N_H