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 | * @see KLocalizedString |
25 | * @internal exported only for use in KI18nLocaleData. |
26 | */ |
27 | class KI18N_EXPORT KCatalog |
28 | { |
29 | public: |
30 | /** |
31 | * Constructor. |
32 | * |
33 | * @param name translation domain |
34 | * @param language translation language |
35 | */ |
36 | KCatalog(const QByteArray &domain, const QString &language); |
37 | |
38 | /** |
39 | * Destructor. |
40 | */ |
41 | ~KCatalog(); |
42 | |
43 | /** |
44 | * Get translation of the given message text. |
45 | * |
46 | * Do not pass empty message text. |
47 | * |
48 | * @param msgid message text |
49 | * |
50 | * @return translated message if found, <tt>QString()</tt> otherwise |
51 | */ |
52 | QString translate(const QByteArray &msgid) const; |
53 | |
54 | /** |
55 | * Get translation of the given message text with given context. |
56 | * |
57 | * Do not pass empty message text. |
58 | * |
59 | * @param msgctxt message context |
60 | * @param msgid message text |
61 | * |
62 | * @return translated message if found, <tt>QString()</tt> otherwise |
63 | */ |
64 | QString translate(const QByteArray &msgctxt, const QByteArray &msgid) const; |
65 | |
66 | /** |
67 | * Get translation of given message with plural forms. |
68 | * |
69 | * Do not pass empty message text. |
70 | * |
71 | * @param msgid singular message text |
72 | * @param msgid_plural plural message text |
73 | * @param n number for which the plural form is needed |
74 | * |
75 | * @return translated message if found, <tt>QString()</tt> otherwise |
76 | */ |
77 | QString translate(const QByteArray &msgid, const QByteArray &msgid_plural, qulonglong n) const; |
78 | |
79 | /** |
80 | * Get translation of given message with plural forms with given context. |
81 | * |
82 | * Do not pass empty message text. |
83 | * |
84 | * @param msgctxt message context |
85 | * @param msgid singular message text |
86 | * @param msgid_plural plural message text |
87 | * @param n number for which the plural form is needed |
88 | * |
89 | * @return translated message if found, <tt>QString()</tt> otherwise |
90 | */ |
91 | QString translate(const QByteArray &msgctxt, const QByteArray &msgid, const QByteArray &msgid_plural, qulonglong n) const; |
92 | |
93 | /** |
94 | * Find the locale directory for the given domain in the given language. |
95 | * |
96 | * @param domain translation domain |
97 | * @param language language of the catalog |
98 | * |
99 | * @return the locale directory if found, <tt>QByteArray()</tt> otherwise. |
100 | */ |
101 | static QString catalogLocaleDir(const QByteArray &domain, const QString &language); |
102 | |
103 | /** |
104 | * Find the all languages for which the translation catalog |
105 | * of given domain exists. |
106 | * |
107 | * @param domain translation domain |
108 | * |
109 | * @return set of language codes |
110 | */ |
111 | static QSet<QString> availableCatalogLanguages(const QByteArray &domain); |
112 | |
113 | static void addDomainLocaleDir(const QByteArray &domain, const QString &path); |
114 | |
115 | private: |
116 | Q_DISABLE_COPY(KCatalog) |
117 | |
118 | std::unique_ptr<KCatalogPrivate> const d; |
119 | }; |
120 | |
121 | #endif |
122 | |