File: ktoolbarhelper.cpp

package info (click to toggle)
kf6-kxmlgui 6.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,708 kB
  • sloc: cpp: 16,748; xml: 45; python: 41; ansic: 22; sh: 18; makefile: 7
file content (52 lines) | stat: -rw-r--r-- 1,580 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
    SPDX-FileCopyrightText: 2017 Alexander Potashev <aspotashev@gmail.com>

    SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "ktoolbarhelper_p.h"

#include <QList>

#include <KLocalizedString>

namespace KToolbarHelper
{
QString i18nToolBarName(const QDomElement &element)
{
    QDomElement textElement;
    bool textElementFound = false;
    const QList<QString> textKeys = {QStringLiteral("text"), QStringLiteral("Text")};
    for (const QString &key : textKeys) {
        QDomNode textNode = element.namedItem(key);
        if (textNode.isElement()) {
            textElement = textNode.toElement();
            textElementFound = true;
            break;
        }
    }

    if (!textElementFound) {
        return element.attribute(QStringLiteral("name"));
    }

    QByteArray domain = textElement.attribute(QStringLiteral("translationDomain")).toUtf8();
    QByteArray text = textElement.text().toUtf8();
    QByteArray context = textElement.attribute(QStringLiteral("context")).toUtf8();

    if (domain.isEmpty()) {
        domain = element.ownerDocument().documentElement().attribute(QStringLiteral("translationDomain")).toUtf8();
        if (domain.isEmpty()) {
            domain = KLocalizedString::applicationDomain();
        }
    }
    QString i18nText;
    if (!text.isEmpty() && !context.isEmpty()) {
        i18nText = i18ndc(domain.constData(), context.constData(), text.constData());
    } else if (!text.isEmpty()) {
        i18nText = i18nd(domain.constData(), text.constData());
    }
    return i18nText;
}

} // namespace KToolbarHelper