Git commit a48ec499fd471799e46bfa6f43ff0d544d558139 by Boudewijn Rempt, on = behalf of L. E. Segovia. Committed on 30/09/2020 at 07:53. Pushed by rempt into branch 'krita/4.4.0'. Fix translation lookup in KisActionRegistry In b55fdf3303efa79c9c315916ab44a91b794b2ebd, unknowingly for translators, a default "action" message context was introduced for .action files. However, this context was hardcoded, meaning that translations would break if the text used a more specific disambiguation context. This is only part of the fix for bug 426992. To fix it completely, the i18n team must start marking strings as verified -- translations marked with 'fuzzy' are skipped by gettext. CCBUG: 426992 CCMAIL: kimageshop@kde.org M +31 -10 libs/widgetutils/kis_action_registry.cpp https://invent.kde.org/graphics/krita/commit/a48ec499fd471799e46bfa6f43ff0d= 544d558139 diff --git a/libs/widgetutils/kis_action_registry.cpp b/libs/widgetutils/ki= s_action_registry.cpp index 9022e1b9c9..e1b3092a22 100644 --- a/libs/widgetutils/kis_action_registry.cpp +++ b/libs/widgetutils/kis_action_registry.cpp @@ -80,6 +80,11 @@ namespace { bool m_explicitlyReset =3D false; }; = + // Convenience macros to extract a child node. + QDomElement getChild(QDomElement xml, QString node) { + return xml.firstChildElement(node); + } + // Convenience macros to extract text of a child node. QString getChildContent(QDomElement xml, QString node) { return xml.firstChildElement(node).text(); @@ -87,17 +92,33 @@ namespace { = // Use Krita debug logging categories instead of KDE's default qDebug(= ) for // harmless empty strings and translations - QString quietlyTranslate(const QString &s) { - if (s.isEmpty()) { - return s; + QString quietlyTranslate(const QDomElement &s) { + if (s.isNull() || s.text().isEmpty()) { + return QString(); + } + QString translatedString; + const QString attrContext =3D QStringLiteral("context"); + const QString attrDomain =3D QStringLiteral("translationDomain"); + QString context =3D QStringLiteral("action"); + + if (!s.attribute(attrContext).isEmpty()) { + context =3D s.attribute(attrContext); + } + + QByteArray domain =3D s.attribute(attrDomain).toUtf8(); + if (domain.isEmpty()) { + domain =3D s.ownerDocument().documentElement().attribute(attrD= omain).toUtf8(); + if (domain.isEmpty()) { + domain =3D KLocalizedString::applicationDomain(); + } } - QString translatedString =3D i18nc("action", s.toUtf8()); - if (translatedString =3D=3D s) { - translatedString =3D i18n(s.toUtf8()); + translatedString =3D i18ndc(domain.constData(), context.toUtf8().c= onstData(), s.text().toUtf8().constData()); + if (translatedString =3D=3D s.text()) { + translatedString =3D i18n(s.text().toUtf8().constData()); } if (translatedString.isEmpty()) { - dbgAction << "No translation found for" << s; - return s; + dbgAction << "No translation found for" << s.text(); + return s.text(); } = return translatedString; @@ -268,7 +289,7 @@ bool KisActionRegistry::propertizeAction(const QString = &name, QAction * a) QDomElement actionXml =3D info.xmlData; if (!actionXml.text().isEmpty()) { // i18n requires converting format from QString. - auto getChildContent_i18n =3D [=3D](QString node){return quietlyTr= anslate(getChildContent(actionXml, node));}; + auto getChildContent_i18n =3D [=3D](QString node){return quietlyTr= anslate(getChild(actionXml, node));}; = // Note: the fields in the .action documents marked for translatio= n are determined by extractrc. QString icon =3D getChildContent(actionXml, "icon"); @@ -340,7 +361,7 @@ void KisActionRegistry::Private::loadActionFiles() = // field QDomElement categoryTextNode =3D actions.firstChild().toElemen= t(); - QString categoryName =3D quietlyTranslate(categoryText= Node.text()); + QString categoryName =3D quietlyTranslate(categoryText= Node); = // tags QDomElement actionXml =3D categoryTextNode.nextSiblingElement= ();