KI18n

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

KDE's Doxygen guidelines are available online.