KCalUtils

grantleeki18nlocalizer.cpp
1/*
2 * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 */
7
8#include "grantleeki18nlocalizer_p.h"
9#include "kcalutils_debug.h"
10
11#include <KTextTemplate/SafeString>
12#include <QLocale>
13
14#include <KLocalizedString>
15
16GrantleeKi18nLocalizer::GrantleeKi18nLocalizer()
17 : KTextTemplate::QtLocalizer()
18{
19}
20
21GrantleeKi18nLocalizer::~GrantleeKi18nLocalizer()
22{
23}
24
25QString GrantleeKi18nLocalizer::processArguments(const KLocalizedString &kstr, const QVariantList &arguments) const
26{
27 KLocalizedString str = kstr;
28 for (auto iter = arguments.cbegin(), end = arguments.cend(); iter != end; ++iter) {
29 switch (iter->userType()) {
31 str = str.subs(iter->toString());
32 break;
33 case QMetaType::Int:
34 str = str.subs(iter->toInt());
35 break;
36 case QMetaType::UInt:
37 str = str.subs(iter->toUInt());
38 break;
40 str = str.subs(iter->toLongLong());
41 break;
43 str = str.subs(iter->toULongLong());
44 break;
45 case QMetaType::Char:
46 str = str.subs(iter->toChar());
47 break;
49 str = str.subs(iter->toDouble());
50 break;
51 case QMetaType::User:
52 default:
53 if (iter->canConvert<KTextTemplate::SafeString>()) {
54 str = str.subs(iter->value<KTextTemplate::SafeString>().get());
55 break;
56 } else {
57 qCWarning(KCALUTILS_LOG) << "Unknown type" << iter->typeName() << "(" << iter->userType() << ")";
58 break;
59 }
60 }
61 }
62
63 // Return localized in the currently active locale
64 return str.toString("libkcalutils6");
65}
66
67QString GrantleeKi18nLocalizer::localizeContextString(const QString &string, const QString &context, const QVariantList &arguments) const
68{
69 const KLocalizedString str = kxi18nc(qPrintable(context), qPrintable(string));
70 return processArguments(str, arguments);
71}
72
73QString GrantleeKi18nLocalizer::localizeString(const QString &string, const QVariantList &arguments) const
74{
75 const KLocalizedString str = kxi18n(qPrintable(string));
76 return processArguments(str, arguments);
77}
78
79QString GrantleeKi18nLocalizer::localizePluralContextString(const QString &string,
80 const QString &pluralForm,
81 const QString &context,
82 const QVariantList &arguments) const
83{
84 const KLocalizedString str = kxi18ncp(qPrintable(context), qPrintable(string), qPrintable(pluralForm));
85 return processArguments(str, arguments);
86}
87
88QString GrantleeKi18nLocalizer::localizePluralString(const QString &string, const QString &pluralForm, const QVariantList &arguments) const
89{
90 const KLocalizedString str = kxi18np(qPrintable(string), qPrintable(pluralForm));
91 return processArguments(str, arguments);
92}
93
94QString GrantleeKi18nLocalizer::localizeMonetaryValue(qreal value, const QString &currencySymbol) const
95{
96 return QLocale(currentLocale()).toCurrencyString(value, currencySymbol);
97}
QString toString() const
KLocalizedString subs(const KLocalizedString &a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
KLocalizedString KI18N_EXPORT kxi18np(const char *singular, const char *plural)
KLocalizedString KI18N_EXPORT kxi18ncp(const char *context, const char *singular, const char *plural)
KLocalizedString KI18N_EXPORT kxi18n(const char *text)
KLocalizedString KI18N_EXPORT kxi18nc(const char *context, const char *text)
QString toCurrencyString(double value, const QString &symbol, int precision) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.