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

Kross

  • sources
  • kde-4.12
  • kdelibs
  • 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 
32 extern "C"
33 {
34  KDE_EXPORT QObject* krossmodule()
35  {
36  return new Kross::TranslationModule();
37  }
38 }
39 
40 using namespace Kross;
41 
42 
43 namespace Kross {
44 
46  class TranslationModule::Private
47  {
48  };
49 }
50 
51 TranslationModule::TranslationModule()
52  : QObject()
53  , d( new Private() )
54 {
55 }
56 
57 TranslationModule::~TranslationModule()
58 {
59  delete d;
60 }
61 
62 KLocalizedString 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 
80 QString TranslationModule::i18n( const QString &text, const QVariantList &arguments ) const
81 {
82  KLocalizedString ls = ki18n(text.toUtf8());
83  return substituteArguments( ls, arguments ).toString();
84 }
85 
86 QString 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 
92 QString 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 
98 QString 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"
QVariant
KLocalizedString::toString
QString toString() const
kdebug.h
Kross::TranslationModule::~TranslationModule
virtual ~TranslationModule()
Definition: translation.cpp:57
Kross::TranslationModule::TranslationModule
TranslationModule()
Definition: translation.cpp:51
krossmodule
QObject * krossmodule()
Definition: translation.cpp:34
ki18n
KLocalizedString ki18n(const char *msg)
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, with added context. Substitute arguments (may be empty)
Definition: translation.cpp:98
QString
QObject
klocale.h
ki18np
KLocalizedString ki18np(const char *singular, const char *plural)
kpluginloader.h
translation.h
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. Substitute arguments (may be empty)
Definition: translation.cpp:92
ki18ncp
KLocalizedString ki18ncp(const char *ctxt, const char *singular, const char *plural)
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
klocalizedstring.h
kpluginfactory.h
ki18nc
KLocalizedString ki18nc(const char *ctxt, const char *msg)
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
KLocalizedString::subs
KLocalizedString subs(int a, int fieldWidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const
Kross::TranslationModule
The TranslationModule provides access to KDE translation and internationalization facilities...
Definition: translation.h:43
KLocalizedString
Kross::TranslationModule::substituteArguments
KLocalizedString substituteArguments(const KLocalizedString &kls, const QVariantList &arguments, int max=99) const
Definition: translation.cpp:62
KDE_EXPORT
#define KDE_EXPORT
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:54 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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