• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Kross

  • kross
  • modules
translation.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * translation.cpp
3 * This file is part of the KDE project
4 * copyright (C)2008 by Dag Andersen <danders@get2net.dk>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#include "translation.h"
21
22#include <QString>
23#include <QVariant>
24#include <QVariantList>
25
26#include <kdebug.h>
27#include <klocale.h>
28#include <klocalizedstring.h>
29#include <kpluginloader.h>
30#include <kpluginfactory.h>
31
32extern "C"
33{
34 KDE_EXPORT QObject* krossmodule()
35 {
36 return new Kross::TranslationModule();
37 }
38}
39
40using namespace Kross;
41
42
43namespace Kross {
44
46 class TranslationModule::Private
47 {
48 };
49}
50
51TranslationModule::TranslationModule()
52 : QObject()
53 , d( new Private() )
54{
55}
56
57TranslationModule::~TranslationModule()
58{
59 delete d;
60}
61
62KLocalizedString TranslationModule::substituteArguments( const KLocalizedString &kls, const QVariantList &arguments, int max ) const
63{
64 KLocalizedString ls = kls;
65 int cnt = qMin( arguments.count(), max ); // QString supports max 99
66 for ( int i = 0; i < cnt; ++i ) {
67 QVariant arg = arguments[i];
68 switch ( arg.type() ) {
69 case QVariant::Int: ls = ls.subs(arg.toInt()); break;
70 case QVariant::UInt: ls = ls.subs(arg.toUInt()); break;
71 case QVariant::LongLong: ls = ls.subs(arg.toLongLong()); break;
72 case QVariant::ULongLong: ls = ls.subs(arg.toULongLong()); break;
73 case QVariant::Double: ls = ls.subs(arg.toDouble()); break;
74 default: ls = ls.subs(arg.toString()); break;
75 }
76 }
77 return ls;
78}
79
80QString TranslationModule::i18n( const QString &text, const QVariantList &arguments ) const
81{
82 KLocalizedString ls = ki18n(text.toUtf8());
83 return substituteArguments( ls, arguments ).toString();
84}
85
86QString TranslationModule::i18nc( const QString &context, const QString &text, const QVariantList &arguments ) const
87{
88 KLocalizedString ls = ki18nc(context.toUtf8(), text.toUtf8());
89 return substituteArguments( ls, arguments ).toString();
90}
91
92QString TranslationModule::i18np( const QString &singular, const QString &plural, int number, const QVariantList &arguments ) const
93{
94 KLocalizedString ls = ki18np(singular.toUtf8(), plural.toUtf8()).subs(number);
95 return substituteArguments( ls, arguments, 98 ).toString();
96}
97
98QString TranslationModule::i18ncp( const QString &context, const QString &singular, const QString &plural, int number, const QVariantList &arguments ) const
99{
100 KLocalizedString ls = ki18ncp(context.toUtf8(), singular.toUtf8(), plural.toUtf8()).subs( number );
101 return substituteArguments( ls, arguments, 98 ).toString();
102}
103
104#include "translation.moc"
KLocalizedString
KLocalizedString::toString
QString toString() const
KLocalizedString::subs
KLocalizedString subs(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char(' ')) const
Kross::TranslationModule
The TranslationModule provides access to KDE translation and internationalization facilities.
Definition: translation.h:44
Kross::TranslationModule::i18nc
QString i18nc(const QString &context, const QString &text, const QVariantList &arguments=QVariantList()) const
Creates localized string from a given text, with added context. Substitute arguments (may be empty)
Definition: translation.cpp:86
Kross::TranslationModule::i18np
QString i18np(const QString &singular, const QString &plural, int number, const QVariantList &arguments=QVariantList()) const
Creates localized string from a given plural and singular form dependent on number....
Definition: translation.cpp:92
Kross::TranslationModule::substituteArguments
KLocalizedString substituteArguments(const KLocalizedString &kls, const QVariantList &arguments, int max=99) const
Definition: translation.cpp:62
Kross::TranslationModule::~TranslationModule
virtual ~TranslationModule()
Definition: translation.cpp:57
Kross::TranslationModule::i18n
QString i18n(const QString &text, const QVariantList &arguments=QVariantList()) const
Creates localized string from a given text. Substitute arguments (may be empty)
Definition: translation.cpp:80
Kross::TranslationModule::TranslationModule
TranslationModule()
Definition: translation.cpp:51
Kross::TranslationModule::i18ncp
QString i18ncp(const QString &context, const QString &singular, const QString &plural, int number, const QVariantList &arguments=QVariantList()) const
Creates localized string from a given plural and singular form dependent on number,...
Definition: translation.cpp:98
QObject
kdebug.h
klocale.h
ki18n
KLocalizedString ki18n(const char *msg)
ki18ncp
KLocalizedString ki18ncp(const char *ctxt, const char *singular, const char *plural)
ki18nc
KLocalizedString ki18nc(const char *ctxt, const char *msg)
ki18np
KLocalizedString ki18np(const char *singular, const char *plural)
klocalizedstring.h
kpluginfactory.h
kpluginloader.h
Kross
Definition: action.cpp:36
krossmodule
QObject * krossmodule()
Definition: translation.cpp:34
translation.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal