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 | |
13 | namespace KToolbarHelper |
14 | { |
15 | QString 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(name: 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()) { |
40 | domain = KLocalizedString::applicationDomain(); |
41 | } |
42 | } |
43 | QString i18nText; |
44 | if (!text.isEmpty() && !context.isEmpty()) { |
45 | i18nText = i18ndc(domain: domain.constData(), context: context.constData(), text: text.constData()); |
46 | } else if (!text.isEmpty()) { |
47 | i18nText = i18nd(domain: domain.constData(), text: text.constData()); |
48 | } |
49 | return i18nText; |
50 | } |
51 | |
52 | } // namespace KToolbarHelper |
53 | |