2017-09-07 10:44:15 +00:00
|
|
|
#ifndef TRANSLATIONMANAGER_H
|
|
|
|
#define TRANSLATIONMANAGER_H
|
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
#include <QLocale>
|
2017-09-07 10:44:15 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QStringList>
|
2017-09-09 04:24:04 +00:00
|
|
|
#include <QVector>
|
2017-09-07 10:44:15 +00:00
|
|
|
|
|
|
|
class QTranslator;
|
|
|
|
|
|
|
|
class TranslationManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool dummyBool READ dummyBool NOTIFY dummyBoolChanged)
|
2017-09-09 04:24:04 +00:00
|
|
|
Q_PROPERTY(int language READ language WRITE switchLanguage NOTIFY languageChanged)
|
|
|
|
Q_PROPERTY(QStringList naturalLabels READ naturalLabels CONSTANT)
|
2017-09-07 10:44:15 +00:00
|
|
|
|
|
|
|
protected:
|
2017-11-01 14:06:47 +00:00
|
|
|
explicit TranslationManager(QObject *parent = nullptr);
|
2017-09-07 10:44:15 +00:00
|
|
|
virtual ~TranslationManager();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static TranslationManager *instance();
|
|
|
|
|
|
|
|
bool dummyBool() const { return true; }
|
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
int language() const { return m_language; }
|
|
|
|
QString localeName() const { return m_locale.name(); }
|
2017-09-07 10:44:15 +00:00
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
QStringList naturalLabels() const;
|
2017-09-07 10:44:15 +00:00
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
int getLanguageByName(const QString &localeName) const;
|
2017-09-07 10:44:15 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void dummyBoolChanged();
|
2017-09-09 04:24:04 +00:00
|
|
|
void languageChanged(int language);
|
2017-09-07 10:44:15 +00:00
|
|
|
|
|
|
|
public slots:
|
2017-09-09 04:24:04 +00:00
|
|
|
bool switchLanguage(int language = 0);
|
|
|
|
bool switchLanguageByName(const QString &localeName);
|
2017-09-07 10:44:15 +00:00
|
|
|
|
|
|
|
void refreshTranslations();
|
|
|
|
|
|
|
|
private:
|
2017-09-09 04:24:04 +00:00
|
|
|
void setupTranslation();
|
|
|
|
|
|
|
|
void uninstallAllTranslators();
|
|
|
|
void uninstallTranslator(int language);
|
|
|
|
|
|
|
|
void installTranslator(int language, const QLocale &locale);
|
2017-09-07 10:44:15 +00:00
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
QTranslator *loadTranslator(int language, const QLocale &locale);
|
2017-09-07 10:44:15 +00:00
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
static QString i18nDir();
|
2017-09-07 10:44:15 +00:00
|
|
|
|
|
|
|
private:
|
2017-09-09 04:24:04 +00:00
|
|
|
int m_language;
|
2017-09-07 10:44:15 +00:00
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
QLocale m_locale;
|
2017-09-07 10:44:15 +00:00
|
|
|
|
2017-09-09 04:24:04 +00:00
|
|
|
QList<QLocale> m_locales;
|
|
|
|
QVector<QTranslator *> m_translators;
|
2017-09-07 10:44:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TRANSLATIONMANAGER_H
|