KXmlGui

ktoolbarhelper.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Alexander Potashev <aspotashev@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "ktoolbarhelper_p.h"
8
9#include <QList>
10
11#include <KLocalizedString>
12
13namespace KToolbarHelper
14{
15QString i18nToolBarName(const QDomElement &element)
16{
17 QDomElement textElement;
18 bool textElementFound = false;
19 const QList<QString> textKeys = {QStringLiteral("text"), QStringLiteral("Text")};
20 for (const QString &key : textKeys) {
21 QDomNode textNode = element.namedItem(key);
22 if (textNode.isElement()) {
23 textElement = textNode.toElement();
24 textElementFound = true;
25 break;
26 }
27 }
28
29 if (!textElementFound) {
30 return element.attribute(QStringLiteral("name"));
31 }
32
33 QByteArray domain = textElement.attribute(QStringLiteral("translationDomain")).toUtf8();
34 QByteArray text = textElement.text().toUtf8();
35 QByteArray context = textElement.attribute(QStringLiteral("context")).toUtf8();
36
37 if (domain.isEmpty()) {
38 domain = element.ownerDocument().documentElement().attribute(QStringLiteral("translationDomain")).toUtf8();
39 if (domain.isEmpty()) {
41 }
42 }
43 QString i18nText;
44 if (!text.isEmpty() && !context.isEmpty()) {
45 i18nText = i18ndc(domain.constData(), context.constData(), text.constData());
46 } else if (!text.isEmpty()) {
47 i18nText = i18nd(domain.constData(), text.constData());
48 }
49 return i18nText;
50}
51
52} // namespace KToolbarHelper
static QByteArray applicationDomain()
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
const char * constData() const const
bool isEmpty() const const
QDomElement documentElement() const const
QString attribute(const QString &name, const QString &defValue) const const
QString text() const const
bool isElement() const const
QDomNode namedItem(const QString &name) const const
QDomDocument ownerDocument() const const
QDomElement toElement() const const
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.