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

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

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