| 1 | /* This file is part of the KDE libraries |
| 2 | SPDX-FileCopyrightText: 2001 Hans Petter Bieker <bieker@kde.org> |
| 3 | SPDX-FileCopyrightText: 2012, 2013 Chusslove Illich <caslav.ilic@gmx.net> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef KCATALOG_H |
| 9 | #define KCATALOG_H |
| 10 | |
| 11 | #include "ki18n_export.h" |
| 12 | |
| 13 | #include <QByteArray> |
| 14 | #include <QSet> |
| 15 | #include <QString> |
| 16 | #include <memory> |
| 17 | |
| 18 | class KCatalogPrivate; |
| 19 | |
| 20 | /*! |
| 21 | * This class abstracts a Gettext message catalog. |
| 22 | * It takes care of needed Gettext bindings. |
| 23 | * |
| 24 | * \sa KLocalizedString |
| 25 | * \internal exported only for use in KI18nLocaleData. |
| 26 | */ |
| 27 | class KI18N_EXPORT KCatalog |
| 28 | { |
| 29 | public: |
| 30 | /*! |
| 31 | * Constructor. |
| 32 | * |
| 33 | * \a name translation domain |
| 34 | * |
| 35 | * \a language translation language |
| 36 | */ |
| 37 | KCatalog(const QByteArray &domain, const QString &language); |
| 38 | |
| 39 | /*! |
| 40 | * Destructor. |
| 41 | */ |
| 42 | ~KCatalog(); |
| 43 | |
| 44 | /*! |
| 45 | * Get translation of the given message text. |
| 46 | * |
| 47 | * Do not pass empty message text. |
| 48 | * |
| 49 | * \a msgid message text |
| 50 | * |
| 51 | * Returns translated message if found, QString() otherwise |
| 52 | */ |
| 53 | QString translate(const QByteArray &msgid) const; |
| 54 | |
| 55 | /*! |
| 56 | * Get translation of the given message text with given context. |
| 57 | * |
| 58 | * Do not pass empty message text. |
| 59 | * |
| 60 | * \a msgctxt message context |
| 61 | * |
| 62 | * \a msgid message text |
| 63 | * |
| 64 | * Returns translated message if found, QString() otherwise |
| 65 | */ |
| 66 | QString translate(const QByteArray &msgctxt, const QByteArray &msgid) const; |
| 67 | |
| 68 | /*! |
| 69 | * Get translation of given message with plural forms. |
| 70 | * |
| 71 | * Do not pass empty message text. |
| 72 | * |
| 73 | * \a msgid singular message text |
| 74 | * |
| 75 | * \a msgid_plural plural message text |
| 76 | * |
| 77 | * \a n number for which the plural form is needed |
| 78 | * |
| 79 | * Returns translated message if found, QString() otherwise |
| 80 | */ |
| 81 | QString translate(const QByteArray &msgid, const QByteArray &msgid_plural, qulonglong n) const; |
| 82 | |
| 83 | /*! |
| 84 | * Get translation of given message with plural forms with given context. |
| 85 | * |
| 86 | * Do not pass empty message text. |
| 87 | * |
| 88 | * \a msgctxt message context |
| 89 | * |
| 90 | * \a msgid singular message text |
| 91 | * |
| 92 | * \a msgid_plural plural message text |
| 93 | * |
| 94 | * \a n number for which the plural form is needed |
| 95 | * |
| 96 | * Returns translated message if found, QString() otherwise |
| 97 | */ |
| 98 | QString translate(const QByteArray &msgctxt, const QByteArray &msgid, const QByteArray &msgid_plural, qulonglong n) const; |
| 99 | |
| 100 | /*! |
| 101 | * Find the locale directory for the given domain in the given language. |
| 102 | * |
| 103 | * \a domain translation domain |
| 104 | * |
| 105 | * \a language language of the catalog |
| 106 | * |
| 107 | * Returns the locale directory if found, QByteArray() otherwise. |
| 108 | */ |
| 109 | static QString catalogLocaleDir(const QByteArray &domain, const QString &language); |
| 110 | |
| 111 | /*! |
| 112 | * Find the all languages for which the translation catalog |
| 113 | * of given domain exists. |
| 114 | * |
| 115 | * \a domain translation domain |
| 116 | * |
| 117 | * Returns set of language codes |
| 118 | */ |
| 119 | static QSet<QString> availableCatalogLanguages(const QByteArray &domain); |
| 120 | |
| 121 | static void addDomainLocaleDir(const QByteArray &domain, const QString &path); |
| 122 | |
| 123 | private: |
| 124 | Q_DISABLE_COPY(KCatalog) |
| 125 | |
| 126 | std::unique_ptr<KCatalogPrivate> const d; |
| 127 | }; |
| 128 | |
| 129 | #endif |
| 130 | |