summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtranslator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qtranslator.cpp')
-rw-r--r--src/corelib/kernel/qtranslator.cpp56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index d7d670b5bc..bdcd016630 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -601,9 +601,14 @@ bool QTranslatorPrivate::do_load(const QString &realname, const QString &directo
}
}
- if (ok && d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength, directory)) {
- d->filePath = realname;
- return true;
+ if (ok) {
+ const QString base_dir =
+ !directory.isEmpty() ? directory : QFileInfo(realname).absolutePath();
+ if (d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength,
+ base_dir)) {
+ d->filePath = realname;
+ return true;
+ }
}
#if defined(QT_USE_MMAP)
@@ -647,46 +652,30 @@ static QString find_translation(const QLocale & locale,
QString realname;
realname += path + filename + prefix; // using += in the hope for some reserve capacity
const int realNameBaseSize = realname.size();
- QStringList fuzzyLocales;
// see http://www.unicode.org/reports/tr35/#LanguageMatching for inspiration
+ // For each language_country returned by locale.uiLanguages(), add
+ // also a lowercase version to the list. Since these languages are
+ // used to create file names, this is important on case-sensitive
+ // file systems, where otherwise a file called something like
+ // "prefix_en_us.qm" won't be found under the "en_US" locale. Note
+ // that the Qt resource system is always case-sensitive, even on
+ // Windows (in other words: this codepath is *not* UNIX-only).
QStringList languages = locale.uiLanguages();
-#if defined(Q_OS_UNIX)
for (int i = languages.size()-1; i >= 0; --i) {
QString lang = languages.at(i);
QString lowerLang = lang.toLower();
if (lang != lowerLang)
languages.insert(i+1, lowerLang);
}
-#endif
- // try explicit locales names first
for (QString localeName : qAsConst(languages)) {
localeName.replace(QLatin1Char('-'), QLatin1Char('_'));
- realname += localeName + suffixOrDotQM;
- if (is_readable_file(realname))
- return realname;
-
- realname.truncate(realNameBaseSize + localeName.size());
- if (is_readable_file(realname))
- return realname;
-
- realname.truncate(realNameBaseSize);
- fuzzyLocales.append(localeName);
- }
-
- // start guessing
- for (const QString &fuzzyLocale : qAsConst(fuzzyLocales)) {
- QStringRef localeName(&fuzzyLocale);
+ // try the complete locale name first and progressively truncate from
+ // the end until a matching language tag is found (with or without suffix)
for (;;) {
- int rightmost = localeName.lastIndexOf(QLatin1Char('_'));
- // no truncations? fail
- if (rightmost <= 0)
- break;
- localeName.truncate(rightmost);
-
realname += localeName + suffixOrDotQM;
if (is_readable_file(realname))
return realname;
@@ -696,6 +685,11 @@ static QString find_translation(const QLocale & locale,
return realname;
realname.truncate(realNameBaseSize);
+
+ int rightmost = localeName.lastIndexOf(QLatin1Char('_'));
+ if (rightmost <= 0)
+ break; // no truncations anymore, break
+ localeName.truncate(rightmost);
}
}
@@ -754,10 +748,10 @@ static QString find_translation(const QLocale & locale,
\li \c /opt/foolib/foo.es
\li \c /opt/foolib/foo.fr_CA.qm
\li \c /opt/foolib/foo.fr_CA
- \li \c /opt/foolib/foo.de.qm
- \li \c /opt/foolib/foo.de
\li \c /opt/foolib/foo.fr.qm
\li \c /opt/foolib/foo.fr
+ \li \c /opt/foolib/foo.de.qm
+ \li \c /opt/foolib/foo.de
\li \c /opt/foolib/foo.qm
\li \c /opt/foolib/foo.
\li \c /opt/foolib/foo
@@ -1120,7 +1114,7 @@ void QTranslatorPrivate::clear()
If \a n is not -1, it is used to choose an appropriate form for
the translation (e.g. "%n file found" vs. "%n files found").
- If you need to programatically insert translations into a
+ If you need to programmatically insert translations into a
QTranslator, this function can be reimplemented.
\sa load()