File indexing completed on 2024-04-14 14:27:10

0001 /***************************************************************************
0002  * translation.h
0003  * This file is part of the KDE project
0004  * copyright (C)2008 by Dag Andersen <danders@get2net.dk>
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this program; see the file COPYING.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  ***************************************************************************/
0019 
0020 #ifndef KROSS_TRANSLATION_H
0021 #define KROSS_TRANSLATION_H
0022 
0023 #include <QObject>
0024 #include <QVariantList>
0025 
0026 class QString;
0027 
0028 class KLocalizedString;
0029 
0030 namespace Kross
0031 {
0032 
0033 /**
0034  * The TranslationModule provides access to KDE translation and internationalization facilities.
0035  *
0036  * Example (in Python) :
0037  * \code
0038  * import Kross
0039  * t = Kross.module("kdetranslation")
0040  * print t.i18n("This string can be translated")
0041  * print t.i18ncp("Plural example", "%1 file not deleted %2", "%1 files not deleted %2", 3, [t.i18n("yesterday")])
0042  * \endcode
0043  */
0044 class TranslationModule: public QObject
0045 {
0046     Q_OBJECT
0047 
0048 public:
0049     explicit TranslationModule();
0050     ~TranslationModule() override;
0051 
0052 public Q_SLOTS:
0053     /// Creates localized string from a given @p text. Substitute @p arguments (may be empty)
0054     QString i18n(const QString &text, const QVariantList &arguments = QVariantList()) const;
0055     /// Creates localized string from a given @p text, with added context. Substitute @p arguments (may be empty)
0056     QString i18nc(const QString &context, const QString &text, const QVariantList &arguments = QVariantList()) const;
0057     /// Creates localized string from a given @p plural and @p singular form dependent on @p number. Substitute @p arguments (may be empty)
0058     QString i18np(const QString &singular, const QString &plural, int number, const QVariantList &arguments = QVariantList()) const;
0059     /// Creates localized string from a given @p plural and @p singular form dependent on @p number, with added context. Substitute @p arguments (may be empty)
0060     QString i18ncp(const QString &context, const QString &singular, const QString &plural, int number, const QVariantList &arguments = QVariantList()) const;
0061 
0062 protected:
0063     KLocalizedString substituteArguments(const KLocalizedString &kls, const QVariantList &arguments, int max = 99) const;
0064 
0065 private:
0066     /// \internal d-pointer class.
0067     class Private;
0068     /// \internal d-pointer instance.
0069     Private *const d;
0070 };
0071 }
0072 
0073 #endif
0074