KI18n

klocalizedtranslator.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#include "klocalizedtranslator.h"
7#include "klocalizedstring.h"
8
9// Qt
10#include <QMetaObject>
11#include <QMetaProperty>
12
13class KLocalizedTranslatorPrivate
14{
15public:
16 QString translationDomain;
17 QSet<QString> monitoredContexts;
18};
19
20KLocalizedTranslator::KLocalizedTranslator(QObject *parent)
21 : QTranslator(parent)
22 , d(new KLocalizedTranslatorPrivate)
23{
24}
25
26KLocalizedTranslator::~KLocalizedTranslator()
27{
28}
29
31{
32 d->translationDomain = translationDomain;
33}
34
36{
37 d->monitoredContexts.insert(context);
38}
39
41{
42 d->monitoredContexts.remove(context);
43}
44
45QString KLocalizedTranslator::translate(const char *context, const char *sourceText, const char *disambiguation, int n) const
46{
47 if (d->translationDomain.isEmpty() || !d->monitoredContexts.contains(QString::fromUtf8(context))) {
48 return QTranslator::translate(context, sourceText, disambiguation, n);
49 }
50 if (qstrlen(disambiguation) == 0) {
51 return ki18nd(d->translationDomain.toUtf8().constData(), sourceText).toString();
52 } else {
53 return ki18ndc(d->translationDomain.toUtf8().constData(), disambiguation, sourceText).toString();
54 }
55}
56
57#include "moc_klocalizedtranslator.cpp"
QString toString() const
Finalize the translation.
void addContextToMonitor(const QString &context)
Adds a context for which this Translator should be active.
void setTranslationDomain(const QString &translationDomain)
Sets the translationDomain to be used.
void removeContextToMonitor(const QString &context)
Stop translating for the given context.
QString fromUtf8(QByteArrayView str)
virtual QString translate(const char *context, const char *sourceText, const char *disambiguation, int n) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.