File indexing completed on 2024-04-21 03:54:20

0001 /*  This file is part of the KDE libraries
0002     SPDX-FileCopyrightText: 2001 Hans Petter Bieker <bieker@kde.org>
0003     SPDX-FileCopyrightText: 2012, 2013 Chusslove Illich <caslav.ilic@gmx.net>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KCATALOG_H
0009 #define KCATALOG_H
0010 
0011 #include "ki18n_export.h"
0012 
0013 #include <QByteArray>
0014 #include <QSet>
0015 #include <QString>
0016 #include <memory>
0017 
0018 class KCatalogPrivate;
0019 
0020 /**
0021  * This class abstracts a Gettext message catalog.
0022  * It takes care of needed Gettext bindings.
0023  *
0024  * @see KLocalizedString
0025  * @internal exported only for use in KI18nLocaleData.
0026  */
0027 class KI18N_EXPORT KCatalog
0028 {
0029 public:
0030     /**
0031      * Constructor.
0032      *
0033      * @param name translation domain
0034      * @param language translation language
0035      */
0036     KCatalog(const QByteArray &domain, const QString &language);
0037 
0038     /**
0039      * Destructor.
0040      */
0041     ~KCatalog();
0042 
0043     /**
0044      * Get translation of the given message text.
0045      *
0046      * Do not pass empty message text.
0047      *
0048      * @param msgid message text
0049      *
0050      * @return translated message if found, <tt>QString()</tt> otherwise
0051      */
0052     QString translate(const QByteArray &msgid) const;
0053 
0054     /**
0055      * Get translation of the given message text with given context.
0056      *
0057      * Do not pass empty message text.
0058      *
0059      * @param msgctxt message context
0060      * @param msgid message text
0061      *
0062      * @return translated message if found, <tt>QString()</tt> otherwise
0063      */
0064     QString translate(const QByteArray &msgctxt, const QByteArray &msgid) const;
0065 
0066     /**
0067      * Get translation of given message with plural forms.
0068      *
0069      * Do not pass empty message text.
0070      *
0071      * @param msgid singular message text
0072      * @param msgid_plural plural message text
0073      * @param n number for which the plural form is needed
0074      *
0075      * @return translated message if found, <tt>QString()</tt> otherwise
0076      */
0077     QString translate(const QByteArray &msgid, const QByteArray &msgid_plural, qulonglong n) const;
0078 
0079     /**
0080      * Get translation of given message with plural forms with given context.
0081      *
0082      * Do not pass empty message text.
0083      *
0084      * @param msgctxt message context
0085      * @param msgid singular message text
0086      * @param msgid_plural plural message text
0087      * @param n number for which the plural form is needed
0088      *
0089      * @return translated message if found, <tt>QString()</tt> otherwise
0090      */
0091     QString translate(const QByteArray &msgctxt, const QByteArray &msgid, const QByteArray &msgid_plural, qulonglong n) const;
0092 
0093     /**
0094      * Find the locale directory for the given domain in the given language.
0095      *
0096      * @param domain translation domain
0097      * @param language language of the catalog
0098      *
0099      * @return the locale directory if found, <tt>QByteArray()</tt> otherwise.
0100      */
0101     static QString catalogLocaleDir(const QByteArray &domain, const QString &language);
0102 
0103     /**
0104      * Find the all languages for which the translation catalog
0105      * of given domain exists.
0106      *
0107      * @param domain translation domain
0108      *
0109      * @return set of language codes
0110      */
0111     static QSet<QString> availableCatalogLanguages(const QByteArray &domain);
0112 
0113     static void addDomainLocaleDir(const QByteArray &domain, const QString &path);
0114 
0115 private:
0116     Q_DISABLE_COPY(KCatalog)
0117 
0118     std::unique_ptr<KCatalogPrivate> const d;
0119 };
0120 
0121 #endif