Debian Codegraph @

src/translator.h

raw symbols SCIP
1 // Copyright (C) 2014 Sacha Refshauge
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 3.0.
6
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 3.0 for more details.
11
12 // A copy of the GPL 3.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14
15 // Official GIT repository and contact information can be found at
16 // http://github.com/xsacha/Sachesi
17
18 #pragma once
19
20 #include <QApplication>
21 #include <QTranslator>
22
23 class Translator : public QObject {
24 Q_OBJECT
25
26 Q_PROPERTY(bool exists MEMBER _exists NOTIFY existsChanged)
27 Q_PROPERTY(QString lang MEMBER _lang NOTIFY langChanged)
28 public:
29 Translator()
30 : QObject()
31 , _exists(false)
32 {
33 // Install translator by locale language string
34 // zh_HK is considered 'Chinese' language but the characters are entirely different.
35 if ((QLocale().name() != "zh_HK") && _appTranslator.load(QString(":/translations/%1.qm")
36 .arg(QLocale::languageToString(QLocale().language())))
37 ) {
38 _exists = true;
39 }
40 emit existsChanged();
41 }
42 Q_INVOKABLE void load() {
43 if (_exists) {
44 qApp->installTranslator(&_appTranslator);
45 emit langChanged();
46 }
47 }
48 Q_INVOKABLE void remove() {
49 qApp->removeTranslator(&_appTranslator);
50 emit langChanged();
51 }
52
53 signals:
54 void existsChanged();
55 void langChanged();
56
57 private:
58 bool _exists;
59 QString _lang;
60 QTranslator _appTranslator;
61 };