24 #include <QApplication>
25 #include <QCoreApplication>
29 #include <QMessageBox>
30 #include <QTranslator>
37 Q_UNUSED(QT_TRANSLATE_NOOP(
"QPlatformTheme",
"OK"))
38 Q_UNUSED(QT_TRANSLATE_NOOP(
"QPlatformTheme",
"Cancel"))
39 Q_UNUSED(QT_TRANSLATE_NOOP(
"QPlatformTheme",
"Close"))
40 Q_UNUSED(QT_TRANSLATE_NOOP(
"QPlatformTheme",
"Save"))
45 mCurrentLanguage(
"en")
71 if (code.indexOf(
"en") == 0) {
86 error = QObject::tr(
"Unknown language specified!");
94 const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
98 QString translationFile;
99 if (QFile::exists(datadir +
"/lang/" +
mTranslations[index].mFilename +
".qm"))
100 translationFile = datadir +
"/lang/" +
mTranslations[index].mFilename +
".qm";
102 else if (QFile::exists(datadir +
"/" +
mTranslations[index].mFilename +
".qm"))
103 translationFile = datadir +
"/" +
mTranslations[index].mFilename +
".qm";
106 translationFile = appPath +
"/" +
mTranslations[index].mFilename +
".qm";
111 if (!QFile::exists(translationFile)) {
112 error = QObject::tr(
"Language file %1 not found!");
117 error = QObject::tr(
"Failed to load translation for language %1 from file %2");
125 const QString msg(tr(
"Failed to change the user interface language:"
127 "The user interface language has been reset to English. Open "
128 "the Preferences-dialog to select any of the available "
129 "languages.").arg(
error));
130 QMessageBox msgBox(QMessageBox::Warning,
153 QString language = QLocale::system().name();
172 const int codeLength = QString(filename).length() - QString(filename).indexOf(
'_') - 1;
173 info.
mCode = QString(filename).right(codeLength);
TranslationHandler(QObject *parent=nullptr)
int getLanguageIndexByCode(const QString &code) const
Find language in the list and return its index.
const QString & getCurrentLanguage() const
Get currently selected translation.
QTranslator * mTranslator
Translator class instance.
bool setLanguage(const QString &code)
Set active translation.
void addTranslation(const char *name, const char *filename)
Add new translation to list of available translations.
QList< TranslationInfo > mTranslations
List of available translations.
QString suggestLanguage() const
Get translation suggestion for the system.
QString mCurrentLanguage
ISO 639 language code of the currently selected translation.
@ error
Programming error.
QString getDataDir()
Get configured data dir.
Information for one translation.
QString mName
Readable name for the translation (e.g.
QString mCode
ISO 639 language code for the translation (e.g.
QString mFilename
Filename for the translation.
static UNUSED void unused()