diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMAddQch) +include(ECMQtDeclareLoggingCategory) ecm_setup_version( @@ -120,4 +121,6 @@ cmake/ts-pmap-compile.py DESTINATION ${CMAKECONFIG_INSTALL_DIR} COMPONENT Devel ) +install(FILES ki18n.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) + feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/ki18n.categories b/ki18n.categories new file mode 100644 --- /dev/null +++ b/ki18n.categories @@ -0,0 +1,2 @@ +kf5.ki18n KI18n DEFAULT_SEVERITY [WARNING] IDENTIFIER [KI18N] +kf5.ki18n.kuit KI18n KUIT DEFAULT_SEVERITY [WARNING] IDENTIFIER [KI18N_KUIT] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,18 @@ main.cpp ) +ecm_qt_declare_logging_category(libki18n_SRCS + HEADER ki18n_logging.h + IDENTIFIER KI18N + CATEGORY_NAME kf5.ki18n +) + +ecm_qt_declare_logging_category(libki18n_SRCS + HEADER ki18n_logging_kuit.h + IDENTIFIER KI18N_KUIT + CATEGORY_NAME kf5.ki18n.kuit +) + add_library(KF5I18n ${libki18n_SRCS}) generate_export_header(KF5I18n BASE_NAME KI18n) add_library(KF5::I18n ALIAS KF5I18n) diff --git a/src/kcatalog.cpp b/src/kcatalog.cpp --- a/src/kcatalog.cpp +++ b/src/kcatalog.cpp @@ -36,6 +36,8 @@ #include +#include "ki18n_logging.h" + // not defined on win32 :( #ifdef _WIN32 #ifndef LC_MESSAGES @@ -200,7 +202,7 @@ if (language != currentLanguage || !bindDone) { Q_ASSERT_X(QCoreApplication::instance(), "KCatalogPrivate::setupGettextEnv", "You need to instantiate a Q*Application before using KCatalog"); if (!QCoreApplication::instance()) { - qWarning() << "KCatalog being used without a Q*Application instance. Some translations won't work"; + qCWarning(KI18N) << "KCatalog being used without a Q*Application instance. Some translations won't work"; } currentLanguage = language; diff --git a/src/klocalizedcontext.cpp b/src/klocalizedcontext.cpp --- a/src/klocalizedcontext.cpp +++ b/src/klocalizedcontext.cpp @@ -22,10 +22,10 @@ #include "klocalizedcontext.h" -#include - #include +#include "ki18n_logging.h" + class KLocalizedContextPrivate { public: @@ -78,7 +78,7 @@ trMessage = trMessage.subs(value.toString()); } else { trMessage = trMessage.subs(QStringLiteral("???")); - qWarning() << "couldn't convert" << value << "to translate"; + qCWarning(KI18N) << "couldn't convert" << value << "to translate"; } } @@ -130,7 +130,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (message.isEmpty()) { - qWarning() << "i18n() needs at least one parameter"; + qCWarning(KI18N) << "i18n() needs at least one parameter"; return QString(); } @@ -152,7 +152,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (context.isEmpty() || message.isEmpty()) { - qWarning() << "i18nc() needs at least two arguments"; + qCWarning(KI18N) << "i18nc() needs at least two arguments"; return QString(); } @@ -174,7 +174,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (singular.isEmpty() || plural.isEmpty()) { - qWarning() << "i18np() needs at least two arguments"; + qCWarning(KI18N) << "i18np() needs at least two arguments"; return QString(); } @@ -197,7 +197,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (context.isEmpty() || singular.isEmpty() || plural.isEmpty()) { - qWarning() << "i18ncp() needs at least three arguments"; + qCWarning(KI18N) << "i18ncp() needs at least three arguments"; return QString(); } @@ -220,7 +220,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || message.isEmpty()) { - qWarning() << "i18nd() needs at least two parameters"; + qCWarning(KI18N) << "i18nd() needs at least two parameters"; return QString(); } @@ -236,7 +236,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || context.isEmpty() || message.isEmpty()) { - qWarning() << "i18ndc() needs at least three arguments"; + qCWarning(KI18N) << "i18ndc() needs at least three arguments"; return QString(); } @@ -252,7 +252,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || singular.isEmpty() || plural.isEmpty()) { - qWarning() << "i18ndp() needs at least three arguments"; + qCWarning(KI18N) << "i18ndp() needs at least three arguments"; return QString(); } @@ -269,7 +269,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || context.isEmpty() || singular.isEmpty() || plural.isEmpty()) { - qWarning() << "i18ndcp() needs at least four arguments"; + qCWarning(KI18N) << "i18ndcp() needs at least four arguments"; return QString(); } @@ -288,7 +288,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (message.isEmpty()) { - qWarning() << "xi18n() needs at least one parameter"; + qCWarning(KI18N) << "xi18n() needs at least one parameter"; return QString(); } @@ -310,7 +310,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (context.isEmpty() || message.isEmpty()) { - qWarning() << "xi18nc() needs at least two arguments"; + qCWarning(KI18N) << "xi18nc() needs at least two arguments"; return QString(); } @@ -332,7 +332,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (singular.isEmpty() || plural.isEmpty()) { - qWarning() << "xi18np() needs at least two arguments"; + qCWarning(KI18N) << "xi18np() needs at least two arguments"; return QString(); } @@ -355,7 +355,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (context.isEmpty() || singular.isEmpty() || plural.isEmpty()) { - qWarning() << "xi18ncp() needs at least three arguments"; + qCWarning(KI18N) << "xi18ncp() needs at least three arguments"; return QString(); } @@ -378,7 +378,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || message.isEmpty()) { - qWarning() << "xi18nd() needs at least two parameters"; + qCWarning(KI18N) << "xi18nd() needs at least two parameters"; return QString(); } @@ -394,7 +394,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || context.isEmpty() || message.isEmpty()) { - qWarning() << "x18ndc() needs at least three arguments"; + qCWarning(KI18N) << "x18ndc() needs at least three arguments"; return QString(); } @@ -410,7 +410,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || singular.isEmpty() || plural.isEmpty()) { - qWarning() << "xi18ndp() needs at least three arguments"; + qCWarning(KI18N) << "xi18ndp() needs at least three arguments"; return QString(); } @@ -427,7 +427,7 @@ const QVariant ¶m6, const QVariant ¶m7, const QVariant ¶m8, const QVariant ¶m9, const QVariant ¶m10) const { if (domain.isEmpty() || context.isEmpty() || singular.isEmpty() || plural.isEmpty()) { - qWarning() << "xi18ndcp() needs at least four arguments"; + qCWarning(KI18N) << "xi18ndcp() needs at least four arguments"; return QString(); } diff --git a/src/klocalizedstring.cpp b/src/klocalizedstring.cpp --- a/src/klocalizedstring.cpp +++ b/src/klocalizedstring.cpp @@ -22,7 +22,6 @@ #include -#include #include #include #include @@ -45,6 +44,8 @@ #include #include +#include "ki18n_logging.h" + // Truncate string, for output of long messages. static QString shortenMessage(const QString &str) { @@ -431,21 +432,21 @@ // Empty msgid would result in returning the catalog header, // which is never intended, so warn and return empty translation. if (msgid.isNull() || msgid.isEmpty()) { - qWarning() << "KLocalizedString: " - "Trying to look up translation of \"\", fix the code."; + qCWarning(KI18N) << "KLocalizedString: " + "Trying to look up translation of \"\", fix the code."; language.clear(); msgstr.clear(); return; } // Gettext semantics allows empty context, but it is pointless, so warn. if (!msgctxt.isNull() && msgctxt.isEmpty()) { - qWarning() << "KLocalizedString: " - "Using \"\" as context, fix the code."; + qCWarning(KI18N) << "KLocalizedString: " + "Using \"\" as context, fix the code."; } // Gettext semantics allows empty plural, but it is pointless, so warn. if (!msgid_plural.isNull() && msgid_plural.isEmpty()) { - qWarning() << "KLocalizedString: " - "Using \"\" as plural text, fix the code."; + qCWarning(KI18N) << "KLocalizedString: " + "Using \"\" as plural text, fix the code."; } // Set translation to text in code language, in case no translation found. @@ -515,7 +516,7 @@ // Assure the message has been supplied. if (text.isEmpty()) { - qWarning() << "Trying to convert empty KLocalizedString to QString."; + qCWarning(KI18N) << "Trying to convert empty KLocalizedString to QString."; #ifndef NDEBUG return QStringLiteral("(I18N_EMPTY_MESSAGE)"); #else @@ -525,9 +526,9 @@ // Check whether plural argument has been supplied, if message has plural. if (!plural.isEmpty() && !numberSet) { - qWarning() << QStringLiteral( - "Plural argument to message {%1} not supplied before conversion.") - .arg(shortenMessage(QString::fromUtf8(text))); + qCWarning(KI18N) << QStringLiteral( + "Plural argument to message {%1} not supplied before conversion.") + .arg(shortenMessage(QString::fromUtf8(text))); } // Resolve inputs. @@ -576,9 +577,9 @@ } else { // fencePos == 0 // The msgstr starts with the script fence, no ordinary translation. // This is not allowed, consider message not translated. - qWarning() << QStringLiteral( - "Scripted message {%1} without ordinary translation, discarded.") - .arg(shortenMessage(translation)); + qCWarning(KI18N) << QStringLiteral( + "Scripted message {%1} without ordinary translation, discarded.") + .arg(shortenMessage(translation)); translation = plural.isEmpty() || number == 1 ? QString::fromUtf8(text) : QString::fromUtf8(plural); @@ -761,19 +762,19 @@ for (int i = 0; i < ords.size(); i++) { if (!ords.at(i)) { gaps = true; - qWarning() << QStringLiteral( - "Placeholder %%1 skipped in message {%2}.") - .arg(QString::number(i + 1), shortenMessage(translation)); + qCWarning(KI18N) << QStringLiteral( + "Placeholder %%1 skipped in message {%2}.") + .arg(QString::number(i + 1), shortenMessage(translation)); } } // If no gaps, check for mismatch between the number of // unique placeholders and actually supplied arguments. if (!gaps && ords.size() != arguments.size()) { - qWarning() << QString::fromLatin1( - "%1 instead of %2 arguments to message {%3} " - "supplied before conversion.") - .arg(arguments.size()).arg(ords.size()) - .arg(shortenMessage(translation)); + qCWarning(KI18N) << QString::fromLatin1( + "%1 instead of %2 arguments to message {%3} " + "supplied before conversion.") + .arg(arguments.size()).arg(ords.size()) + .arg(shortenMessage(translation)); } // Some spoofs. @@ -902,10 +903,10 @@ ++tpos; } if (tpos == slen) { - qWarning() << QStringLiteral( - "Unclosed interpolation {%1} in message {%2}.") - .arg(scriptedTranslation.mid(pos, tpos - pos), - shortenMessage(scriptedTranslation)); + qCWarning(KI18N) << QStringLiteral( + "Unclosed interpolation {%1} in message {%2}.") + .arg(scriptedTranslation.mid(pos, tpos - pos), + shortenMessage(scriptedTranslation)); return -1; } if (scriptedTranslation.midRef(tpos, ielen) == s->endInterp) { @@ -935,10 +936,10 @@ ++tpos; } if (tpos == slen) { - qWarning() << QStringLiteral( - "Unclosed quote in interpolation {%1} in message {%2}.") - .arg(scriptedTranslation.mid(pos, tpos - pos), - shortenMessage(scriptedTranslation)); + qCWarning(KI18N) << QStringLiteral( + "Unclosed quote in interpolation {%1} in message {%2}.") + .arg(scriptedTranslation.mid(pos, tpos - pos), + shortenMessage(scriptedTranslation)); return -1; } @@ -976,10 +977,10 @@ ++tpos; } if (tpos == slen) { - qWarning() << QStringLiteral( - "Non-terminated interpolation {%1} in message {%2}.") - .arg(scriptedTranslation.mid(pos, tpos - pos), - shortenMessage(scriptedTranslation)); + qCWarning(KI18N) << QStringLiteral( + "Non-terminated interpolation {%1} in message {%2}.") + .arg(scriptedTranslation.mid(pos, tpos - pos), + shortenMessage(scriptedTranslation)); return -1; } @@ -1031,11 +1032,11 @@ if (!scriptError.isEmpty()) { // problem with evaluation fallback = true; // also signal fallback if (!scriptError.isEmpty()) { - qWarning() << QStringLiteral( - "Interpolation {%1} in {%2} failed: %3") - .arg(scriptedTranslation.mid(pos, tpos - pos), - shortenMessage(scriptedTranslation), - scriptError); + qCWarning(KI18N) << QStringLiteral( + "Interpolation {%1} in {%2} failed: %3") + .arg(scriptedTranslation.mid(pos, tpos - pos), + shortenMessage(scriptedTranslation), + scriptError); } } @@ -1103,9 +1104,9 @@ // If the evaluation went wrong. if (!scriptError.isEmpty()) { - qWarning() << QStringLiteral( - "Post call {%1} for message {%2} failed: %3") - .arg(pcall, shortenMessage(msgid), scriptError); + qCWarning(KI18N) << QStringLiteral( + "Post call {%1} for message {%2} failed: %3") + .arg(pcall, shortenMessage(msgid), scriptError); return QString(); } @@ -1398,21 +1399,21 @@ // QPluginLoader is just used to find the plugin QPluginLoader loader(QStringLiteral("kf5/ktranscript")); if (loader.fileName().isEmpty()) { - qWarning() << "Cannot find Transcript plugin."; + qCWarning(KI18N) << "Cannot find Transcript plugin."; return; } QLibrary lib(loader.fileName()); if (!lib.load()) { - qWarning() << "Cannot load Transcript plugin:" - << lib.errorString(); + qCWarning(KI18N) << "Cannot load Transcript plugin:" + << lib.errorString(); return; } InitFunc initf = (InitFunc) lib.resolve("load_transcript"); if (!initf) { lib.unload(); - qWarning() << "Cannot find function load_transcript in Transcript plugin."; + qCWarning(KI18N) << "Cannot find function load_transcript in Transcript plugin."; return; } @@ -1489,8 +1490,8 @@ QMutexLocker lock(&s->klspMutex); if (!sourceText || !sourceText[0]) { - qWarning() << "KLocalizedString::translateQt: " - "Trying to look up translation of \"\", fix the code."; + qCWarning(KI18N) << "KLocalizedString::translateQt: " + "Trying to look up translation of \"\", fix the code."; return QString(); } diff --git a/src/kuitmarkup.cpp b/src/kuitmarkup.cpp --- a/src/kuitmarkup.cpp +++ b/src/kuitmarkup.cpp @@ -25,12 +25,13 @@ #include #include #include -#include #include #include #include +#include "ki18n_logging_kuit.h" + #define QL1S(x) QLatin1String(x) #define QSL(x) QStringLiteral(x) #define QL1C(x) QLatin1Char(x) @@ -496,13 +497,13 @@ formattedText = modText; } } else if (patterns.contains(attribKey)) { - qWarning() << QStringLiteral( - "Undefined visual format for tag <%1> and attribute combination %2: %3.") - .arg(name, attribKey, s->namesByFormat.value(format)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Undefined visual format for tag <%1> and attribute combination %2: %3.") + .arg(name, attribKey, s->namesByFormat.value(format)); } else { - qWarning() << QStringLiteral( - "Undefined attribute combination for tag <%1>: %2.") - .arg(name, attribKey); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Undefined attribute combination for tag <%1>: %2.") + .arg(name, attribKey); } return formattedText; } @@ -594,30 +595,30 @@ if (s->rolesByName.contains(roleName)) { role = s->rolesByName.value(roleName); } else if (!roleName.isEmpty()) { - qWarning() << QStringLiteral( - "Unknown role '@%1' in UI marker {%2}, visual format not set.") - .arg(roleName, marker); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Unknown role '@%1' in UI marker {%2}, visual format not set.") + .arg(roleName, marker); return; } else { - qWarning() << QStringLiteral( - "Empty role in UI marker {%1}, visual format not set.") - .arg(marker); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Empty role in UI marker {%1}, visual format not set.") + .arg(marker); return; } Kuit::Cue cue; if (s->cuesByName.contains(cueName)) { cue = s->cuesByName.value(cueName); if (!s->knownRoleCues.value(role).contains(cue)) { - qWarning() << QStringLiteral( - "Subcue ':%1' does not belong to role '@%2' in UI marker {%3}, visual format not set.") - .arg(cueName, roleName, marker); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Subcue ':%1' does not belong to role '@%2' in UI marker {%3}, visual format not set.") + .arg(cueName, roleName, marker); return; } } else if (!cueName.isEmpty()) { - qWarning() << QStringLiteral( - "Unknown subcue ':%1' in UI marker {%2}, visual format not set.") - .arg(cueName, marker); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Unknown subcue ':%1' in UI marker {%2}, visual format not set.") + .arg(cueName, marker); return; } else { cue = Kuit::UndefinedCue; @@ -1254,9 +1255,9 @@ Kuit::Role role = s->rolesByName.value(roleName, Kuit::UndefinedRole); if (role == Kuit::UndefinedRole) { // unknown role if (!roleName.isEmpty()) { - qWarning() << QStringLiteral( - "Unknown role '@%1' in UI marker in context {%2}.") - .arg(roleName, shorten(context)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Unknown role '@%1' in UI marker in context {%2}.") + .arg(roleName, shorten(context)); } } @@ -1267,15 +1268,15 @@ if (cue != Kuit::UndefinedCue) { // known subcue if (!s->knownRoleCues.value(role).contains(cue)) { cue = Kuit::UndefinedCue; - qWarning() << QStringLiteral( - "Subcue ':%1' does not belong to role '@%2' in UI marker in context {%3}.") - .arg(cueName, roleName, shorten(context)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Subcue ':%1' does not belong to role '@%2' in UI marker in context {%3}.") + .arg(cueName, roleName, shorten(context)); } } else { // unknown or not given subcue if (!cueName.isEmpty()) { - qWarning() << QStringLiteral( - "Unknown subcue ':%1' in UI marker in context {%2}.") - .arg(cueName, shorten(context)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Unknown subcue ':%1' in UI marker in context {%2}.") + .arg(cueName, shorten(context)); } } } else { @@ -1296,9 +1297,9 @@ } } if (!formatName.isEmpty()) { - qWarning() << QStringLiteral( - "Unknown format '/%1' in UI marker for message {%2}.") - .arg(formatName, shorten(context)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Unknown format '/%1' in UI marker for message {%2}.") + .arg(formatName, shorten(context)); } } if (format == Kuit::UndefinedFormat) { @@ -1420,10 +1421,10 @@ } if (xml.hasError()) { - qWarning() << QStringLiteral( - "Markup error in message {%1}: %2. Last tag parsed: %3. Complete message follows:\n%4") - .arg(shorten(text), xml.errorString(), lastElementName.toString(), - text); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Markup error in message {%1}: %2. Last tag parsed: %3. Complete message follows:\n%4") + .arg(shorten(text), xml.errorString(), lastElementName.toString(), + text); return QString(); } @@ -1464,9 +1465,9 @@ oel.handling = OpenEl::Proper; } else { oel.handling = OpenEl::Dropout; - qWarning() << QStringLiteral( - "Structuring tag ('%1') cannot be subtag of phrase tag ('%2') in message {%3}.") - .arg(tag.name, etag.name, shorten(text)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Structuring tag ('%1') cannot be subtag of phrase tag ('%2') in message {%3}.") + .arg(tag.name, etag.name, shorten(text)); } // Resolve attributes and compute attribute set key. @@ -1477,9 +1478,9 @@ attset << att; oel.attributes[att] = attribValues[i]; } else { - qWarning() << QStringLiteral( - "Attribute '%1' not defined for tag '%2' in message {%3}.") - .arg(att, tag.name, shorten(text)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Attribute '%1' not defined for tag '%2' in message {%3}.") + .arg(att, tag.name, shorten(text)); } } @@ -1489,9 +1490,9 @@ } else { // unknown element, leave it in verbatim oel.handling = OpenEl::Ignored; - qWarning() << QStringLiteral( - "Tag '%1' is not defined in message {%2}.") - .arg(oel.name, shorten(text)); + qCWarning(KI18N_KUIT) << QStringLiteral( + "Tag '%1' is not defined in message {%2}.") + .arg(oel.name, shorten(text)); } return oel;