KI18n

klocalizedcontext.h
1 /*
2  SPDX-FileCopyrightText: 2011 Marco Martin <[email protected]>
3  SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KLOCALIZEDCONTEXT_H
9 #define KLOCALIZEDCONTEXT_H
10 
11 #include <QObject>
12 #include <QVariant>
13 #include <ki18n_export.h>
14 #include <memory>
15 
16 /**
17  * @class KLocalizedContext klocalizedcontext.h <KLocalizedContext>
18  *
19  * This class is meant to be used to simplify integration of the KI18n framework
20  * in QML.
21  *
22  * The way to do so, is by creating this object and setting it as a context
23  * object:
24  *
25  * @code
26  * QQuickView* view = new QQuickView;
27  * view.engine()->rootContext()->setContextObject(new KLocalizedContext(view));
28  * @endcode
29  *
30  * Then i18n*() and xi18n*() functions should be available for use from the code
31  * loaded in the engine, for the view.
32  *
33  * @note Plural functions differ from the C/C++ version. On QML/JS we can get a
34  * real value easily. To solve warnings on those cases we'll cast the first argument
35  * to make sure it's taken into account for the plural.
36  *
37  * @since 5.17
38  */
39 
40 class KI18N_EXPORT KLocalizedContext : public QObject
41 {
42  Q_OBJECT
43 
44  /**
45  * This property only needs to be specified if the context is being run on a library.
46  * in an application there is no need to set the translation domain as the application's
47  * domain can be used.
48  */
49  Q_PROPERTY(QString translationDomain READ translationDomain WRITE setTranslationDomain NOTIFY translationDomainChanged)
50 
51 public:
52  explicit KLocalizedContext(QObject *parent = nullptr);
53  ~KLocalizedContext() override;
54 
55  QString translationDomain() const;
56  void setTranslationDomain(const QString &domain);
57 
58  Q_INVOKABLE QString i18n(const QString &message,
59  const QVariant &p1 = QVariant(),
60  const QVariant &p2 = QVariant(),
61  const QVariant &p3 = QVariant(),
62  const QVariant &p4 = QVariant(),
63  const QVariant &p5 = QVariant(),
64  const QVariant &p6 = QVariant(),
65  const QVariant &p7 = QVariant(),
66  const QVariant &p8 = QVariant(),
67  const QVariant &p9 = QVariant(),
68  const QVariant &p10 = QVariant()) const;
69 
70  Q_INVOKABLE QString i18nc(const QString &context,
71  const QString &message,
72  const QVariant &p1 = QVariant(),
73  const QVariant &p2 = QVariant(),
74  const QVariant &p3 = QVariant(),
75  const QVariant &p4 = QVariant(),
76  const QVariant &p5 = QVariant(),
77  const QVariant &p6 = QVariant(),
78  const QVariant &p7 = QVariant(),
79  const QVariant &p8 = QVariant(),
80  const QVariant &p9 = QVariant(),
81  const QVariant &p10 = QVariant()) const;
82 
83  Q_INVOKABLE QString i18np(const QString &singular,
84  const QString &plural,
85  const QVariant &p1 = QVariant(),
86  const QVariant &p2 = QVariant(),
87  const QVariant &p3 = QVariant(),
88  const QVariant &p4 = QVariant(),
89  const QVariant &p5 = QVariant(),
90  const QVariant &p6 = QVariant(),
91  const QVariant &p7 = QVariant(),
92  const QVariant &p8 = QVariant(),
93  const QVariant &p9 = QVariant(),
94  const QVariant &p10 = QVariant()) const;
95 
96  Q_INVOKABLE QString i18ncp(const QString &context,
97  const QString &singular,
98  const QString &plural,
99  const QVariant &p1 = QVariant(),
100  const QVariant &p2 = QVariant(),
101  const QVariant &p3 = QVariant(),
102  const QVariant &p4 = QVariant(),
103  const QVariant &p5 = QVariant(),
104  const QVariant &p6 = QVariant(),
105  const QVariant &p7 = QVariant(),
106  const QVariant &p8 = QVariant(),
107  const QVariant &p9 = QVariant(),
108  const QVariant &p10 = QVariant()) const;
109 
110  Q_INVOKABLE QString i18nd(const QString &domain,
111  const QString &message,
112  const QVariant &p1 = QVariant(),
113  const QVariant &p2 = QVariant(),
114  const QVariant &p3 = QVariant(),
115  const QVariant &p4 = QVariant(),
116  const QVariant &p5 = QVariant(),
117  const QVariant &p6 = QVariant(),
118  const QVariant &p7 = QVariant(),
119  const QVariant &p8 = QVariant(),
120  const QVariant &p9 = QVariant(),
121  const QVariant &p10 = QVariant()) const;
122 
123  Q_INVOKABLE QString i18ndc(const QString &domain,
124  const QString &context,
125  const QString &message,
126  const QVariant &p1 = QVariant(),
127  const QVariant &p2 = QVariant(),
128  const QVariant &p3 = QVariant(),
129  const QVariant &p4 = QVariant(),
130  const QVariant &p5 = QVariant(),
131  const QVariant &p6 = QVariant(),
132  const QVariant &p7 = QVariant(),
133  const QVariant &p8 = QVariant(),
134  const QVariant &p9 = QVariant(),
135  const QVariant &p10 = QVariant()) const;
136 
137  Q_INVOKABLE QString i18ndp(const QString &domain,
138  const QString &singular,
139  const QString &plural,
140  const QVariant &p1 = QVariant(),
141  const QVariant &p2 = QVariant(),
142  const QVariant &p3 = QVariant(),
143  const QVariant &p4 = QVariant(),
144  const QVariant &p5 = QVariant(),
145  const QVariant &p6 = QVariant(),
146  const QVariant &p7 = QVariant(),
147  const QVariant &p8 = QVariant(),
148  const QVariant &p9 = QVariant(),
149  const QVariant &p10 = QVariant()) const;
150 
151  Q_INVOKABLE QString i18ndcp(const QString &domain,
152  const QString &context,
153  const QString &singular,
154  const QString &plural,
155  const QVariant &p1 = QVariant(),
156  const QVariant &p2 = QVariant(),
157  const QVariant &p3 = QVariant(),
158  const QVariant &p4 = QVariant(),
159  const QVariant &p5 = QVariant(),
160  const QVariant &p6 = QVariant(),
161  const QVariant &p7 = QVariant(),
162  const QVariant &p8 = QVariant(),
163  const QVariant &p9 = QVariant(),
164  const QVariant &p10 = QVariant()) const;
165 
166  Q_INVOKABLE QString xi18n(const QString &message,
167  const QVariant &p1 = QVariant(),
168  const QVariant &p2 = QVariant(),
169  const QVariant &p3 = QVariant(),
170  const QVariant &p4 = QVariant(),
171  const QVariant &p5 = QVariant(),
172  const QVariant &p6 = QVariant(),
173  const QVariant &p7 = QVariant(),
174  const QVariant &p8 = QVariant(),
175  const QVariant &p9 = QVariant(),
176  const QVariant &p10 = QVariant()) const;
177 
178  Q_INVOKABLE QString xi18nc(const QString &context,
179  const QString &message,
180  const QVariant &p1 = QVariant(),
181  const QVariant &p2 = QVariant(),
182  const QVariant &p3 = QVariant(),
183  const QVariant &p4 = QVariant(),
184  const QVariant &p5 = QVariant(),
185  const QVariant &p6 = QVariant(),
186  const QVariant &p7 = QVariant(),
187  const QVariant &p8 = QVariant(),
188  const QVariant &p9 = QVariant(),
189  const QVariant &p10 = QVariant()) const;
190 
191  Q_INVOKABLE QString xi18np(const QString &singular,
192  const QString &plural,
193  const QVariant &p1 = QVariant(),
194  const QVariant &p2 = QVariant(),
195  const QVariant &p3 = QVariant(),
196  const QVariant &p4 = QVariant(),
197  const QVariant &p5 = QVariant(),
198  const QVariant &p6 = QVariant(),
199  const QVariant &p7 = QVariant(),
200  const QVariant &p8 = QVariant(),
201  const QVariant &p9 = QVariant(),
202  const QVariant &p10 = QVariant()) const;
203 
204  Q_INVOKABLE QString xi18ncp(const QString &context,
205  const QString &singular,
206  const QString &plural,
207  const QVariant &p1 = QVariant(),
208  const QVariant &p2 = QVariant(),
209  const QVariant &p3 = QVariant(),
210  const QVariant &p4 = QVariant(),
211  const QVariant &p5 = QVariant(),
212  const QVariant &p6 = QVariant(),
213  const QVariant &p7 = QVariant(),
214  const QVariant &p8 = QVariant(),
215  const QVariant &p9 = QVariant(),
216  const QVariant &p10 = QVariant()) const;
217 
218  Q_INVOKABLE QString xi18nd(const QString &domain,
219  const QString &message,
220  const QVariant &p1 = QVariant(),
221  const QVariant &p2 = QVariant(),
222  const QVariant &p3 = QVariant(),
223  const QVariant &p4 = QVariant(),
224  const QVariant &p5 = QVariant(),
225  const QVariant &p6 = QVariant(),
226  const QVariant &p7 = QVariant(),
227  const QVariant &p8 = QVariant(),
228  const QVariant &p9 = QVariant(),
229  const QVariant &p10 = QVariant()) const;
230 
231  Q_INVOKABLE QString xi18ndc(const QString &domain,
232  const QString &context,
233  const QString &message,
234  const QVariant &p1 = QVariant(),
235  const QVariant &p2 = QVariant(),
236  const QVariant &p3 = QVariant(),
237  const QVariant &p4 = QVariant(),
238  const QVariant &p5 = QVariant(),
239  const QVariant &p6 = QVariant(),
240  const QVariant &p7 = QVariant(),
241  const QVariant &p8 = QVariant(),
242  const QVariant &p9 = QVariant(),
243  const QVariant &p10 = QVariant()) const;
244 
245  Q_INVOKABLE QString xi18ndp(const QString &domain,
246  const QString &singular,
247  const QString &plural,
248  const QVariant &p1 = QVariant(),
249  const QVariant &p2 = QVariant(),
250  const QVariant &p3 = QVariant(),
251  const QVariant &p4 = QVariant(),
252  const QVariant &p5 = QVariant(),
253  const QVariant &p6 = QVariant(),
254  const QVariant &p7 = QVariant(),
255  const QVariant &p8 = QVariant(),
256  const QVariant &p9 = QVariant(),
257  const QVariant &p10 = QVariant()) const;
258 
259  Q_INVOKABLE QString xi18ndcp(const QString &domain,
260  const QString &context,
261  const QString &singular,
262  const QString &plural,
263  const QVariant &p1 = QVariant(),
264  const QVariant &p2 = QVariant(),
265  const QVariant &p3 = QVariant(),
266  const QVariant &p4 = QVariant(),
267  const QVariant &p5 = QVariant(),
268  const QVariant &p6 = QVariant(),
269  const QVariant &p7 = QVariant(),
270  const QVariant &p8 = QVariant(),
271  const QVariant &p9 = QVariant(),
272  const QVariant &p10 = QVariant()) const;
273 
274 Q_SIGNALS:
275  void translationDomainChanged(const QString &translationDomain);
276 
277 private:
278  std::unique_ptr<class KLocalizedContextPrivate> const d_ptr;
279  Q_DECLARE_PRIVATE(KLocalizedContext)
280 };
281 
282 #endif
QString xi18ncp(const char *context, const char *singular, const char *plural, const TYPE &arg...)
Translate a markup-aware string with context and plural and substitute any arguments.
QString xi18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
Translate a markup-aware string from domain with context and substitute any arguments.
Q_PROPERTY(...)
QString xi18nc(const char *context, const char *text, const TYPE &arg...)
Translate a markup-aware string with context and substitute any arguments.
QString xi18ndcp(const char *domain, const char *context, const char *singular, const char *plural, const TYPE &arg...)
Translate a markup-aware string from domain with context and plural and substitute any arguments.
QString xi18n(const char *text, const TYPE &arg...)
Translate a markup-aware string and substitute any arguments.
QString xi18ndp(const char *domain, const char *singular, const char *plural, const TYPE &arg...)
Translate a markup-aware string from domain with plural and substitute any arguments.
QString i18ncp(const char *context, const char *singular, const char *plural, const TYPE &arg...)
Translate a string with context and plural and substitute any arguments.
QString xi18nd(const char *domain, const char *text, const TYPE &arg...)
Translate a markup-aware string from domain and substitute any arguments.
QString xi18np(const char *singular, const char *plural, const TYPE &arg...)
Translate a markup-aware string with plural and substitute any arguments.
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
Translate a string from domain with context and substitute any arguments.
QString i18n(const char *text, const TYPE &arg...)
Translate a string and substitute any arguments.
QString i18ndp(const char *domain, const char *singular, const char *plural, const TYPE &arg...)
Translate a string from domain with plural and substitute any arguments.
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
Translate a string from domain and substitute any arguments.
Q_SIGNALSQ_SIGNALS
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
Translate a string with plural and substitute any arguments.
QString i18ndcp(const char *domain, const char *context, const char *singular, const char *plural, const TYPE &arg...)
Translate a string from domain with context and plural and substitute any arguments.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Translate a string with context and substitute any arguments.
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:07:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.