KDeclarative

translationcontext.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7// Undefine this because we don't want our i18n*() method names to be turned into i18nd*()
8#undef TRANSLATION_DOMAIN
9
10#include "translationcontext.h"
11
12#include <QDebug>
13
14#include <KLocalizedString>
15
16TranslationContext::TranslationContext(QObject *parent)
17 : QObject(parent)
18{
19}
20
21TranslationContext::~TranslationContext()
22{
23}
24
25QString TranslationContext::domain() const
26{
27 return m_domain;
28}
29
30void TranslationContext::setDomain(const QString &domain)
31{
32 if (m_domain == domain) {
33 return;
34 }
35
36 m_domain = domain;
37 Q_EMIT domainChanged(domain);
38}
39
40QString TranslationContext::i18n(const QString &message,
41 const QString &param1,
42 const QString &param2,
43 const QString &param3,
44 const QString &param4,
45 const QString &param5,
46 const QString &param6,
47 const QString &param7,
48 const QString &param8,
49 const QString &param9,
50 const QString &param10) const
51{
52 if (message.isNull()) {
53 qWarning() << "i18n() needs at least one parameter";
54 return QString();
55 }
56
57 KLocalizedString trMessage = ki18nd(m_domain.toUtf8().constData(), message.toUtf8().constData());
58
59 if (!param1.isNull()) {
60 trMessage = trMessage.subs(param1);
61 }
62 if (!param2.isNull()) {
63 trMessage = trMessage.subs(param2);
64 }
65 if (!param3.isNull()) {
66 trMessage = trMessage.subs(param3);
67 }
68 if (!param4.isNull()) {
69 trMessage = trMessage.subs(param4);
70 }
71 if (!param5.isNull()) {
72 trMessage = trMessage.subs(param5);
73 }
74 if (!param6.isNull()) {
75 trMessage = trMessage.subs(param6);
76 }
77 if (!param7.isNull()) {
78 trMessage = trMessage.subs(param7);
79 }
80 if (!param8.isNull()) {
81 trMessage = trMessage.subs(param8);
82 }
83 if (!param9.isNull()) {
84 trMessage = trMessage.subs(param9);
85 }
86 if (!param10.isNull()) {
87 trMessage = trMessage.subs(param10);
88 }
89
90 return trMessage.toString();
91}
92
93QString TranslationContext::i18nc(const QString &context,
94 const QString &message,
95 const QString &param1,
96 const QString &param2,
97 const QString &param3,
98 const QString &param4,
99 const QString &param5,
100 const QString &param6,
101 const QString &param7,
102 const QString &param8,
103 const QString &param9,
104 const QString &param10) const
105{
106 if (context.isNull() || message.isNull()) {
107 qWarning() << "i18nc() needs at least two arguments";
108 return QString();
109 }
110
111 KLocalizedString trMessage = ki18ndc(m_domain.toUtf8().constData(), context.toUtf8().constData(), message.toUtf8().constData());
112
113 if (!param1.isNull()) {
114 trMessage = trMessage.subs(param1);
115 }
116 if (!param2.isNull()) {
117 trMessage = trMessage.subs(param2);
118 }
119 if (!param3.isNull()) {
120 trMessage = trMessage.subs(param3);
121 }
122 if (!param4.isNull()) {
123 trMessage = trMessage.subs(param4);
124 }
125 if (!param5.isNull()) {
126 trMessage = trMessage.subs(param5);
127 }
128 if (!param6.isNull()) {
129 trMessage = trMessage.subs(param6);
130 }
131 if (!param7.isNull()) {
132 trMessage = trMessage.subs(param7);
133 }
134 if (!param8.isNull()) {
135 trMessage = trMessage.subs(param8);
136 }
137 if (!param9.isNull()) {
138 trMessage = trMessage.subs(param9);
139 }
140 if (!param10.isNull()) {
141 trMessage = trMessage.subs(param10);
142 }
143
144 return trMessage.toString();
145}
146
147QString TranslationContext::i18np(const QString &singular,
148 const QString &plural,
149 const QString &param1,
150 const QString &param2,
151 const QString &param3,
152 const QString &param4,
153 const QString &param5,
154 const QString &param6,
155 const QString &param7,
156 const QString &param8,
157 const QString &param9,
158 const QString &param10) const
159{
160 if (singular.isNull() || plural.isNull()) {
161 qWarning() << "i18np() needs at least two arguments";
162 return QString();
163 }
164
165 KLocalizedString trMessage = ki18ndp(m_domain.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
166
167 if (!param1.isNull()) {
168 bool ok;
169 int num = param1.toInt(&ok);
170 if (ok) {
171 trMessage = trMessage.subs(num);
172 } else {
173 trMessage = trMessage.subs(param1);
174 }
175 }
176 if (!param2.isNull()) {
177 trMessage = trMessage.subs(param2);
178 }
179 if (!param3.isNull()) {
180 trMessage = trMessage.subs(param3);
181 }
182 if (!param4.isNull()) {
183 trMessage = trMessage.subs(param4);
184 }
185 if (!param5.isNull()) {
186 trMessage = trMessage.subs(param5);
187 }
188 if (!param6.isNull()) {
189 trMessage = trMessage.subs(param6);
190 }
191 if (!param7.isNull()) {
192 trMessage = trMessage.subs(param7);
193 }
194 if (!param8.isNull()) {
195 trMessage = trMessage.subs(param8);
196 }
197 if (!param9.isNull()) {
198 trMessage = trMessage.subs(param9);
199 }
200 if (!param10.isNull()) {
201 trMessage = trMessage.subs(param10);
202 }
203
204 return trMessage.toString();
205}
206
207QString TranslationContext::i18ncp(const QString &context,
208 const QString &singular,
209 const QString &plural,
210 const QString &param1,
211 const QString &param2,
212 const QString &param3,
213 const QString &param4,
214 const QString &param5,
215 const QString &param6,
216 const QString &param7,
217 const QString &param8,
218 const QString &param9,
219 const QString &param10) const
220{
221 if (context.isNull() || singular.isNull() || plural.isNull()) {
222 qWarning() << "i18ncp() needs at least three arguments";
223 return QString();
224 }
225
226 KLocalizedString trMessage =
227 ki18ndcp(m_domain.toUtf8().constData(), context.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
228
229 if (!param1.isNull()) {
230 bool ok;
231 int num = param1.toInt(&ok);
232 if (ok) {
233 trMessage = trMessage.subs(num);
234 } else {
235 trMessage = trMessage.subs(param1);
236 }
237 }
238 if (!param2.isNull()) {
239 trMessage = trMessage.subs(param2);
240 }
241 if (!param3.isNull()) {
242 trMessage = trMessage.subs(param3);
243 }
244 if (!param4.isNull()) {
245 trMessage = trMessage.subs(param4);
246 }
247 if (!param5.isNull()) {
248 trMessage = trMessage.subs(param5);
249 }
250 if (!param6.isNull()) {
251 trMessage = trMessage.subs(param6);
252 }
253 if (!param7.isNull()) {
254 trMessage = trMessage.subs(param7);
255 }
256 if (!param8.isNull()) {
257 trMessage = trMessage.subs(param8);
258 }
259 if (!param9.isNull()) {
260 trMessage = trMessage.subs(param9);
261 }
262 if (!param10.isNull()) {
263 trMessage = trMessage.subs(param10);
264 }
265
266 return trMessage.toString();
267}
268
269#include "moc_translationcontext.cpp"
QString toString() const
KLocalizedString subs(const KLocalizedString &a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
KLocalizedString KI18N_EXPORT ki18nd(const char *domain, const char *text)
KLocalizedString KI18N_EXPORT ki18ndc(const char *domain, const char *context, const char *text)
KLocalizedString KI18N_EXPORT ki18ndcp(const char *domain, const char *context, const char *singular, const char *plural)
KLocalizedString KI18N_EXPORT ki18ndp(const char *domain, const char *singular, const char *plural)
const char * constData() const const
Q_EMITQ_EMIT
bool isNull() const const
int toInt(bool *ok, int base) const const
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.