source: trunk/tools/linguist/shared/numerus.cpp@ 235

Last change on this file since 235 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 13.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt Linguist of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "translator.h"
43
44#include <QtCore/QCoreApplication>
45#include <QtCore/QByteArray>
46#include <QtCore/QDebug>
47#include <QtCore/QDir>
48#include <QtCore/QFile>
49#include <QtCore/QFileInfo>
50#include <QtCore/QMap>
51
52#include <private/qtranslator_p.h>
53
54QT_BEGIN_NAMESPACE
55
56static const uchar englishStyleRules[] =
57 { Q_EQ, 1 };
58static const uchar frenchStyleRules[] =
59 { Q_LEQ, 1 };
60static const uchar latvianRules[] =
61 { Q_MOD_10 | Q_EQ, 1, Q_AND, Q_MOD_100 | Q_NEQ, 11, Q_NEWRULE,
62 Q_NEQ, 0 };
63static const uchar irishStyleRules[] =
64 { Q_EQ, 1, Q_NEWRULE,
65 Q_EQ, 2 };
66static const uchar czechRules[] =
67 { Q_MOD_100 | Q_EQ, 1, Q_NEWRULE,
68 Q_MOD_100 | Q_BETWEEN, 2, 4 };
69static const uchar slovakRules[] =
70 { Q_EQ, 1, Q_NEWRULE,
71 Q_BETWEEN, 2, 4 };
72static const uchar macedonianRules[] =
73 { Q_MOD_10 | Q_EQ, 1, Q_NEWRULE,
74 Q_MOD_10 | Q_EQ, 2 };
75static const uchar lithuanianRules[] =
76 { Q_MOD_10 | Q_EQ, 1, Q_AND, Q_MOD_100 | Q_NEQ, 11, Q_NEWRULE,
77 Q_MOD_10 | Q_EQ, 2, Q_AND, Q_MOD_100 | Q_NOT_BETWEEN, 10, 19 };
78static const uchar russianStyleRules[] =
79 { Q_MOD_10 | Q_EQ, 1, Q_AND, Q_MOD_100 | Q_NEQ, 11, Q_NEWRULE,
80 Q_MOD_10 | Q_BETWEEN, 2, 4, Q_AND, Q_MOD_100 | Q_NOT_BETWEEN, 10, 19 };
81static const uchar polishRules[] =
82 { Q_EQ, 1, Q_NEWRULE,
83 Q_MOD_10 | Q_BETWEEN, 2, 4, Q_AND, Q_MOD_100 | Q_NOT_BETWEEN, 10, 19 };
84static const uchar romanianRules[] =
85 { Q_EQ, 1, Q_NEWRULE,
86 Q_EQ, 0, Q_OR, Q_MOD_100 | Q_BETWEEN, 1, 19 };
87static const uchar slovenianRules[] =
88 { Q_MOD_100 | Q_EQ, 1, Q_NEWRULE,
89 Q_MOD_100 | Q_EQ, 2, Q_NEWRULE,
90 Q_MOD_100 | Q_BETWEEN, 3, 4 };
91static const uchar malteseRules[] =
92 { Q_EQ, 1, Q_NEWRULE,
93 Q_EQ, 0, Q_OR, Q_MOD_100 | Q_BETWEEN, 1, 10, Q_NEWRULE,
94 Q_MOD_100 | Q_BETWEEN, 11, 19 };
95static const uchar welshRules[] =
96 { Q_EQ, 0, Q_NEWRULE,
97 Q_EQ, 1, Q_NEWRULE,
98 Q_BETWEEN, 2, 5, Q_NEWRULE,
99 Q_EQ, 6 };
100static const uchar arabicRules[] =
101 { Q_EQ, 0, Q_NEWRULE,
102 Q_EQ, 1, Q_NEWRULE,
103 Q_EQ, 2, Q_NEWRULE,
104 Q_MOD_100 | Q_BETWEEN, 3, 10, Q_NEWRULE,
105 Q_MOD_100 | Q_NEQ, 0 };
106
107static const char * const japaneseStyleForms[] = { "Universal Form", 0 };
108static const char * const englishStyleForms[] = { "Singular", "Plural", 0 };
109static const char * const frenchStyleForms[] = { "Singular", "Plural", 0 };
110static const char * const latvianForms[] = { "Singular", "Plural", "Nullar", 0 };
111static const char * const irishStyleForms[] = { "Singular", "Dual", "Plural", 0 };
112static const char * const czechForms[] = { "Singular", "Dual", "Plural", 0 };
113static const char * const slovakForms[] = { "Singular", "Dual", "Plural", 0 };
114static const char * const macedonianForms[] = { "Singular", "Dual", "Plural", 0 };
115static const char * const lithuanianForms[] = { "Singular", "Dual", "Plural", 0 };
116static const char * const russianStyleForms[] = { "Singular", "Dual", "Plural", 0 };
117static const char * const polishForms[] = { "Singular", "Paucal", "Plural", 0 };
118static const char * const romanianForms[] =
119 { "Singular", "Plural Form for 2 to 19", "Plural", 0 };
120static const char * const slovenianForms[] = { "Singular", "Dual", "Trial", "Plural", 0 };
121static const char * const malteseForms[] =
122 { "Singular", "Plural Form for 2 to 10", "Plural Form for 11 to 19", "Plural", 0 };
123static const char * const welshForms[] =
124 { "Nullar", "Singular", "Dual", "Sexal", "Plural", 0 };
125static const char * const arabicForms[] =
126 { "Nullar", "Singular", "Dual", "Minority Plural", "Plural", "Plural Form for 100, 200, ...", 0 };
127
128#define EOL QLocale::C
129
130static const QLocale::Language japaneseStyleLanguages[] = {
131 QLocale::Afan,
132 QLocale::Armenian,
133 QLocale::Bhutani,
134 QLocale::Bislama,
135 QLocale::Burmese,
136 QLocale::Chinese,
137 QLocale::FijiLanguage,
138 QLocale::Guarani,
139 QLocale::Hungarian,
140 QLocale::Indonesian,
141 QLocale::Japanese,
142 QLocale::Javanese,
143 QLocale::Korean,
144 QLocale::Malay,
145 QLocale::NauruLanguage,
146 QLocale::Persian,
147 QLocale::Sundanese,
148 QLocale::Thai,
149 QLocale::Tibetan,
150 QLocale::Vietnamese,
151 QLocale::Yoruba,
152 QLocale::Zhuang,
153 EOL
154};
155
156static const QLocale::Language englishStyleLanguages[] = {
157 QLocale::Abkhazian,
158 QLocale::Afar,
159 QLocale::Afrikaans,
160 QLocale::Albanian,
161 QLocale::Amharic,
162 QLocale::Assamese,
163 QLocale::Aymara,
164 QLocale::Azerbaijani,
165 QLocale::Bashkir,
166 QLocale::Basque,
167 QLocale::Bengali,
168 QLocale::Bihari,
169 // Missing: Bokmal,
170 QLocale::Bulgarian,
171 QLocale::Cambodian,
172 QLocale::Catalan,
173 QLocale::Cornish,
174 QLocale::Corsican,
175 QLocale::Danish,
176 QLocale::Dutch,
177 QLocale::English,
178 QLocale::Esperanto,
179 QLocale::Estonian,
180 QLocale::Faroese,
181 QLocale::Finnish,
182 // Missing: Friulian,
183 QLocale::Frisian,
184 QLocale::Galician,
185 QLocale::Georgian,
186 QLocale::German,
187 QLocale::Greek,
188 QLocale::Greenlandic,
189 QLocale::Gujarati,
190 QLocale::Hausa,
191 QLocale::Hebrew,
192 QLocale::Hindi,
193 QLocale::Icelandic,
194 QLocale::Interlingua,
195 QLocale::Interlingue,
196 QLocale::Italian,
197 QLocale::Kannada,
198 QLocale::Kashmiri,
199 QLocale::Kazakh,
200 QLocale::Kinyarwanda,
201 QLocale::Kirghiz,
202 QLocale::Kurdish,
203 QLocale::Kurundi,
204 QLocale::Laothian,
205 QLocale::Latin,
206 // Missing: Letzeburgesch,
207 QLocale::Lingala,
208 QLocale::Malagasy,
209 QLocale::Malayalam,
210 QLocale::Marathi,
211 QLocale::Mongolian,
212 // Missing: Nahuatl,
213 QLocale::Nepali,
214 // Missing: Northern Sotho,
215 QLocale::Norwegian,
216 QLocale::Nynorsk,
217 QLocale::Occitan,
218 QLocale::Oriya,
219 QLocale::Pashto,
220 QLocale::Portuguese,
221 QLocale::Punjabi,
222 QLocale::Quechua,
223 QLocale::RhaetoRomance,
224 QLocale::Sesotho,
225 QLocale::Setswana,
226 QLocale::Shona,
227 QLocale::Sindhi,
228 QLocale::Singhalese,
229 QLocale::Siswati,
230 QLocale::Somali,
231 QLocale::Spanish,
232 QLocale::Swahili,
233 QLocale::Swedish,
234 QLocale::Tagalog,
235 QLocale::Tajik,
236 QLocale::Tamil,
237 QLocale::Tatar,
238 QLocale::Telugu,
239 QLocale::TongaLanguage,
240 QLocale::Tsonga,
241 QLocale::Turkish,
242 QLocale::Turkmen,
243 QLocale::Twi,
244 QLocale::Uigur,
245 QLocale::Uzbek,
246 QLocale::Volapuk,
247 QLocale::Wolof,
248 QLocale::Xhosa,
249 QLocale::Yiddish,
250 QLocale::Zulu,
251 EOL
252};
253static const QLocale::Language frenchStyleLanguages[] = {
254 // keep synchronized with frenchStyleCountries
255 QLocale::Breton,
256 QLocale::French,
257 QLocale::Portuguese,
258 // Missing: Filipino,
259 QLocale::Tigrinya,
260 // Missing: Walloon
261 EOL
262};
263static const QLocale::Language latvianLanguage[] = { QLocale::Latvian, EOL };
264static const QLocale::Language irishStyleLanguages[] = {
265 QLocale::Divehi,
266 QLocale::Gaelic,
267 QLocale::Inuktitut,
268 QLocale::Inupiak,
269 QLocale::Irish,
270 QLocale::Manx,
271 QLocale::Maori,
272 // Missing: Sami,
273 QLocale::Samoan,
274 QLocale::Sanskrit,
275 EOL
276};
277static const QLocale::Language czechLanguage[] = { QLocale::Czech, EOL };
278static const QLocale::Language slovakLanguage[] = { QLocale::Slovak, EOL };
279static const QLocale::Language macedonianLanguage[] = { QLocale::Macedonian, EOL };
280static const QLocale::Language lithuanianLanguage[] = { QLocale::Lithuanian, EOL };
281static const QLocale::Language russianStyleLanguages[] = {
282 QLocale::Bosnian,
283 QLocale::Byelorussian,
284 QLocale::Croatian,
285 QLocale::Russian,
286 QLocale::Serbian,
287 QLocale::SerboCroatian,
288 QLocale::Ukrainian,
289 EOL
290};
291static const QLocale::Language polishLanguage[] = { QLocale::Polish, EOL };
292static const QLocale::Language romanianLanguages[] = {
293 QLocale::Moldavian,
294 QLocale::Romanian,
295 EOL
296};
297static const QLocale::Language slovenianLanguage[] = { QLocale::Slovenian, EOL };
298static const QLocale::Language malteseLanguage[] = { QLocale::Maltese, EOL };
299static const QLocale::Language welshLanguage[] = { QLocale::Welsh, EOL };
300static const QLocale::Language arabicLanguage[] = { QLocale::Arabic, EOL };
301
302static const QLocale::Country frenchStyleCountries[] = {
303 // keep synchronized with frenchStyleLanguages
304 QLocale::AnyCountry,
305 QLocale::AnyCountry,
306 QLocale::Brazil,
307 QLocale::AnyCountry
308};
309struct NumerusTableEntry {
310 const uchar *rules;
311 int rulesSize;
312 const char * const *forms;
313 const QLocale::Language *languages;
314 const QLocale::Country *countries;
315};
316
317static const NumerusTableEntry numerusTable[] = {
318 { 0, 0, japaneseStyleForms, japaneseStyleLanguages, 0 },
319 { englishStyleRules, sizeof(englishStyleRules), englishStyleForms, englishStyleLanguages, 0 },
320 { frenchStyleRules, sizeof(frenchStyleRules), frenchStyleForms, frenchStyleLanguages,
321 frenchStyleCountries },
322 { latvianRules, sizeof(latvianRules), latvianForms, latvianLanguage, 0 },
323 { irishStyleRules, sizeof(irishStyleRules), irishStyleForms, irishStyleLanguages, 0 },
324 { czechRules, sizeof(czechRules), czechForms, czechLanguage, 0 },
325 { slovakRules, sizeof(slovakRules), slovakForms, slovakLanguage, 0 },
326 { macedonianRules, sizeof(macedonianRules), macedonianForms, macedonianLanguage, 0 },
327 { lithuanianRules, sizeof(lithuanianRules), lithuanianForms, lithuanianLanguage, 0 },
328 { russianStyleRules, sizeof(russianStyleRules), russianStyleForms, russianStyleLanguages, 0 },
329 { polishRules, sizeof(polishRules), polishForms, polishLanguage, 0 },
330 { romanianRules, sizeof(romanianRules), romanianForms, romanianLanguages, 0 },
331 { slovenianRules, sizeof(slovenianRules), slovenianForms, slovenianLanguage, 0 },
332 { malteseRules, sizeof(malteseRules), malteseForms, malteseLanguage, 0 },
333 { welshRules, sizeof(welshRules), welshForms, welshLanguage, 0 },
334 { arabicRules, sizeof(arabicRules), arabicForms, arabicLanguage, 0 }
335};
336
337static const int NumerusTableSize = sizeof(numerusTable) / sizeof(numerusTable[0]);
338
339// magic number for the file
340static const int MagicLength = 16;
341static const uchar magic[MagicLength] = {
342 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
343 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd
344};
345
346bool getNumerusInfo(QLocale::Language language, QLocale::Country country,
347 QByteArray *rules, QStringList *forms)
348{
349 while (true) {
350 for (int i = 0; i < NumerusTableSize; ++i) {
351 const NumerusTableEntry &entry = numerusTable[i];
352 for (int j = 0; entry.languages[j] != EOL; ++j) {
353 if (entry.languages[j] == language
354 && ((!entry.countries && country == QLocale::AnyCountry)
355 || (entry.countries && entry.countries[j] == country))) {
356 if (rules) {
357 *rules = QByteArray::fromRawData(reinterpret_cast<const char *>(entry.rules),
358 entry.rulesSize);
359 }
360 if (forms) {
361 forms->clear();
362 for (int k = 0; entry.forms[k]; ++k)
363 forms->append(QLatin1String(entry.forms[k]));
364 }
365 return true;
366 }
367 }
368 }
369
370 if (country == QLocale::AnyCountry)
371 break;
372 country = QLocale::AnyCountry;
373 }
374 return false;
375}
376
377QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.