Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <rtl/ustring.hxx>
21 : #include <rtl/string.hxx>
22 : #include <rtl/ustrbuf.hxx>
23 : #include <rtl/strbuf.hxx>
24 :
25 : #include "i18npool/mslangid.hxx"
26 :
27 : // =======================================================================
28 :
29 : struct IsoLangEngEntry
30 : {
31 : LanguageType mnLang;
32 : sal_Char maCountry[3];
33 : };
34 :
35 : struct IsoLangNoneStdEntry
36 : {
37 : LanguageType mnLang;
38 : sal_Char maLangStr[4];
39 : sal_Char maCountry[9];
40 : };
41 :
42 : struct IsoLangOtherEntry
43 : {
44 : LanguageType mnLang;
45 : const sal_Char* mpLangStr;
46 : };
47 :
48 : // -----------------------------------------------------------------------
49 :
50 : // Entries for languages are lower case, for countries upper case, as
51 : // recommended by rfc4646 (obsoletes rfc3066 (obsoletes rfc1766)).
52 : // convertIsoNamesToLanguage() is case insensitive
53 : //
54 : // Sort order: Most used first.
55 : //
56 : // The default entry for a LangID <-> ISO mapping has to be first. For
57 : // conversion of legacy mappings one LangID can map to multiple ISO codes, and
58 : // one ISO code combination can map to multiple LangIDs. For compatibility with
59 : // already existing calls it can also be a sequence as follows:
60 :
61 : // LANGUAGE_ENGLISH, "en", ""
62 : // LANGUAGE_ENGLISH_US, "en", "US"
63 :
64 : // Here, in a convertIsoNamesToLanguage() call "en-US" is converted to
65 : // LANGUAGE_ENGLISH_US and "en" is converted to LANGUAGE_ENGLISH. A call with
66 : // "en-ZZ" (not in table) would result in LANGUAGE_ENGLISH because the first
67 : // entry matching the language and not having a country is returned, regardless
68 : // of whether being sorted before or after other entries of the same language
69 : // with some country. To obtain a _locale_ (not language only) in the order
70 : // given, convertLocaleToLanguageWithFallback() must be called.
71 :
72 : // If the sequence instead was
73 :
74 : // LANGUAGE_ENGLISH_US, "en", "US"
75 : // LANGUAGE_ENGLISH, "en", ""
76 :
77 : // in a convertIsoNamesToLanguage() call "en-US" is still converted to
78 : // LANGUAGE_ENGLISH_US, but "en" is _also_ converted to LANGUAGE_ENGLISH_US
79 : // because no country was passed and it is the first entry to match the
80 : // language, see code. A call with "en-ZZ" (not in table) would still result in
81 : // LANGUAGE_ENGLISH.
82 :
83 : /* erAck: 2007-07-05T20:01+0200 TODO: The entire suite's "primary language
84 : * only" usage and locale fall back should be cleaned up and made consistent. I
85 : * strongly doubt that most callers exactly expect the behavior described.
86 : * Currently these primary LangIDs are used literally in OOo code:
87 : * LANGUAGE_ENGLISH LANGUAGE_CHINESE LANGUAGE_MALAY
88 : * LANGUAGE_AZERI LANGUAGE_URDU LANGUAGE_KASHMIRI
89 : */
90 :
91 : static MsLangId::IsoLangEntry const aImplIsoLangEntries[] =
92 : {
93 : // MS-LANGID codes ISO639-1/2/3 ISO3166
94 : { LANGUAGE_ENGLISH, "en", "" },
95 : { LANGUAGE_ENGLISH_US, "en", "US" },
96 : { LANGUAGE_ENGLISH_UK, "en", "GB" },
97 : { LANGUAGE_ENGLISH_AUS, "en", "AU" },
98 : { LANGUAGE_ENGLISH_CAN, "en", "CA" },
99 : { LANGUAGE_FRENCH, "fr", "FR" },
100 : { LANGUAGE_FRENCH, "fr", "" },
101 : { LANGUAGE_GERMAN, "de", "DE" },
102 : { LANGUAGE_ITALIAN, "it", "IT" },
103 : { LANGUAGE_DUTCH, "nl", "NL" },
104 : { LANGUAGE_SPANISH_MODERN, "es", "ES" },
105 : { LANGUAGE_SPANISH_DATED, "es", "ES" },
106 : { LANGUAGE_PORTUGUESE, "pt", "PT" },
107 : { LANGUAGE_PORTUGUESE_BRAZILIAN, "pt", "BR" },
108 : { LANGUAGE_DANISH, "da", "DK" },
109 : { LANGUAGE_GREEK, "el", "GR" },
110 : { LANGUAGE_CHINESE, "zh", "" },
111 : { LANGUAGE_CHINESE_SIMPLIFIED, "zh", "CN" },
112 : { LANGUAGE_CHINESE_TRADITIONAL, "zh", "TW" },
113 : { LANGUAGE_CHINESE_HONGKONG, "zh", "HK" },
114 : { LANGUAGE_CHINESE_SINGAPORE, "zh", "SG" },
115 : { LANGUAGE_CHINESE_MACAU, "zh", "MO" },
116 : { LANGUAGE_ENGLISH_HONG_KONG_SAR, "en", "HK" },
117 : { LANGUAGE_JAPANESE, "ja", "JP" },
118 : { LANGUAGE_KOREAN, "ko", "KR" },
119 : { LANGUAGE_KOREAN_JOHAB, "ko", "KR" },
120 : { LANGUAGE_USER_KOREAN_NORTH, "ko", "KP" },
121 : { LANGUAGE_SWEDISH, "sv", "SE" },
122 : { LANGUAGE_SWEDISH_FINLAND, "sv", "FI" },
123 : { LANGUAGE_FINNISH, "fi", "FI" },
124 : { LANGUAGE_RUSSIAN, "ru", "RU" },
125 : { LANGUAGE_TATAR, "tt", "RU" },
126 : { LANGUAGE_ENGLISH_NZ, "en", "NZ" },
127 : { LANGUAGE_ENGLISH_EIRE, "en", "IE" },
128 : { LANGUAGE_DUTCH_BELGIAN, "nl", "BE" },
129 : { LANGUAGE_FRENCH_BELGIAN, "fr", "BE" },
130 : { LANGUAGE_FRENCH_CANADIAN, "fr", "CA" },
131 : { LANGUAGE_FRENCH_SWISS, "fr", "CH" },
132 : { LANGUAGE_GERMAN_SWISS, "de", "CH" },
133 : { LANGUAGE_GERMAN_AUSTRIAN, "de", "AT" },
134 : { LANGUAGE_ITALIAN_SWISS, "it", "CH" },
135 : { LANGUAGE_ALBANIAN, "sq", "AL" },
136 : { LANGUAGE_ARABIC_SAUDI_ARABIA, "ar", "SA" },
137 : { LANGUAGE_ARABIC_EGYPT, "ar", "EG" },
138 : { LANGUAGE_ARABIC_UAE, "ar", "AE" },
139 : { LANGUAGE_ARABIC_IRAQ, "ar", "IQ" },
140 : { LANGUAGE_ARABIC_LIBYA, "ar", "LY" },
141 : { LANGUAGE_ARABIC_ALGERIA, "ar", "DZ" },
142 : { LANGUAGE_ARABIC_MOROCCO, "ar", "MA" },
143 : { LANGUAGE_ARABIC_TUNISIA, "ar", "TN" },
144 : { LANGUAGE_ARABIC_OMAN, "ar", "OM" },
145 : { LANGUAGE_ARABIC_YEMEN, "ar", "YE" },
146 : { LANGUAGE_ARABIC_SYRIA, "ar", "SY" },
147 : { LANGUAGE_ARABIC_JORDAN, "ar", "JO" },
148 : { LANGUAGE_ARABIC_LEBANON, "ar", "LB" },
149 : { LANGUAGE_ARABIC_KUWAIT, "ar", "KW" },
150 : { LANGUAGE_ARABIC_BAHRAIN, "ar", "BH" },
151 : { LANGUAGE_ARABIC_QATAR, "ar", "QA" },
152 : { LANGUAGE_USER_ARABIC_CHAD, "ar", "TD" },
153 : { LANGUAGE_USER_ARABIC_COMOROS, "ar", "KM" },
154 : { LANGUAGE_USER_ARABIC_DJIBOUTI, "ar", "DJ" },
155 : { LANGUAGE_USER_ARABIC_ERITREA, "ar", "ER" },
156 : { LANGUAGE_USER_ARABIC_ISRAEL, "ar", "IL" },
157 : { LANGUAGE_USER_ARABIC_MAURITANIA, "ar", "MR" },
158 : { LANGUAGE_USER_ARABIC_PALESTINE, "ar", "PS" },
159 : { LANGUAGE_USER_ARABIC_SOMALIA, "ar", "SO" },
160 : { LANGUAGE_USER_ARABIC_SUDAN, "ar", "SD" },
161 : { LANGUAGE_ARABIC_PRIMARY_ONLY, "ar", "" },
162 : { LANGUAGE_BASQUE, "eu", "" },
163 : { LANGUAGE_BULGARIAN, "bg", "BG" },
164 : { LANGUAGE_CZECH, "cs", "CZ" },
165 : { LANGUAGE_CZECH, "cz", "" },
166 : { LANGUAGE_ENGLISH_JAMAICA, "en", "JM" },
167 : { LANGUAGE_ENGLISH_CARRIBEAN, "en", "BS" }, // not 100%, because AG is Bahamas
168 : { LANGUAGE_ENGLISH_BELIZE, "en", "BZ" },
169 : { LANGUAGE_ENGLISH_TRINIDAD, "en", "TT" },
170 : { LANGUAGE_ENGLISH_ZIMBABWE, "en", "ZW" },
171 : { LANGUAGE_ENGLISH_INDONESIA, "en", "ID" },
172 : { LANGUAGE_ESTONIAN, "et", "EE" },
173 : { LANGUAGE_FAEROESE, "fo", "FO" },
174 : { LANGUAGE_FARSI, "fa", "IR" },
175 : { LANGUAGE_FRENCH_LUXEMBOURG, "fr", "LU" },
176 : { LANGUAGE_FRENCH_MONACO, "fr", "MC" },
177 : { LANGUAGE_GERMAN_LUXEMBOURG, "de", "LU" },
178 : { LANGUAGE_GERMAN_LIECHTENSTEIN, "de", "LI" },
179 : { LANGUAGE_HEBREW, "he", "IL" }, // new: old was "iw"
180 : { LANGUAGE_HEBREW, "iw", "IL" }, // old: new is "he"
181 : { LANGUAGE_HUNGARIAN, "hu", "HU" },
182 : { LANGUAGE_ICELANDIC, "is", "IS" },
183 : { LANGUAGE_INDONESIAN, "id", "ID" }, // new: old was "in"
184 : { LANGUAGE_INDONESIAN, "in", "ID" }, // old: new is "id"
185 : { LANGUAGE_NORWEGIAN, "no", "NO" },
186 : { LANGUAGE_NORWEGIAN_BOKMAL, "nb", "NO" },
187 : { LANGUAGE_NORWEGIAN_NYNORSK, "nn", "NO" },
188 : { LANGUAGE_POLISH, "pl", "PL" },
189 : { LANGUAGE_RHAETO_ROMAN, "rm", "CH" },
190 : { LANGUAGE_ROMANIAN, "ro", "RO" },
191 : { LANGUAGE_ROMANIAN_MOLDOVA, "ro", "MD" },
192 : { LANGUAGE_SLOVAK, "sk", "SK" },
193 : { LANGUAGE_SLOVENIAN, "sl", "SI" },
194 : { LANGUAGE_SPANISH_MEXICAN, "es", "MX" },
195 : { LANGUAGE_SPANISH_GUATEMALA, "es", "GT" },
196 : { LANGUAGE_SPANISH_COSTARICA, "es", "CR" },
197 : { LANGUAGE_SPANISH_PANAMA, "es", "PA" },
198 : { LANGUAGE_SPANISH_DOMINICAN_REPUBLIC, "es", "DO" },
199 : { LANGUAGE_SPANISH_VENEZUELA, "es", "VE" },
200 : { LANGUAGE_SPANISH_COLOMBIA, "es", "CO" },
201 : { LANGUAGE_SPANISH_PERU, "es", "PE" },
202 : { LANGUAGE_SPANISH_ARGENTINA, "es", "AR" },
203 : { LANGUAGE_SPANISH_ECUADOR, "es", "EC" },
204 : { LANGUAGE_SPANISH_CHILE, "es", "CL" },
205 : { LANGUAGE_SPANISH_URUGUAY, "es", "UY" },
206 : { LANGUAGE_SPANISH_PARAGUAY, "es", "PY" },
207 : { LANGUAGE_SPANISH_BOLIVIA, "es", "BO" },
208 : { LANGUAGE_SPANISH_EL_SALVADOR, "es", "SV" },
209 : { LANGUAGE_SPANISH_HONDURAS, "es", "HN" },
210 : { LANGUAGE_SPANISH_NICARAGUA, "es", "NI" },
211 : { LANGUAGE_SPANISH_PUERTO_RICO, "es", "PR" },
212 : { LANGUAGE_SPANISH_UNITED_STATES, "es", "US" },
213 : { LANGUAGE_SPANISH_LATIN_AMERICA, "es", "" },
214 : { LANGUAGE_TURKISH, "tr", "TR" },
215 : { LANGUAGE_UKRAINIAN, "uk", "UA" },
216 : { LANGUAGE_VIETNAMESE, "vi", "VN" },
217 : { LANGUAGE_LATVIAN, "lv", "LV" },
218 : { LANGUAGE_MACEDONIAN, "mk", "MK" },
219 : { LANGUAGE_MALAY, "ms", "" },
220 : { LANGUAGE_MALAY_MALAYSIA, "ms", "MY" },
221 : { LANGUAGE_MALAY_BRUNEI_DARUSSALAM, "ms", "BN" },
222 : { LANGUAGE_ENGLISH_MALAYSIA, "en", "MY" },
223 : { LANGUAGE_THAI, "th", "TH" },
224 : { LANGUAGE_LITHUANIAN, "lt", "LT" },
225 : { LANGUAGE_LITHUANIAN_CLASSIC, "lt", "LT" },
226 : { LANGUAGE_CROATIAN, "hr", "HR" }, // Croatian in Croatia
227 : { LANGUAGE_CROATIAN_BOSNIA_HERZEGOVINA, "hr", "BA" },
228 : { LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA, "bs", "BA" },
229 : // { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_AND_HERZEGOVINA, "bs", "BA" }, // script codes not supported yet
230 : { LANGUAGE_USER_SERBIAN_CYRILLIC_SERBIA, "sr", "RS" }, // Serbian Cyrillic in Serbia
231 : { LANGUAGE_SERBIAN_CYRILLIC, "sr", "YU" }, // legacy Serbian Cyrillic in Serbia and Montenegro (former Yugoslavia); kludge, needed to be sr_CS instead, sr_CS not supported by ICU 2.6 (3.4 does)
232 : { LANGUAGE_SERBIAN_CYRILLIC, "sr", "CS" }, // alias to be able to integrate localizations, rsc needs it
233 : { LANGUAGE_USER_SERBIAN_CYRILLIC_MONTENEGRO, "sr", "ME" },
234 : { LANGUAGE_SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "sr", "BA" },
235 : { LANGUAGE_SERBIAN, "sr", "" }, // SERBIAN is only LID, MS-LCID not defined (was dupe of CROATIAN)
236 : { LANGUAGE_USER_SERBIAN_LATIN_SERBIA, "sh", "RS" }, // Serbian Latin in Serbia; kludge, needed to be sr_Latn_RS instead, script codes not supported yet
237 : { LANGUAGE_SERBIAN_LATIN, "sh", "YU" }, // legacy Serbian Latin in Serbia and Montenegro (former Yugoslavia); kludge, needed to be sr_Latn_CS instead, script codes not supported yet
238 : { LANGUAGE_SERBIAN_LATIN, "sh", "CS" }, // Serbian Latin in Serbia and Montenegro; kludge, needed to be sr_Latn_CS instead, script codes not supported yet
239 : { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO, "sh", "ME" }, // Serbian Latin in Montenegro; kludge, needed to be sr_Latn_ME instead, script codes not supported yet
240 : { LANGUAGE_SERBIAN_LATIN_BOSNIA_HERZEGOVINA, "sh", "BA" },
241 : { LANGUAGE_SERBIAN_LATIN_NEUTRAL, "sh", "" }, // kludge, needed to be sr_Latn instead, script codes not supported yet
242 : { LANGUAGE_ARMENIAN, "hy", "AM" },
243 : { LANGUAGE_AZERI, "az", "" },
244 : { LANGUAGE_AZERI_LATIN, "az", "AZ" },
245 : // { LANGUAGE_AZERI_CYRILLIC, "az", "AZ" }, // script codes not supported yet
246 : { LANGUAGE_UZBEK_LATIN, "uz", "UZ" },
247 : // { LANGUAGE_UZBEK_CYRILLIC, "uz", "UZ" }, // script codes not supported yet
248 : { LANGUAGE_BENGALI_BANGLADESH, "bn", "BD" },
249 : { LANGUAGE_BENGALI, "bn", "IN" },
250 : { LANGUAGE_BURMESE, "my", "MM" },
251 : { LANGUAGE_KAZAK, "kk", "KZ" },
252 : { LANGUAGE_ENGLISH_INDIA, "en", "IN" },
253 : { LANGUAGE_URDU, "ur", "" },
254 : { LANGUAGE_URDU_INDIA, "ur", "IN" },
255 : { LANGUAGE_URDU_PAKISTAN, "ur", "PK" },
256 : { LANGUAGE_HINDI, "hi", "IN" },
257 : { LANGUAGE_GUJARATI, "gu", "IN" },
258 : { LANGUAGE_KANNADA, "kn", "IN" },
259 : { LANGUAGE_ASSAMESE, "as", "IN" },
260 : { LANGUAGE_KASHMIRI, "ks", "" },
261 : { LANGUAGE_KASHMIRI_INDIA, "ks", "IN" },
262 : { LANGUAGE_MALAYALAM, "ml", "IN" },
263 : { LANGUAGE_MANIPURI, "mni", "IN" },
264 : { LANGUAGE_MARATHI, "mr", "IN" },
265 : { LANGUAGE_KONKANI, "kok", "IN" },
266 : { LANGUAGE_NEPALI, "ne", "NP" },
267 : { LANGUAGE_NEPALI_INDIA, "ne", "IN" },
268 : { LANGUAGE_ORIYA, "or", "IN" },
269 : { LANGUAGE_PUNJABI, "pa", "IN" },
270 : { LANGUAGE_SANSKRIT, "sa", "IN" },
271 : { LANGUAGE_SINDHI, "sd", "IN" },
272 : { LANGUAGE_TAMIL, "ta", "IN" },
273 : { LANGUAGE_TELUGU, "te", "IN" },
274 : { LANGUAGE_PUNJABI_PAKISTAN, "lah", "PK" }, // preferring "lah" over "pa" for Western Punjabi, see http://www.ethnologue.com/show_language.asp?code=PNB
275 : { LANGUAGE_PUNJABI_PAKISTAN, "pa", "PK" },
276 : { LANGUAGE_SINDHI_PAKISTAN, "sd", "PK" },
277 : { LANGUAGE_BELARUSIAN, "be", "BY" },
278 : { LANGUAGE_CATALAN, "ca", "ES" }, // Spain (default)
279 : { LANGUAGE_CATALAN, "ca", "AD" }, // Andorra
280 : { LANGUAGE_USER_CATALAN_VALENCIAN, "ca", "XV" }, // XV: ISO 3166 user-assigned; workaround for UI localization only, do not use in document content!
281 : { LANGUAGE_CATALAN, "qcv", "ES" }, // qcv: ISO 639-3 reserved-for-local-use; UI localization quirk only, do not use in document content!
282 : // { LANGUAGE_USER_CATALAN_VALENCIAN, "ca", "ES" }, // In case MS format files escaped into the wild, map them back.
283 : { LANGUAGE_FRENCH_CAMEROON, "fr", "CM" },
284 : { LANGUAGE_FRENCH_COTE_D_IVOIRE, "fr", "CI" },
285 : { LANGUAGE_FRENCH_MALI, "fr", "ML" },
286 : { LANGUAGE_FRENCH_SENEGAL, "fr", "SN" },
287 : { LANGUAGE_FRENCH_ZAIRE, "fr", "CD" }, // Democratic Republic Of Congo
288 : { LANGUAGE_FRENCH_MOROCCO, "fr", "MA" },
289 : { LANGUAGE_FRENCH_REUNION, "fr", "RE" },
290 : { LANGUAGE_FRENCH_NORTH_AFRICA, "fr", "" },
291 : { LANGUAGE_FRENCH_WEST_INDIES, "fr", "" }, // unknown ISO country code
292 : { LANGUAGE_FRISIAN_NETHERLANDS, "fy", "NL" },
293 : { LANGUAGE_GAELIC_IRELAND, "ga", "IE" },
294 : { LANGUAGE_GAELIC_SCOTLAND, "gd", "GB" },
295 : { LANGUAGE_GALICIAN, "gl", "ES" },
296 : { LANGUAGE_GEORGIAN, "ka", "GE" },
297 : { LANGUAGE_KHMER, "km", "KH" },
298 : { LANGUAGE_KIRGHIZ, "ky", "KG" },
299 : { LANGUAGE_LAO, "lo", "LA" },
300 : { LANGUAGE_MALTESE, "mt", "MT" },
301 : { LANGUAGE_MONGOLIAN, "mn", "MN" }, // Cyrillic script
302 : { LANGUAGE_MONGOLIAN_MONGOLIAN, "mn", "MN" },
303 : { LANGUAGE_RUSSIAN_MOLDOVA, "mo", "MD" },
304 : { LANGUAGE_SWAHILI, "sw", "KE" },
305 : { LANGUAGE_USER_SWAHILI_TANZANIA, "sw", "TZ" },
306 : { LANGUAGE_TAJIK, "tg", "TJ" },
307 : { LANGUAGE_TIBETAN, "bo", "CN" }, // CN politically correct?
308 : { LANGUAGE_DZONGKHA, "dz", "BT" },
309 : { LANGUAGE_TURKMEN, "tk", "TM" },
310 : { LANGUAGE_WELSH, "cy", "GB" },
311 : { LANGUAGE_SESOTHO, "st", "ZA" },
312 : { LANGUAGE_SEPEDI, "nso", "ZA" },
313 : { LANGUAGE_SEPEDI, "ns", "ZA" }, // fake "ns" for compatibility with existing OOo1.1.x localization to be able to read those documents
314 : { LANGUAGE_TSONGA, "ts", "ZA" },
315 : { LANGUAGE_TSWANA, "tn", "ZA" },
316 : { LANGUAGE_ENGLISH_SAFRICA, "en", "ZA" },
317 : { LANGUAGE_AFRIKAANS, "af", "ZA" },
318 : { LANGUAGE_VENDA, "ve", "ZA" }, // default 639-1
319 : { LANGUAGE_VENDA, "ven", "ZA" }, // 639-2 may have been used temporarily since 2004-07-23
320 : { LANGUAGE_XHOSA, "xh", "ZA" },
321 : { LANGUAGE_ZULU, "zu", "ZA" },
322 : { LANGUAGE_QUECHUA_ECUADOR, "qu", "EC" },
323 : { LANGUAGE_QUECHUA_PERU, "qu", "PE" },
324 : { LANGUAGE_QUECHUA_BOLIVIA, "qu", "BO" }, // macro: quh-BO, qul-BO
325 : { LANGUAGE_PASHTO, "ps", "AF" },
326 : { LANGUAGE_OROMO, "om", "ET" },
327 : { LANGUAGE_DHIVEHI, "dv", "MV" },
328 : { LANGUAGE_UIGHUR_CHINA, "ug", "CN" },
329 : { LANGUAGE_TIGRIGNA_ETHIOPIA, "ti", "ET" },
330 : { LANGUAGE_TIGRIGNA_ERITREA, "ti", "ER" },
331 : { LANGUAGE_AMHARIC_ETHIOPIA, "am", "ET" },
332 : { LANGUAGE_GUARANI_PARAGUAY, "gug", "PY" },
333 : { LANGUAGE_HAWAIIAN_UNITED_STATES, "haw", "US" },
334 : { LANGUAGE_EDO, "bin", "NG" },
335 : { LANGUAGE_FULFULDE_NIGERIA, "ff", "NG" },
336 : { LANGUAGE_HAUSA_NIGERIA, "ha", "NG" },
337 : { LANGUAGE_USER_HAUSA_GHANA, "ha", "GH" },
338 : { LANGUAGE_IGBO_NIGERIA, "ig", "NG" },
339 : { LANGUAGE_KANURI_NIGERIA, "kr", "NG" },
340 : { LANGUAGE_YORUBA, "yo", "NG" },
341 : { LANGUAGE_SOMALI, "so", "SO" },
342 : { LANGUAGE_PAPIAMENTU, "pap", "AN" },
343 : { LANGUAGE_USER_PAPIAMENTU_ARUBA, "pap", "AW" },
344 : { LANGUAGE_USER_PAPIAMENTU_CURACAO, "pap", "CW" },
345 : { LANGUAGE_USER_PAPIAMENTU_BONAIRE, "pap", "BQ" },
346 : { LANGUAGE_ENGLISH_SINGAPORE, "en", "SG" },
347 : { LANGUAGE_USER_YIDDISH_US, "yi", "US" },
348 : { LANGUAGE_YIDDISH, "yi", "IL" }, // new: old was "ji"
349 : { LANGUAGE_YIDDISH, "ji", "IL" }, // old: new is "yi"
350 : { LANGUAGE_SYRIAC, "syr", "TR" }, // "TR" according to http://www.ethnologue.com/show_language.asp?code=SYC
351 : { LANGUAGE_SINHALESE_SRI_LANKA, "si", "LK" },
352 : { LANGUAGE_CHEROKEE_UNITED_STATES, "chr", "US" },
353 : { LANGUAGE_INUKTITUT_LATIN_CANADA, "iu", "CA" },
354 : // { LANGUAGE_INUKTITUT_SYLLABICS_CANADA, "iu", "CA" }, // script codes not supported yet
355 : { LANGUAGE_SAMI_NORTHERN_NORWAY, "se", "NO" },
356 : { LANGUAGE_SAMI_INARI, "smn", "FI" },
357 : { LANGUAGE_SAMI_LULE_NORWAY, "smj", "NO" },
358 : { LANGUAGE_SAMI_LULE_SWEDEN, "smj", "SE" },
359 : { LANGUAGE_SAMI_NORTHERN_FINLAND, "se", "FI" },
360 : { LANGUAGE_SAMI_NORTHERN_SWEDEN, "se", "SE" },
361 : { LANGUAGE_SAMI_SKOLT, "sms", "FI" },
362 : { LANGUAGE_SAMI_SOUTHERN_NORWAY, "sma", "NO" },
363 : { LANGUAGE_SAMI_SOUTHERN_SWEDEN, "sma", "SE" },
364 : { LANGUAGE_USER_SAMI_KILDIN_RUSSIA, "sjd", "RU" },
365 : { LANGUAGE_MAPUDUNGUN_CHILE, "arn", "CL" },
366 : { LANGUAGE_CORSICAN_FRANCE, "co", "FR" },
367 : { LANGUAGE_ALSATIAN_FRANCE, "gsw", "FR" }, // in fact 'gsw' is Schwyzerduetsch (Swiss German), which is a dialect of Alemannic German, as is Alsatian. They aren't distinct languages and share this code.
368 : { LANGUAGE_YAKUT_RUSSIA, "sah", "RU" },
369 : { LANGUAGE_MOHAWK_CANADA, "moh", "CA" },
370 : { LANGUAGE_BASHKIR_RUSSIA, "ba", "RU" },
371 : { LANGUAGE_KICHE_GUATEMALA, "qut", "GT" },
372 : { LANGUAGE_DARI_AFGHANISTAN, "gbz", "AF" },
373 : { LANGUAGE_WOLOF_SENEGAL, "wo", "SN" },
374 : { LANGUAGE_FILIPINO, "fil", "PH" },
375 : { LANGUAGE_USER_TAGALOG, "tl", "PH" },
376 : { LANGUAGE_ENGLISH_PHILIPPINES, "en", "PH" },
377 : // { LANGUAGE_IBIBIO_NIGERIA, "nic", "NG" }, // ISO "nic" is only a collective language code
378 : { LANGUAGE_YI, "ii", "CN" },
379 : { LANGUAGE_TAMAZIGHT_LATIN, "kab", "DZ" }, // In practice Kabyle is the language used for this
380 : { LANGUAGE_OBSOLETE_USER_KABYLE, "kab", "DZ" },
381 : { LANGUAGE_TAMAZIGHT_LATIN, "ber", "DZ" }, // In practice Algeria has standardized on Kabyle as the member of the "ber" collective which gets used there.
382 : { LANGUAGE_TAMAZIGHT_TIFINAGH, "ber", "MA" }, // Morocco is officially using Tifinagh for its Berber languages so store it to distinguish explicitly from LANGUAGE_TAMAZIGHT_LATIN, even though as a collective language its not of much use
383 : // { LANGUAGE_TAMAZIGHT_ARABIC, "ber", "" }, // ISO "ber" only collective!
384 : { LANGUAGE_LATIN, "la", "VA" },
385 : { LANGUAGE_OBSOLETE_USER_LATIN, "la", "VA" },
386 : { LANGUAGE_USER_ESPERANTO, "eo", "" },
387 : { LANGUAGE_USER_INTERLINGUA, "ia", "" },
388 : { LANGUAGE_MAORI_NEW_ZEALAND, "mi", "NZ" },
389 : { LANGUAGE_OBSOLETE_USER_MAORI, "mi", "NZ" },
390 : { LANGUAGE_KINYARWANDA_RWANDA, "rw", "RW" },
391 : { LANGUAGE_OBSOLETE_USER_KINYARWANDA, "rw", "RW" },
392 : { LANGUAGE_UPPER_SORBIAN_GERMANY, "hsb", "DE" }, // MS maps this to 'wen-DE', which is nonsense. 'wen' is a collective language code, 'WEN' is a SIL code, see http://www.ethnologue.com/14/show_iso639.asp?code=wen and http://www.ethnologue.com/14/show_language.asp?code=WEN
393 : { LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN,"hsb", "DE" },
394 : { LANGUAGE_LOWER_SORBIAN_GERMANY, "dsb", "DE" }, // MS maps this to 'wee-DE', which is nonsense. 'WEE' is a SIL code, see http://www.ethnologue.com/14/show_language.asp?code=WEE
395 : { LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN,"dsb", "DE" },
396 : { LANGUAGE_OCCITAN_FRANCE, "oc", "FR" },
397 : { LANGUAGE_OBSOLETE_USER_OCCITAN, "oc", "FR" },
398 : { LANGUAGE_USER_KURDISH_TURKEY, "ku", "TR" },
399 : { LANGUAGE_USER_KURDISH_SYRIA, "ku", "SY" },
400 : { LANGUAGE_USER_KURDISH_IRAQ, "ku", "IQ" },
401 : { LANGUAGE_USER_KURDISH_IRAN, "ku", "IR" },
402 : { LANGUAGE_USER_SARDINIAN, "sc", "IT" }, // macrolanguage code
403 : { LANGUAGE_USER_SARDINIAN_CAMPIDANESE, "sro", "IT" },
404 : { LANGUAGE_USER_SARDINIAN_GALLURESE, "sdn", "IT" },
405 : { LANGUAGE_USER_SARDINIAN_LOGUDORESE, "src", "IT" },
406 : { LANGUAGE_USER_SARDINIAN_SASSARESE, "sdc", "IT" },
407 : { LANGUAGE_BRETON_FRANCE, "br", "FR" },
408 : { LANGUAGE_OBSOLETE_USER_BRETON, "br", "FR" },
409 : { LANGUAGE_KALAALLISUT_GREENLAND, "kl", "GL" },
410 : { LANGUAGE_OBSOLETE_USER_KALAALLISUT, "kl", "GL" },
411 : { LANGUAGE_USER_SWAZI, "ss", "ZA" },
412 : { LANGUAGE_USER_NDEBELE_SOUTH, "nr", "ZA" },
413 : { LANGUAGE_USER_TSWANA_BOTSWANA, "tn", "BW" },
414 : { LANGUAGE_USER_MOORE, "mos", "BF" },
415 : { LANGUAGE_USER_BAMBARA, "bm", "ML" },
416 : { LANGUAGE_USER_AKAN, "ak", "GH" },
417 : { LANGUAGE_LUXEMBOURGISH_LUXEMBOURG, "lb", "LU" },
418 : { LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH, "lb", "LU" },
419 : { LANGUAGE_USER_FRIULIAN, "fur", "IT" },
420 : { LANGUAGE_USER_FIJIAN, "fj", "FJ" },
421 : { LANGUAGE_USER_AFRIKAANS_NAMIBIA, "af", "NA" },
422 : { LANGUAGE_USER_ENGLISH_NAMIBIA, "en", "NA" },
423 : { LANGUAGE_USER_WALLOON, "wa", "BE" },
424 : { LANGUAGE_USER_COPTIC, "cop", "EG" },
425 : { LANGUAGE_USER_GASCON, "gsc", "FR" },
426 : { LANGUAGE_USER_GERMAN_BELGIUM, "de", "BE" },
427 : { LANGUAGE_USER_CHUVASH, "cv", "RU" },
428 : { LANGUAGE_USER_EWE_GHANA, "ee", "GH" },
429 : { LANGUAGE_USER_ENGLISH_GHANA, "en", "GH" },
430 : { LANGUAGE_USER_SANGO, "sg", "CF" },
431 : { LANGUAGE_USER_GANDA, "lg", "UG" },
432 : { LANGUAGE_USER_LINGALA_DRCONGO, "ln", "CD" },
433 : { LANGUAGE_USER_LOW_GERMAN, "nds", "DE" },
434 : { LANGUAGE_USER_HILIGAYNON, "hil", "PH" },
435 : { LANGUAGE_USER_ENGLISH_MALAWI, "en", "MW" }, /* en default for MW */
436 : { LANGUAGE_USER_NYANJA, "ny", "MW" },
437 : { LANGUAGE_USER_KASHUBIAN, "csb", "PL" },
438 : { LANGUAGE_USER_SPANISH_CUBA, "es", "CU" },
439 : { LANGUAGE_USER_QUECHUA_NORTH_BOLIVIA, "qul", "BO" },
440 : { LANGUAGE_USER_QUECHUA_SOUTH_BOLIVIA, "quh", "BO" },
441 : { LANGUAGE_USER_BODO_INDIA, "brx", "IN" },
442 : { LANGUAGE_USER_DOGRI_INDIA, "dgo", "IN" },
443 : { LANGUAGE_USER_MAITHILI_INDIA, "mai", "IN" },
444 : { LANGUAGE_USER_SANTALI_INDIA, "sat", "IN" },
445 : { LANGUAGE_USER_TETUN, "tet", "ID" },
446 : { LANGUAGE_USER_TETUN_TIMOR_LESTE, "tet", "TL" },
447 : { LANGUAGE_USER_TOK_PISIN, "tpi", "PG" },
448 : { LANGUAGE_USER_SHUSWAP, "shs", "CA" },
449 : { LANGUAGE_USER_ANCIENT_GREEK, "grc", "GR" },
450 : { LANGUAGE_USER_ASTURIAN, "ast", "ES" },
451 : { LANGUAGE_USER_LATGALIAN, "ltg", "LV" },
452 : { LANGUAGE_USER_MAORE, "swb", "YT" },
453 : { LANGUAGE_USER_BUSHI, "buc", "YT" },
454 : { LANGUAGE_USER_TAHITIAN, "ty", "PF" },
455 : { LANGUAGE_USER_MALAGASY_PLATEAU, "plt", "MG" },
456 : { LANGUAGE_USER_MALAGASY_PLATEAU, "mg", "MG" },
457 : { LANGUAGE_USER_BAFIA, "ksf", "CM" },
458 : { LANGUAGE_USER_GIKUYU, "ki", "KE" },
459 : { LANGUAGE_USER_RUSYN_UKRAINE, "rue", "UA" },
460 : { LANGUAGE_USER_RUSYN_SLOVAKIA, "rue", "SK" },
461 : { LANGUAGE_USER_LIMBU, "lif", "NP" },
462 : { LANGUAGE_USER_LOJBAN, "jbo", "" },
463 : { LANGUAGE_USER_HAITIAN, "ht", "HT" },
464 : { LANGUAGE_FRENCH_HAITI, "fr", "HT" },
465 : { LANGUAGE_USER_BEEMBE, "beq", "CG" },
466 : { LANGUAGE_USER_BEKWEL, "bkw", "CG" },
467 : { LANGUAGE_USER_KITUBA, "mkw", "CG" },
468 : { LANGUAGE_USER_LARI, "ldi", "CG" },
469 : { LANGUAGE_USER_MBOCHI, "mdw", "CG" },
470 : { LANGUAGE_USER_TEKE_EBOO, "ebo", "CG" },
471 : { LANGUAGE_USER_TEKE_IBALI, "tek", "CG" },
472 : { LANGUAGE_USER_TEKE_TYEE, "tyx", "CG" },
473 : { LANGUAGE_USER_VILI, "vif", "CG" },
474 : { LANGUAGE_USER_PORTUGUESE_ANGOLA, "pt", "AO" },
475 : { LANGUAGE_USER_MANX, "gv", "GB" },
476 : { LANGUAGE_USER_ARAGONESE, "an", "ES" },
477 : { LANGUAGE_USER_KEYID, "qtz", "" }, // key id pseudolanguage used for UI testing
478 : { LANGUAGE_USER_PALI_LATIN, "pli", "" }, // Pali with Latin script
479 : { LANGUAGE_USER_KYRGYZ_CHINA, "ky", "CN" },
480 : { LANGUAGE_USER_KOMI_ZYRIAN, "kpv", "RU" },
481 : { LANGUAGE_USER_KOMI_PERMYAK, "koi", "RU" },
482 : { LANGUAGE_USER_PITJANTJATJARA, "pjt", "AU" },
483 : { LANGUAGE_USER_ERZYA, "myv", "RU" },
484 : { LANGUAGE_USER_MARI_MEADOW, "mhr", "RU" },
485 : { LANGUAGE_USER_KHANTY, "kca", "RU" },
486 : { LANGUAGE_USER_LIVONIAN, "liv", "RU" },
487 : { LANGUAGE_USER_MOKSHA, "mdf", "RU" },
488 : { LANGUAGE_USER_MARI_HILL, "mrj", "RU" },
489 : { LANGUAGE_USER_NGANASAN, "nio", "RU" },
490 : { LANGUAGE_USER_OLONETS, "olo", "RU" },
491 : { LANGUAGE_USER_VEPS, "vep", "RU" },
492 : { LANGUAGE_USER_VORO, "vro", "EE" },
493 : { LANGUAGE_USER_NENETS, "yrk", "RU" },
494 : { LANGUAGE_USER_AKA, "axk", "CF" },
495 : { LANGUAGE_USER_AKA_CONGO, "axk", "CG" },
496 : { LANGUAGE_USER_DIBOLE, "bvx", "CG" },
497 : { LANGUAGE_USER_DOONDO, "dde", "CG" },
498 : { LANGUAGE_USER_KAAMBA, "xku", "CG" },
499 : { LANGUAGE_USER_KOONGO, "kng", "CD" },
500 : { LANGUAGE_USER_KOONGO_CONGO, "kng", "CG" },
501 : { LANGUAGE_USER_KUNYI, "njx", "CG" },
502 : { LANGUAGE_USER_NGUNGWEL, "ngz", "CG" },
503 : { LANGUAGE_USER_NJYEM, "njy", "CM" },
504 : { LANGUAGE_USER_NJYEM_CONGO, "njy", "CG" },
505 : { LANGUAGE_USER_PUNU, "puu", "GA" },
506 : { LANGUAGE_USER_PUNU_CONGO, "puu", "CG" },
507 : { LANGUAGE_USER_SUUNDI, "sdj", "CG" },
508 : { LANGUAGE_USER_TEKE_KUKUYA, "kkw", "CG" },
509 : { LANGUAGE_USER_TSAANGI, "tsa", "CG" },
510 : { LANGUAGE_USER_YAKA, "iyx", "CG" },
511 : { LANGUAGE_USER_YOMBE, "yom", "CD" },
512 : { LANGUAGE_USER_YOMBE_CONGO, "yom", "CG" },
513 : { LANGUAGE_USER_SIDAMA, "sid", "ET" },
514 : { LANGUAGE_MULTIPLE, "mul", "" }, // multiple languages, many languages are used
515 : { LANGUAGE_UNDETERMINED, "und", "" }, // undetermined language, language cannot be identified
516 : { LANGUAGE_NONE, "zxx", "" }, // added to ISO 639-2 on 2006-01-11: Used to declare the absence of linguistic information
517 : { LANGUAGE_DONTKNOW, "", "" } // marks end of table
518 : };
519 :
520 : static MsLangId::IsoLangEntry aLastResortFallbackEntry =
521 : { LANGUAGE_ENGLISH_US, "en", "US" };
522 :
523 : // -----------------------------------------------------------------------
524 :
525 : // In this table are the countries which should mapped to a specific
526 : // english language
527 : static IsoLangEngEntry const aImplIsoLangEngEntries[] =
528 : {
529 : { LANGUAGE_ENGLISH_UK, "AO" }, // Angola
530 : { LANGUAGE_ENGLISH_UK, "BJ" }, // Benin
531 : { LANGUAGE_ENGLISH_UK, "BW" }, // Botswana
532 : { LANGUAGE_ENGLISH_UK, "BI" }, // Burundi
533 : { LANGUAGE_ENGLISH_UK, "CM" }, // Cameroon
534 : { LANGUAGE_ENGLISH_UK, "GA" }, // Gabon
535 : { LANGUAGE_ENGLISH_UK, "GM" }, // Gambia
536 : { LANGUAGE_ENGLISH_UK, "GH" }, // Ghana
537 : { LANGUAGE_ENGLISH_UK, "GN" }, // Guinea
538 : { LANGUAGE_ENGLISH_UK, "LS" }, // Lesotho
539 : { LANGUAGE_ENGLISH_UK, "MW" }, // Malawi
540 : { LANGUAGE_ENGLISH_UK, "MT" }, // Malta
541 : { LANGUAGE_ENGLISH_UK, "NA" }, // Namibia
542 : { LANGUAGE_ENGLISH_UK, "NG" }, // Nigeria
543 : { LANGUAGE_ENGLISH_UK, "UG" }, // Uganda
544 : { LANGUAGE_ENGLISH_UK, "ZM" }, // Zambia
545 : { LANGUAGE_ENGLISH_UK, "ZW" }, // Zimbabwe
546 : { LANGUAGE_ENGLISH_UK, "SZ" }, // Swaziland
547 : { LANGUAGE_ENGLISH_UK, "NG" }, // Sierra Leone
548 : { LANGUAGE_ENGLISH_UK, "KN" }, // Saint Kitts and Nevis
549 : { LANGUAGE_ENGLISH_UK, "SH" }, // St. Helena
550 : { LANGUAGE_ENGLISH_UK, "IO" }, // British Indian Oceanic Territory
551 : { LANGUAGE_ENGLISH_UK, "FK" }, // Falkland Islands
552 : { LANGUAGE_ENGLISH_UK, "GI" }, // Gibraltar
553 : { LANGUAGE_ENGLISH_UK, "KI" }, // Kiribati
554 : { LANGUAGE_ENGLISH_UK, "VG" }, // Virgin Islands
555 : { LANGUAGE_ENGLISH_UK, "MU" }, // Mauritius
556 : { LANGUAGE_ENGLISH_UK, "FJ" }, // Fiji
557 : { LANGUAGE_ENGLISH_US, "KI" }, // Kiribati
558 : { LANGUAGE_ENGLISH_US, "LR" }, // Liberia
559 : { LANGUAGE_ENGLISH_US, "GU" }, // Guam
560 : { LANGUAGE_ENGLISH_US, "MH" }, // Marshall Islands
561 : { LANGUAGE_ENGLISH_US, "PW" }, // Palau
562 : { LANGUAGE_ENGLISH_CARRIBEAN, "AI" }, // Anguilla
563 : { LANGUAGE_ENGLISH_CARRIBEAN, "AG" }, // Antigua and Barbuda
564 : { LANGUAGE_ENGLISH_CARRIBEAN, "BS" }, // Bahamas
565 : { LANGUAGE_ENGLISH_CARRIBEAN, "BB" }, // Barbedos
566 : { LANGUAGE_ENGLISH_CARRIBEAN, "BM" }, // Bermuda
567 : { LANGUAGE_ENGLISH_CARRIBEAN, "KY" }, // Cayman Islands
568 : { LANGUAGE_ENGLISH_CARRIBEAN, "GD" }, // Grenada
569 : { LANGUAGE_ENGLISH_CARRIBEAN, "DM" }, // Dominica
570 : { LANGUAGE_ENGLISH_CARRIBEAN, "HT" }, // Haiti
571 : { LANGUAGE_ENGLISH_CARRIBEAN, "MS" }, // Montserrat
572 : { LANGUAGE_ENGLISH_CARRIBEAN, "FM" }, // Micronesia
573 : { LANGUAGE_ENGLISH_CARRIBEAN, "VC" }, // St. Vincent / Grenadines
574 : { LANGUAGE_ENGLISH_CARRIBEAN, "LC" }, // Saint Lucia
575 : { LANGUAGE_ENGLISH_CARRIBEAN, "TC" }, // Turks & Caicos Islands
576 : { LANGUAGE_ENGLISH_CARRIBEAN, "GY" }, // Guyana
577 : { LANGUAGE_ENGLISH_CARRIBEAN, "TT" }, // Trinidad and Tobago
578 : { LANGUAGE_ENGLISH_AUS, "CX" }, // Christmas Islands
579 : { LANGUAGE_ENGLISH_AUS, "CC" }, // Cocos (Keeling) Islands
580 : { LANGUAGE_ENGLISH_AUS, "NF" }, // Norfolk Island
581 : { LANGUAGE_ENGLISH_AUS, "PG" }, // Papua New Guinea
582 : { LANGUAGE_ENGLISH_AUS, "SB" }, // Solomon Islands
583 : { LANGUAGE_ENGLISH_AUS, "TV" }, // Tuvalu
584 : { LANGUAGE_ENGLISH_AUS, "NR" }, // Nauru
585 : { LANGUAGE_ENGLISH_NZ, "CK" }, // Cook Islands
586 : { LANGUAGE_ENGLISH_NZ, "NU" }, // Niue
587 : { LANGUAGE_ENGLISH_NZ, "TK" }, // Tokelau
588 : { LANGUAGE_ENGLISH_NZ, "TO" }, // Tonga
589 : { LANGUAGE_DONTKNOW, "" } // marks end of table
590 : };
591 :
592 : // -----------------------------------------------------------------------
593 :
594 : static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries[] =
595 : {
596 : { LANGUAGE_NORWEGIAN_BOKMAL, "no", "BOK" }, // registered subtags for "no" in rfc1766
597 : { LANGUAGE_NORWEGIAN_NYNORSK, "no", "NYN" }, // registered subtags for "no" in rfc1766
598 : { LANGUAGE_SERBIAN_LATIN, "sr", "latin" },
599 : { LANGUAGE_SERBIAN_CYRILLIC, "sr", "cyrillic" },
600 : { LANGUAGE_AZERI_LATIN, "az", "latin" },
601 : { LANGUAGE_AZERI_CYRILLIC, "az", "cyrillic" },
602 : { LANGUAGE_DONTKNOW, "", "" } // marks end of table
603 : };
604 :
605 : // -----------------------------------------------------------------------
606 :
607 : // in this table are only names to find the best language
608 : static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries2[] =
609 : {
610 : { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmaal" },
611 : { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmal" },
612 : { LANGUAGE_NORWEGIAN_NYNORSK, "no", "nynorsk" },
613 : { LANGUAGE_DONTKNOW, "", "" } // marks end of table
614 : };
615 :
616 : // -----------------------------------------------------------------------
617 :
618 : // in this table are only names to find the best language
619 : static IsoLangOtherEntry const aImplOtherEntries[] =
620 : {
621 : { LANGUAGE_ENGLISH_US, "c" },
622 : { LANGUAGE_CHINESE, "chinese" },
623 : { LANGUAGE_GERMAN, "german" },
624 : { LANGUAGE_JAPANESE, "japanese" },
625 : { LANGUAGE_KOREAN, "korean" },
626 : { LANGUAGE_ENGLISH_US, "posix" },
627 : { LANGUAGE_CHINESE_TRADITIONAL, "tchinese" },
628 : { LANGUAGE_DONTKNOW, NULL } // marks end of table
629 : };
630 :
631 : // =======================================================================
632 :
633 : // static
634 44380 : void MsLangId::Conversion::convertLanguageToIsoNames( LanguageType nLang,
635 : rtl::OUString& rLangStr, rtl::OUString& rCountry )
636 : {
637 44380 : if ( nLang == LANGUAGE_SYSTEM )
638 0 : nLang = MsLangId::getSystemLanguage();
639 :
640 : // Search for LangID (in this table we find only defined ISO combinations)
641 44380 : const IsoLangEntry* pEntry = aImplIsoLangEntries;
642 973959 : do
643 : {
644 1018339 : if ( pEntry->mnLang == nLang )
645 : {
646 44380 : rLangStr = rtl::OUString::createFromAscii( pEntry->maLangStr );
647 44380 : rCountry = rtl::OUString::createFromAscii( pEntry->maCountry );
648 44380 : return;
649 : }
650 973959 : ++pEntry;
651 : }
652 : while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
653 :
654 : // Search for LangID if we didn't find a specific ISO combination.
655 : // All entries in this table are allowed for mime specifications,
656 : // but not defined ISO combinations.
657 0 : const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
658 0 : do
659 : {
660 0 : if ( pNoneStdEntry->mnLang == nLang )
661 : {
662 0 : rLangStr = rtl::OUString::createFromAscii( pNoneStdEntry->maLangStr );
663 0 : rCountry = rtl::OUString::createFromAscii( pNoneStdEntry->maCountry );
664 0 : return;
665 : }
666 0 : ++pNoneStdEntry;
667 : }
668 : while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
669 :
670 : // not found
671 0 : rLangStr = rtl::OUString();
672 0 : rCountry = rtl::OUString();
673 : }
674 :
675 : // -----------------------------------------------------------------------
676 :
677 : // -----------------------------------------------------------------------
678 :
679 16 : static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry( LanguageType nLang )
680 : {
681 16 : LanguageType nPrimary = MsLangId::getPrimaryLanguage( nLang);
682 :
683 : // Search for LangID and remember first lang-only.
684 16 : const MsLangId::IsoLangEntry* pFirstPrimary = NULL;
685 16 : const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries;
686 16 : do
687 : {
688 32 : if (pEntry->mnLang == nLang)
689 : {
690 16 : if (*pEntry->maCountry)
691 16 : return *pEntry;
692 0 : switch (nLang)
693 : {
694 : // These are known to have no country assigned.
695 : case LANGUAGE_BASQUE:
696 : case LANGUAGE_USER_ESPERANTO:
697 : case LANGUAGE_USER_INTERLINGUA:
698 : case LANGUAGE_USER_LOJBAN:
699 0 : return *pEntry;
700 : default:
701 : ; // nothing
702 : }
703 : }
704 32 : if (!pFirstPrimary &&
705 16 : MsLangId::getPrimaryLanguage( pEntry->mnLang) == nPrimary)
706 16 : pFirstPrimary = pEntry;
707 16 : ++pEntry;
708 : }
709 : while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
710 :
711 : // Language not found at all => use default.
712 0 : if (!pFirstPrimary)
713 0 : return aLastResortFallbackEntry;
714 :
715 : // Search for first entry of primary language with any country.
716 0 : pEntry = pFirstPrimary;
717 0 : do
718 : {
719 0 : if (MsLangId::getPrimaryLanguage( pEntry->mnLang) == nLang)
720 : {
721 0 : if (*pEntry->maCountry)
722 0 : return *pEntry;
723 : }
724 0 : ++pEntry;
725 : }
726 : while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
727 :
728 0 : return aLastResortFallbackEntry;
729 : }
730 :
731 : // static
732 0 : LanguageType MsLangId::Conversion::lookupFallbackLanguage( LanguageType nLang )
733 : {
734 0 : return lcl_lookupFallbackEntry( nLang).mnLang;
735 : }
736 :
737 :
738 : // static
739 16 : ::com::sun::star::lang::Locale MsLangId::Conversion::lookupFallbackLocale( LanguageType nLang )
740 : {
741 16 : const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( nLang);
742 : return ::com::sun::star::lang::Locale(
743 : rtl::OUString::createFromAscii( rEntry.maLangStr),
744 : rtl::OUString::createFromAscii( rEntry.maCountry),
745 16 : rtl::OUString());
746 : }
747 :
748 : // -----------------------------------------------------------------------
749 :
750 70 : static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry(
751 : const ::com::sun::star::lang::Locale & rLocale )
752 : {
753 : // language is lower case in table
754 70 : rtl::OUString aLowerLang = rLocale.Language.toAsciiLowerCase();
755 : // country is upper case in table
756 70 : rtl::OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
757 70 : sal_Int32 nCountryLen = aUpperCountry.getLength();
758 :
759 : // Search for locale and remember first lang-only.
760 70 : const MsLangId::IsoLangEntry* pFirstLang = NULL;
761 70 : const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries;
762 13267 : do
763 : {
764 13334 : if (aLowerLang.equalsAscii( pEntry->maLangStr))
765 : {
766 110 : if (*pEntry->maCountry)
767 : {
768 40 : if (nCountryLen && aUpperCountry.equalsAscii( pEntry->maCountry))
769 19 : return *pEntry;
770 : }
771 : else
772 : {
773 70 : switch (pEntry->mnLang)
774 : {
775 : // These are known to have no country assigned.
776 : case LANGUAGE_BASQUE:
777 : case LANGUAGE_USER_ESPERANTO:
778 : case LANGUAGE_USER_INTERLINGUA:
779 : case LANGUAGE_USER_LOJBAN:
780 48 : return *pEntry;
781 : default:
782 : ; // nothing
783 : }
784 : }
785 43 : if (!pFirstLang)
786 22 : pFirstLang = pEntry;
787 : }
788 13267 : ++pEntry;
789 : }
790 : while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
791 :
792 : // Language not found at all => use default.
793 3 : if (!pFirstLang)
794 0 : return aLastResortFallbackEntry;
795 :
796 : // Search for first entry of language with any country.
797 3 : pEntry = pFirstLang;
798 3 : do
799 : {
800 4 : if (aLowerLang.equalsAscii( pEntry->maLangStr))
801 : {
802 4 : if (*pEntry->maCountry)
803 1 : return *pEntry;
804 : }
805 3 : ++pEntry;
806 : }
807 : while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
808 :
809 2 : return aLastResortFallbackEntry;
810 : }
811 :
812 :
813 : // static
814 70 : ::com::sun::star::lang::Locale MsLangId::Conversion::lookupFallbackLocale(
815 : const ::com::sun::star::lang::Locale & rLocale )
816 : {
817 70 : const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( rLocale);
818 : return ::com::sun::star::lang::Locale(
819 : rtl::OUString::createFromAscii( rEntry.maLangStr),
820 : rtl::OUString::createFromAscii( rEntry.maCountry),
821 70 : rtl::OUString());
822 : }
823 :
824 : // =======================================================================
825 :
826 : // static
827 16844 : LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const rtl::OUString& rLang,
828 : const rtl::OUString& rCountry )
829 : {
830 : // language is lower case in table
831 16844 : rtl::OUString aLowerLang = rLang.toAsciiLowerCase();
832 : // country is upper case in table
833 16844 : rtl::OUString aUpperCountry = rCountry.toAsciiUpperCase();
834 :
835 : // first look for exact match
836 16844 : const IsoLangEntry* pFirstLang = NULL;
837 16844 : const IsoLangEntry* pEntry = aImplIsoLangEntries;
838 249079 : do
839 : {
840 265917 : if ( aLowerLang.equalsAscii( pEntry->maLangStr ) )
841 : {
842 68206 : if ( aUpperCountry.isEmpty() ||
843 34084 : aUpperCountry.equalsAscii( pEntry->maCountry ) )
844 16838 : return pEntry->mnLang;
845 17284 : if ( !pFirstLang )
846 15364 : pFirstLang = pEntry;
847 1920 : else if ( !*pEntry->maCountry )
848 20 : pFirstLang = pEntry;
849 : }
850 249079 : ++pEntry;
851 : }
852 : while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
853 :
854 : // some eng countries should be mapped to a specific english language
855 6 : if ( aLowerLang == "en" )
856 : {
857 0 : const IsoLangEngEntry* pEngEntry = aImplIsoLangEngEntries;
858 0 : do
859 : {
860 0 : if ( aUpperCountry.equalsAscii( pEngEntry->maCountry ) )
861 0 : return pEngEntry->mnLang;
862 0 : ++pEngEntry;
863 : }
864 : while ( pEngEntry->mnLang != LANGUAGE_DONTKNOW );
865 : }
866 :
867 : // test for specific languages which are not used standard ISO 3166 codes
868 6 : const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
869 36 : do
870 : {
871 36 : if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) )
872 : {
873 : // The countries in this table are not all in upper case
874 0 : if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) )
875 0 : return pNoneStdEntry->mnLang;
876 : }
877 36 : ++pNoneStdEntry;
878 : }
879 : while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
880 6 : pNoneStdEntry = aImplIsoNoneStdLangEntries2;
881 18 : do
882 : {
883 18 : if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) )
884 : {
885 : // The countries in this table are not all in upper case
886 0 : if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) )
887 0 : return pNoneStdEntry->mnLang;
888 : }
889 18 : ++pNoneStdEntry;
890 : }
891 : while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
892 :
893 : // If the language is correct, than we return the default language
894 6 : if ( pFirstLang )
895 0 : return pFirstLang->mnLang;
896 :
897 : // if only the country is set, look for any entry matching the country
898 : // (to allow reading country and language in separate steps, in any order)
899 6 : if ( !rCountry.isEmpty() && rLang.isEmpty() )
900 : {
901 0 : const IsoLangEntry* pEntry2 = aImplIsoLangEntries;
902 0 : do
903 : {
904 0 : if ( aUpperCountry.equalsAscii( pEntry2->maCountry ) )
905 0 : return pEntry2->mnLang;
906 0 : ++pEntry2;
907 : }
908 : while ( pEntry2->mnLang != LANGUAGE_DONTKNOW );
909 :
910 0 : aLowerLang = aUpperCountry.toAsciiLowerCase();
911 : }
912 :
913 : // Now look for all other definitions, which are not standard
914 6 : const IsoLangOtherEntry* pOtherEntry = aImplOtherEntries;
915 42 : do
916 : {
917 42 : if ( aLowerLang.equalsAscii( pOtherEntry->mpLangStr ) )
918 0 : return pOtherEntry->mnLang;
919 42 : ++pOtherEntry;
920 : }
921 : while ( pOtherEntry->mnLang != LANGUAGE_DONTKNOW );
922 :
923 6 : return LANGUAGE_DONTKNOW;
924 : }
925 :
926 : // -----------------------------------------------------------------------
927 :
928 : // static
929 65 : LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const rtl::OString& rLang,
930 : const rtl::OString& rCountry )
931 : {
932 65 : rtl::OUString aLang = OStringToOUString( rLang, RTL_TEXTENCODING_ASCII_US);
933 65 : rtl::OUString aCountry = OStringToOUString( rCountry, RTL_TEXTENCODING_ASCII_US);
934 65 : return convertIsoNamesToLanguage( aLang, aCountry);
935 : }
936 :
937 : // -----------------------------------------------------------------------
938 :
939 : struct IsoLangGLIBCModifiersEntry
940 : {
941 : LanguageType mnLang;
942 : sal_Char maLangStr[4];
943 : sal_Char maCountry[3];
944 : sal_Char maAtString[9];
945 : };
946 :
947 : static IsoLangGLIBCModifiersEntry const aImplIsoLangGLIBCModifiersEntries[] =
948 : {
949 : // MS-LANGID codes ISO639-1/2/3 ISO3166 glibc modifier
950 : { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "bs", "BA", "cyrillic" },
951 : { LANGUAGE_USER_SERBIAN_LATIN_SERBIA, "sr", "RS", "latin" }, // Serbian Latin in Serbia
952 : { LANGUAGE_SERBIAN_LATIN, "sr", "CS", "latin" }, // Serbian Latin in Serbia and Montenegro
953 : { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO, "sr", "ME", "latin" }, // Serbian Latin in Montenegro
954 : { LANGUAGE_SERBIAN_LATIN_NEUTRAL, "sr", "", "latin" },
955 : { LANGUAGE_AZERI_CYRILLIC, "az", "AZ", "cyrillic" },
956 : { LANGUAGE_UZBEK_CYRILLIC, "uz", "UZ", "cyrillic" },
957 : { LANGUAGE_DONTKNOW, "", "", "" } // marks end of table
958 : };
959 :
960 : // convert a unix locale string into LanguageType
961 :
962 : // static
963 65 : LanguageType MsLangId::convertUnxByteStringToLanguage(
964 : const rtl::OString& rString )
965 : {
966 65 : rtl::OString aLang;
967 65 : rtl::OString aCountry;
968 65 : rtl::OString aAtString;
969 :
970 65 : sal_Int32 nLangSepPos = rString.indexOf( (sal_Char)'_' );
971 65 : sal_Int32 nCountrySepPos = rString.indexOf( (sal_Char)'.' );
972 65 : sal_Int32 nAtPos = rString.indexOf( (sal_Char)'@' );
973 :
974 65 : if (nCountrySepPos < 0)
975 0 : nCountrySepPos = nAtPos;
976 65 : if (nCountrySepPos < 0)
977 0 : nCountrySepPos = rString.getLength();
978 :
979 65 : if (nAtPos >= 0)
980 0 : aAtString = rString.copy( nAtPos+1 );
981 :
982 65 : if ( ((nLangSepPos >= 0) && (nLangSepPos > nCountrySepPos))
983 : || ((nLangSepPos < 0)) )
984 : {
985 : // eg. "el.sun_eu_greek", "tchinese", "es.ISO8859-15"
986 0 : aLang = rString.copy( 0, nCountrySepPos );
987 : }
988 65 : else if ( nLangSepPos >= 0 )
989 : {
990 : // well formed iso names like "en_US.UTF-8", "sh_BA.ISO8859-2@bosnia"
991 65 : aLang = rString.copy( 0, nLangSepPos );
992 65 : aCountry = rString.copy( nLangSepPos+1, nCountrySepPos - nLangSepPos - 1);
993 : }
994 :
995 : // if there is a glibc modifier, first look for exact match in modifier table
996 65 : if (!aAtString.isEmpty())
997 : {
998 : // language is lower case in table
999 0 : rtl::OString aLowerLang = aLang.toAsciiLowerCase();
1000 : // country is upper case in table
1001 0 : rtl::OString aUpperCountry = aCountry.toAsciiUpperCase();
1002 0 : const IsoLangGLIBCModifiersEntry* pGLIBCModifiersEntry = aImplIsoLangGLIBCModifiersEntries;
1003 0 : do
1004 : { // avoid embedded \0 warning
1005 0 : if (( aLowerLang.equals( static_cast< const char* >( pGLIBCModifiersEntry->maLangStr ))) &&
1006 0 : ( aAtString.equals( static_cast< const char* >( pGLIBCModifiersEntry->maAtString ))))
1007 : {
1008 0 : if ( aUpperCountry.isEmpty() ||
1009 0 : aUpperCountry.equals( static_cast< const char* >( pGLIBCModifiersEntry->maCountry )))
1010 : {
1011 0 : return pGLIBCModifiersEntry->mnLang;
1012 : }
1013 : }
1014 0 : ++pGLIBCModifiersEntry;
1015 : }
1016 0 : while ( pGLIBCModifiersEntry->mnLang != LANGUAGE_DONTKNOW );
1017 : }
1018 :
1019 65 : return Conversion::convertIsoNamesToLanguage( aLang, aCountry );
1020 : }
1021 :
1022 : // -----------------------------------------------------------------------
1023 : // pass one IsoLangEntry to the outer world of the resource compiler
1024 :
1025 : // static
1026 288147 : const MsLangId::IsoLangEntry* MsLangId::getIsoLangEntry( size_t nIndex )
1027 : {
1028 288147 : if (nIndex < SAL_N_ELEMENTS(aImplIsoLangEntries))
1029 288147 : return &aImplIsoLangEntries[ nIndex];
1030 0 : return 0;
1031 : }
1032 :
1033 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|