Load translations from an empty context too.
This commit is contained in:
parent
64bf9220cb
commit
a4e14afdbb
|
@ -26,6 +26,7 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "equalizer.h"
|
#include "equalizer.h"
|
||||||
|
#include "potranslator.h"
|
||||||
|
|
||||||
#include <QtSingleApplication>
|
#include <QtSingleApplication>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
@ -57,7 +58,7 @@ void LoadTranslation(const QString& prefix, const QString& path) {
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTranslator* t = new QTranslator;
|
QTranslator* t = new PoTranslator;
|
||||||
if (t->load(prefix + "_" + QLocale::system().name(), path))
|
if (t->load(prefix + "_" + QLocale::system().name(), path))
|
||||||
QCoreApplication::installTranslator(t);
|
QCoreApplication::installTranslator(t);
|
||||||
else
|
else
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* This file is part of Clementine.
|
||||||
|
|
||||||
|
Clementine 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,
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef POTRANSLATOR_H
|
||||||
|
#define POTRANSLATOR_H
|
||||||
|
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
|
// We convert from .po files to .qm files, which loses context information.
|
||||||
|
// This translator tries loading strings with an empty context if it can't
|
||||||
|
// find any others.
|
||||||
|
|
||||||
|
class PoTranslator : public QTranslator {
|
||||||
|
public:
|
||||||
|
QString translate(const char* context, const char* source_text, const char* disambiguation = 0) const {
|
||||||
|
QString ret = QTranslator::translate(context, source_text, disambiguation);
|
||||||
|
if (!ret.isEmpty()) return ret;
|
||||||
|
return QTranslator::translate(NULL, source_text, disambiguation);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // POTRANSLATOR_H
|
|
@ -17,18 +17,19 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTranslator>
|
|
||||||
|
|
||||||
|
#include "potranslator.h"
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
|
|
||||||
TEST(Translations, Basic) {
|
TEST(Translations, Basic) {
|
||||||
ASSERT_TRUE(QFile::exists(":/translations"));
|
ASSERT_TRUE(QFile::exists(":/translations"));
|
||||||
ASSERT_TRUE(QFile::exists(":/translations/clementine_empty.qm"));
|
|
||||||
ASSERT_TRUE(QFile::exists(":/translations/clementine_es.qm"));
|
ASSERT_TRUE(QFile::exists(":/translations/clementine_es.qm"));
|
||||||
|
|
||||||
QTranslator t;
|
PoTranslator t;
|
||||||
t.load("clementine_es.qm", ":/translations");
|
t.load("clementine_es.qm", ":/translations");
|
||||||
|
|
||||||
EXPECT_EQ(QString::fromUtf8("Colección"),
|
EXPECT_EQ(QString::fromUtf8("Colección"),
|
||||||
t.translate("MainWindow", "Library"));
|
t.translate("MainWindow", "Library"));
|
||||||
|
EXPECT_EQ(QString::fromUtf8("Colección"),
|
||||||
|
t.translate("", "Library"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue