Revert: use the new form of QTranslator::load() for more flexibility

This reverts commit 427646b8d7.
It seems that it should have been more correct, but we are still not
shipping English translations, and static QString find_translation()
in qtranslator.cpp will return any language which is in
QLocale::uiLanguages() for which the translation file is found.
That is a long list on OSX.

Reverting the patch means find_translation() is not called in
such cases.  This change can be re-done whenever we are more sure
that the attempt to find a translation will succeed in finding a
sensible one, or fall back to not translating, rather than choosing
a language that the user didn't intend.

Task-number: QTBUG-41977
Change-Id: I425946cc71cec96b4f38629eb2b7e80220c5236d
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
This commit is contained in:
Shawn Rutledge 2014-10-16 10:10:04 +02:00
parent 94297b4ca5
commit 05d8ffb4df
4 changed files with 14 additions and 17 deletions

View File

@ -40,9 +40,8 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLocale locale;
QTranslator qtTranslator;
qtTranslator.load(locale, QLatin1String("qml"), QLatin1String("_"), QLatin1String(":/i18n"));
qtTranslator.load("qml_" + QLocale::system().name(), ":/i18n/");
app.installTranslator(&qtTranslator);
QQmlApplicationEngine engine;

View File

@ -65,8 +65,7 @@ void QQmlApplicationEnginePrivate::init()
q->connect(q, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
#ifndef QT_NO_TRANSLATION
QTranslator* qtTranslator = new QTranslator;
QLocale locale;
if (qtTranslator->load(locale, QLatin1String("qt"), QLatin1String("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
if (qtTranslator->load(QLatin1String("qt_") + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
QCoreApplication::installTranslator(qtTranslator);
translators << qtTranslator;
#endif
@ -83,8 +82,7 @@ void QQmlApplicationEnginePrivate::loadTranslations(const QUrl &rootFile)
QFileInfo fi(rootFile.toLocalFile());
QTranslator *translator = new QTranslator;
QLocale locale;
if (translator->load(locale, QLatin1String("qml"), QLatin1String("_"), fi.path() + QLatin1String("/i18n"))) {
if (translator->load(QLatin1String("qml_") + QLocale::system().name(), fi.path() + QLatin1String("/i18n"))) {
QCoreApplication::installTranslator(translator);
translators << translator;
} else {

View File

@ -450,8 +450,10 @@ int main(int argc, char *argv[])
verboseMode = false;
#ifndef QT_NO_TRANSLATION
// qt_ translations are loaded by QQmlApplicationEngine
if (!translationFile.isEmpty()) { // Note: installed before QQmlApplicationEngine's automatic translation loading
//qt_ translations loaded by QQmlApplicationEngine
QString sysLocale = QLocale::system().name();
if (!translationFile.isEmpty()) { //Note: installed before QQmlApplicationEngine's automatic translation loading
QTranslator translator;
if (translator.load(translationFile)) {

View File

@ -307,8 +307,7 @@ static void displayFileDialog(Options *options)
#ifndef QT_NO_TRANSLATION
static void loadTranslationFile(QTranslator &translator, const QString& directory)
{
QLocale locale;
translator.load(locale, QLatin1String("qml"), QLatin1String("_"), directory + QLatin1String("/i18n"));
translator.load(QLatin1String("qml_" )+QLocale::system().name(), directory + QLatin1String("/i18n"));
QCoreApplication::installTranslator(&translator);
}
#endif
@ -416,18 +415,17 @@ int main(int argc, char ** argv)
app.setOrganizationDomain("qt-project.org");
#ifndef QT_NO_TRANSLATION
QLocale locale;
QTranslator qtTranslator;
if (qtTranslator.load(locale, QLatin1String("qt"), QLatin1String("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
app.installTranslator(&qtTranslator);
QTranslator translator;
if (translator.load(locale, QLatin1String("qmlscene"), QLatin1String("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
QTranslator qtTranslator;
QString sysLocale = QLocale::system().name();
if (qtTranslator.load(QLatin1String("qt_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
app.installTranslator(&qtTranslator);
if (translator.load(QLatin1String("qmlscene_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
app.installTranslator(&translator);
QTranslator qmlTranslator;
if (!options.translationFile.isEmpty()) {
if (qmlTranslator.load(locale, options.translationFile)) {
if (qmlTranslator.load(options.translationFile)) {
app.installTranslator(&qmlTranslator);
} else {
qWarning() << "Could not load the translation file" << options.translationFile;