Add translations support (#82)

* Add translations support
* Update .gitignore
This commit is contained in:
Jonas Kvinge
2019-02-22 20:24:38 +01:00
committed by GitHub
parent 034b032cfa
commit 954e0e8a59
29 changed files with 401 additions and 103 deletions

View File

@@ -1,18 +1,18 @@
/* This file is part of Clementine.
/* This file is part of Strawberry.
Copyright 2015, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
Strawberry is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
Strawberry is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"

View File

@@ -1,22 +1,22 @@
/* This file is part of Clementine.
/* This file is part of Strawberry.
Copyright 2015, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
Strawberry is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
Strawberry is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_THREAD_H_
#define CORE_THREAD_H_
#ifndef THREAD_H
#define THREAD_H
#include "config.h"
@@ -40,4 +40,4 @@ class Thread : public QThread {
Utilities::IoPriority io_priority_;
};
#endif // CORE_THREAD_H_
#endif // THREAD_H

View File

@@ -58,6 +58,9 @@
#include <QSettings>
#include <QtEvents>
#include <QtDebug>
#ifdef HAVE_TRANSLATIONS
# include <QTranslator>
#endif
#ifdef Q_OS_LINUX
# include <unistd.h>
@@ -96,6 +99,10 @@
# include "scoped_cftyperef.h"
#endif
#ifdef HAVE_TRANSLATIONS
# include "potranslator.h"
#endif
namespace Utilities {
static QString tr(const char *str) {
@@ -764,6 +771,29 @@ QString DesktopEnvironment() {
}
#ifdef HAVE_TRANSLATIONS
QString SystemLanguageName() {
QString system_language = QLocale::system().uiLanguages().empty() ? QLocale::system().name() : QLocale::system().uiLanguages().first();
// uiLanguages returns strings with "-" as separators for language/region; however QTranslator needs "_" separators
system_language.replace("-", "_");
return system_language;
}
void LoadTranslation(const QString &prefix, const QString &path, const QString &language) {
QTranslator *t = new PoTranslator;
if (t->load(prefix + "_" + language, path))
QCoreApplication::installTranslator(t);
else
delete t;
}
#endif
} // namespace Utilities
ScopedWCharArray::ScopedWCharArray(const QString &str)

View File

@@ -154,6 +154,11 @@ QString GetRandomString(const int len, const QString &UseCharacters);
QString DesktopEnvironment();
#ifdef HAVE_TRANSLATIONS
QString SystemLanguageName();
void LoadTranslation(const QString &prefix, const QString &path, const QString &language);
#endif
} // namespace
class ScopedWCharArray {