diff options
Diffstat (limited to 'src/corelib/kernel/qtranslator.cpp')
-rw-r--r-- | src/corelib/kernel/qtranslator.cpp | 76 |
1 files changed, 23 insertions, 53 deletions
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 1d0c613c17..ec92404a15 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qplatformdefs.h" @@ -58,7 +22,7 @@ #include "qendian.h" #include "qresource.h" -#if defined(Q_OS_UNIX) && !defined(Q_OS_NACL) && !defined(Q_OS_INTEGRITY) +#if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY) # define QT_USE_MMAP # include "private/qcore_unix_p.h" // for mmap @@ -75,8 +39,11 @@ QT_BEGIN_NAMESPACE +namespace { enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, Tag_Obsolete1, Tag_SourceText, Tag_Context, Tag_Comment, Tag_Obsolete2 }; +} + /* $ mcookie 3cb86418caef9c95cd211cbf60a1bddd @@ -485,8 +452,8 @@ bool QTranslator::load(const QString & filename, const QString & directory, QString prefix; if (QFileInfo(filename).isRelative()) { prefix = directory; - if (prefix.length() && !prefix.endsWith(QLatin1Char('/'))) - prefix += QLatin1Char('/'); + if (prefix.size() && !prefix.endsWith(u'/')) + prefix += u'/'; } const QString suffixOrDotQM = suffix.isNull() ? dotQmLiteral() : suffix; @@ -508,7 +475,7 @@ bool QTranslator::load(const QString & filename, const QString & directory, break; int rightmost = 0; - for (int i = 0; i < (int)delims.length(); i++) { + for (int i = 0; i < (int)delims.size(); i++) { int k = fname.lastIndexOf(delims[i]); if (k > rightmost) rightmost = k; @@ -530,7 +497,7 @@ bool QTranslatorPrivate::do_load(const QString &realname, const QString &directo QTranslatorPrivate *d = this; bool ok = false; - if (realname.startsWith(QLatin1Char(':'))) { + if (realname.startsWith(u':')) { // If the translation is in a non-compressed resource file, the data is already in // memory, so no need to use QFile to copy it again. Q_ASSERT(!d->resource); @@ -645,8 +612,8 @@ static QString find_translation(const QLocale & locale, QString path; if (QFileInfo(filename).isRelative()) { path = directory; - if (!path.isEmpty() && !path.endsWith(QLatin1Char('/'))) - path += QLatin1Char('/'); + if (!path.isEmpty() && !path.endsWith(u'/')) + path += u'/'; } const QString suffixOrDotQM = suffix.isNull() ? dotQmLiteral() : suffix; @@ -656,19 +623,22 @@ static QString find_translation(const QLocale & locale, // see http://www.unicode.org/reports/tr35/#LanguageMatching for inspiration - QStringList languages = locale.uiLanguages(); -#if defined(Q_OS_UNIX) + // 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(QLocale::TagSeparator::Underscore); 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 - - for (QString localeName : qAsConst(languages)) { - localeName.replace(QLatin1Char('-'), QLatin1Char('_')); + for (QString localeName : std::as_const(languages)) { // try the complete locale name first and progressively truncate from // the end until a matching language tag is found (with or without suffix) for (;;) { @@ -682,7 +652,7 @@ static QString find_translation(const QLocale & locale, realname.truncate(realNameBaseSize); - int rightmost = localeName.lastIndexOf(QLatin1Char('_')); + int rightmost = localeName.lastIndexOf(u'_'); if (rightmost <= 0) break; // no truncations anymore, break localeName.truncate(rightmost); @@ -945,7 +915,7 @@ end: if (!tn) return QString(); QString str(tn_length / 2, Qt::Uninitialized); - qFromBigEndian<ushort>(tn, str.length(), str.data()); + qFromBigEndian<char16_t>(tn, str.size(), str.data()); return str; } |