QTranslator: add categorized logging

Add categorized logging to QTranslator to trace what QTranslator tries
to load based on the requested locale and the files present in the
search path.

Pick-to: 6.8 6.5
Task-number: QTBUG-124898
Task-number: QTBUG-129434
Change-Id: I32425e72623356820fa9b928418f52fac23fafa9
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Volker Hilsheimer 2024-10-01 17:17:06 +02:00 committed by Edward Welbourne
parent fc0d9b2033
commit 6a785ce90c

View File

@ -15,10 +15,11 @@
#include "qdatastream.h" #include "qdatastream.h"
#include "qendian.h" #include "qendian.h"
#include "qfile.h" #include "qfile.h"
#include "qmap.h"
#include "qalgorithms.h" #include "qalgorithms.h"
#include "qtranslator_p.h" #include "qtranslator_p.h"
#include "qlocale.h" #include "qlocale.h"
#include "qlogging.h"
#include "qdebug.h"
#include "qendian.h" #include "qendian.h"
#include "qresource.h" #include "qresource.h"
@ -39,6 +40,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_STATIC_LOGGING_CATEGORY(lcTranslator, "qt.core.qtranslator")
namespace { namespace {
enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, Tag_Obsolete1, enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, Tag_Obsolete1,
Tag_SourceText, Tag_Context, Tag_Comment, Tag_Obsolete2 }; Tag_SourceText, Tag_Context, Tag_Comment, Tag_Obsolete2 };
@ -600,7 +603,10 @@ Q_NEVER_INLINE
static bool is_readable_file(const QString &name) static bool is_readable_file(const QString &name)
{ {
const QFileInfo fi(name); const QFileInfo fi(name);
return fi.isReadable() && fi.isFile(); const bool isReadableFile = fi.isReadable() && fi.isFile();
qCDebug(lcTranslator) << "Testing file" << name << isReadableFile;
return isReadableFile;
} }
static QString find_translation(const QLocale & locale, static QString find_translation(const QLocale & locale,
@ -609,6 +615,9 @@ static QString find_translation(const QLocale & locale,
const QString & directory, const QString & directory,
const QString & suffix) const QString & suffix)
{ {
qCDebug(lcTranslator).noquote().nospace() << "Searching translation for "
<< filename << prefix << locale << suffix
<< " in " << directory;
QString path; QString path;
if (QFileInfo(filename).isRelative()) { if (QFileInfo(filename).isRelative()) {
path = directory; path = directory;
@ -631,8 +640,9 @@ static QString find_translation(const QLocale & locale,
// that the Qt resource system is always case-sensitive, even on // that the Qt resource system is always case-sensitive, even on
// Windows (in other words: this codepath is *not* UNIX-only). // Windows (in other words: this codepath is *not* UNIX-only).
QStringList languages = locale.uiLanguages(QLocale::TagSeparator::Underscore); QStringList languages = locale.uiLanguages(QLocale::TagSeparator::Underscore);
for (int i = languages.size()-1; i >= 0; --i) { qCDebug(lcTranslator) << "Requested UI languages" << languages;
QString lang = languages.at(i); for (int i = languages.size() - 1; i >= 0; --i) {
const QString &lang = languages.at(i);
QString lowerLang = lang.toLower(); QString lowerLang = lang.toLower();
if (lang != lowerLang) if (lang != lowerLang)
languages.insert(i + 1, lowerLang); languages.insert(i + 1, lowerLang);