KXmlGui

ktoolbarhelper.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Alexander Potashev <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "ktoolbarhelper_p.h"
8 
9 #include <QVector>
10 
11 #include <klocalizedstring.h>
12 
13 namespace KToolbarHelper {
14 
15 QString i18nToolBarName(const QDomElement &element)
16 {
17  QDomElement textElement;
18  bool textElementFound = false;
19  const QVector<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
QString attribute(const QString &name, const QString &defValue) const const
bool isElement() const const
bool isEmpty() const const
QDomElement documentElement() const const
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QDomElement toElement() const const
QDomDocument ownerDocument() const const
QString text() const const
const char * constData() const const
static QByteArray applicationDomain()
QDomNode namedItem(const QString &name) const const
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 22:50:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.