SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / grantleetheme / src / grantleeki18nlocalizer.cpp
blob5ea7d1c492dbee205d6f34567cdf70c7a5be8795
1 /*
2 * Copyright (C) 2015 Daniel Vrátil <dvratil@redhat.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "grantleeki18nlocalizer_p.h"
21 #include "grantleetheme_debug.h"
23 #include <QLocale>
24 #include <QDate>
26 #include <grantlee/safestring.h>
28 #include <KLocalizedString>
30 GrantleeKi18nLocalizer::GrantleeKi18nLocalizer()
31 : Grantlee::QtLocalizer()
35 GrantleeKi18nLocalizer::~GrantleeKi18nLocalizer()
40 QString GrantleeKi18nLocalizer::processArguments(const KLocalizedString &kstr,
41 const QVariantList &arguments) const
43 KLocalizedString str = kstr;
44 for (auto iter = arguments.cbegin(), end = arguments.cend(); iter != end; ++iter) {
45 switch (iter->type()) {
46 case QVariant::String:
47 str = str.subs(iter->toString());
48 break;
49 case QVariant::Int:
50 str = str.subs(iter->toInt());
51 break;
52 case QVariant::UInt:
53 str = str.subs(iter->toUInt());
54 break;
55 case QVariant::LongLong:
56 str = str.subs(iter->toLongLong());
57 break;
58 case QVariant::ULongLong:
59 str = str.subs(iter->toULongLong());
60 break;
61 case QVariant::Char:
62 str = str.subs(iter->toChar());
63 break;
64 case QVariant::Double:
65 str = str.subs(iter->toDouble());
66 break;
67 case QVariant::UserType:
68 if (iter->canConvert<Grantlee::SafeString>()) {
69 str = str.subs(iter->value<Grantlee::SafeString>().get());
70 break;
72 // fall-through
73 default:
74 qCWarning(GRANTLEETHEME_LOG) << "Unknown type" << iter->typeName() << "(" << iter->type() << ")";
75 break;
79 // Return localized in the currenctly active locale
80 return str.toString({ currentLocale() });
83 QString GrantleeKi18nLocalizer::localizeContextString(const QString &string, const QString &context, const QVariantList &arguments) const
85 const KLocalizedString str = kxi18nc(qPrintable(context), qPrintable(string));
86 return processArguments(str, arguments);
89 QString GrantleeKi18nLocalizer::localizeString(const QString &string, const QVariantList &arguments) const
91 const KLocalizedString str = kxi18n(qPrintable(string));
92 return processArguments(str, arguments);
95 QString GrantleeKi18nLocalizer::localizePluralContextString(const QString &string, const QString &pluralForm,
96 const QString &context, const QVariantList &arguments) const
98 const KLocalizedString str = kxi18ncp(qPrintable(context), qPrintable(string), qPrintable(pluralForm));
99 return processArguments(str, arguments);
102 QString GrantleeKi18nLocalizer::localizePluralString(const QString &string, const QString &pluralForm,
103 const QVariantList &arguments) const
105 const KLocalizedString str = kxi18np(qPrintable(string), qPrintable(pluralForm));
106 return processArguments(str, arguments);
109 QString GrantleeKi18nLocalizer::localizeMonetaryValue(qreal value, const QString &currencySymbol) const
111 return QLocale(currentLocale()).toCurrencyString(value, currencySymbol);