bump product version to 4.2.0.1
[LibreOffice.git] / i18nlangtag / source / isolang / isolang.cxx
blob2611dbb03bc5c9a6d454aedca6e251810c017395
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/ustring.hxx>
21 #include <rtl/string.hxx>
22 #include <rtl/ustrbuf.hxx>
23 #include <rtl/strbuf.hxx>
25 #include "i18nlangtag/mslangid.hxx"
26 #include "i18nlangtag/languagetag.hxx"
28 using namespace com::sun::star;
30 // =======================================================================
32 static const LanguageType kSAME = 0xffff;
34 namespace {
35 inline LanguageType getOverrideLang( LanguageType nLang, LanguageType nOverride )
37 return nOverride ? ((nOverride == kSAME) ? nLang : nOverride) : nLang;
41 /* Usage of override mechanism:
42 * If a table entry's mnOverride is not 0, an override entry with an mnLang
43 * value of (mnOverride==kSAME ? mnLang : mnOverride) exists that should be
44 * used instead. There MUST exist one such entry that does not have an
45 * mnOverride value and within one table it MUST be located before any entry
46 * with that mnLang and an mnOverride value of not 0. Usually kSAME is used as
47 * override value, with rare exceptions, see tables below.
49 * The override serves these purposes:
50 * - With getOverride() it indicates that there is a different language tag
51 * (locale) that the requested language tag should be "canonicalized" to.
52 * - With lookupFallbackLocale() a locale may be returned where the language
53 * tag differs.
54 * - With convertLanguageToLocaleImpl() and bIgnoreOverride=false the override
55 * is followed and the override locale returned.
56 * - With convertLocaleToLanguageImpl() a different LangID may be returned in
57 * rare cases where the actual mapped ID differs.
60 struct IsoLanguageCountryEntry
62 LanguageType mnLang;
63 sal_Char maLanguage[4];
64 sal_Char maCountry[3];
65 LanguageType mnOverride;
67 /** Obtain a language tag string with '-' separator. */
68 OUString getTagString() const;
70 /** Obtain a locale. */
71 ::com::sun::star::lang::Locale getLocale() const;
74 struct IsoLanguageScriptCountryEntry
76 LanguageType mnLang;
77 sal_Char maLanguageScript[9]; ///< "ll-Ssss" or "lll-Ssss"
78 sal_Char maCountry[3];
79 LanguageType mnOverride;
81 /** Obtain a language tag string with '-' separator. */
82 OUString getTagString() const;
84 /** Obtain a locale. */
85 ::com::sun::star::lang::Locale getLocale() const;
87 /** If rStr starts with maLanguageScript ignoring case.
89 We don't have OUString::startsWithIgnoreAsciiCaseAscii()
91 bool startsInIgnoreAsciiCase( const OUString & rStr ) const;
94 struct Bcp47CountryEntry
96 LanguageType mnLang;
97 const sal_Char* mpBcp47;
98 sal_Char maCountry[3];
99 const sal_Char* mpFallback;
101 /** Obtain a language tag string with '-' separator. */
102 OUString getTagString() const;
104 /** Obtain a locale. */
105 ::com::sun::star::lang::Locale getLocale() const;
108 struct IsoLangEngEntry
110 LanguageType mnLang;
111 sal_Char maCountry[3];
114 struct IsoLangNoneStdEntry
116 LanguageType mnLang;
117 sal_Char maLanguage[4];
118 sal_Char maCountry[9];
121 struct IsoLangOtherEntry
123 LanguageType mnLang;
124 const sal_Char* mpLanguage;
127 // -----------------------------------------------------------------------
129 // Entries for languages are lower case, for countries upper case, as
130 // recommended by rfc5646 (obsoletes rfc4646 (obsoletes rfc3066 (obsoletes
131 // rfc1766))). convertIsoNamesToLanguage(), convertLocaleToLanguageImpl()
132 // and lookupFallbackLocale() are case insensitive.
134 // Sort order: Most used first and within one language the default fallback
135 // locale of that language first.
137 // The default entry for a LangID <-> ISO mapping has to be first. For
138 // conversion of legacy mappings one LangID can map to multiple ISO codes
139 // except if the LangID is primary-only, and one ISO code combination can map
140 // to multiple LangIDs. For compatibility with already existing calls it can
141 // also be a sequence as follows:
143 // LANGUAGE_ENGLISH, "en", ""
144 // LANGUAGE_ENGLISH_US, "en", "US"
146 // Here, in a convertIsoNamesToLanguage() call "en-US" is converted to
147 // LANGUAGE_ENGLISH_US and "en" is converted to LANGUAGE_ENGLISH. A call with
148 // "en-ZZ" (not in table) would result in LANGUAGE_ENGLISH because the first
149 // entry matching the language and not having a country is returned, regardless
150 // of whether being sorted before or after other entries of the same language
151 // with some country. To obtain a _locale_ (not language only) in the order
152 // given, lookupFallbackLocale() must be called.
154 // If the sequence instead was
156 // LANGUAGE_ENGLISH_US, "en", "US"
157 // LANGUAGE_ENGLISH, "en", ""
159 // in a convertIsoNamesToLanguage() call "en-US" would still be converted to
160 // LANGUAGE_ENGLISH_US, but "en" would _also_ be converted to
161 // LANGUAGE_ENGLISH_US because no country was passed and it is the first entry
162 // to match the language, see code. A call with "en-ZZ" (not in table) would
163 // still result in LANGUAGE_ENGLISH.
165 /* Currently (2013-08-29) only these primary LangID are still used literally in
166 * code:
167 * LANGUAGE_ENGLISH LANGUAGE_ARABIC_PRIMARY_ONLY
170 static IsoLanguageCountryEntry const aImplIsoLangEntries[] =
172 // MS-LANGID codes, ISO639-1/2/3, ISO3166, override
173 { LANGUAGE_ENGLISH, "en", "" , 0 },
174 { LANGUAGE_ENGLISH_US, "en", "US", 0 },
175 { LANGUAGE_ENGLISH_UK, "en", "GB", 0 },
176 { LANGUAGE_ENGLISH_AUS, "en", "AU", 0 },
177 { LANGUAGE_ENGLISH_CAN, "en", "CA", 0 },
178 { LANGUAGE_FRENCH, "fr", "FR", 0 },
179 { LANGUAGE_GERMAN, "de", "DE", 0 },
180 { LANGUAGE_ITALIAN, "it", "IT", 0 },
181 { LANGUAGE_DUTCH, "nl", "NL", 0 },
182 { LANGUAGE_SPANISH_MODERN, "es", "ES", 0 },
183 { LANGUAGE_SPANISH_DATED, "es", "ES", 0 },
184 { LANGUAGE_PORTUGUESE, "pt", "PT", 0 },
185 { LANGUAGE_PORTUGUESE_BRAZILIAN, "pt", "BR", 0 },
186 { LANGUAGE_DANISH, "da", "DK", 0 },
187 { LANGUAGE_GREEK, "el", "GR", 0 },
188 { LANGUAGE_CHINESE_SIMPLIFIED, "zh", "CN", 0 },
189 { LANGUAGE_CHINESE_SIMPLIFIED_LEGACY, "zh", "CN", 0 },
190 { LANGUAGE_CHINESE_TRADITIONAL, "zh", "TW", 0 },
191 { LANGUAGE_CHINESE_HONGKONG, "zh", "HK", 0 },
192 { LANGUAGE_CHINESE_SINGAPORE, "zh", "SG", 0 },
193 { LANGUAGE_CHINESE_MACAU, "zh", "MO", 0 },
194 { LANGUAGE_CHINESE_LSO, "zh", "" , 0 },
195 { LANGUAGE_YUE_CHINESE_HONGKONG, "yue", "HK", 0 },
196 { LANGUAGE_ENGLISH_HONG_KONG_SAR, "en", "HK", 0 },
197 { LANGUAGE_JAPANESE, "ja", "JP", 0 },
198 { LANGUAGE_KOREAN, "ko", "KR", 0 },
199 { LANGUAGE_KOREAN_JOHAB, "ko", "KR", 0 },
200 { LANGUAGE_USER_KOREAN_NORTH, "ko", "KP", 0 },
201 { LANGUAGE_SWEDISH, "sv", "SE", 0 },
202 { LANGUAGE_SWEDISH_FINLAND, "sv", "FI", 0 },
203 { LANGUAGE_FINNISH, "fi", "FI", 0 },
204 { LANGUAGE_RUSSIAN, "ru", "RU", 0 },
205 { LANGUAGE_TATAR, "tt", "RU", 0 },
206 { LANGUAGE_ENGLISH_NZ, "en", "NZ", 0 },
207 { LANGUAGE_ENGLISH_EIRE, "en", "IE", 0 },
208 { LANGUAGE_DUTCH_BELGIAN, "nl", "BE", 0 },
209 { LANGUAGE_FRENCH_BELGIAN, "fr", "BE", 0 },
210 { LANGUAGE_FRENCH_CANADIAN, "fr", "CA", 0 },
211 { LANGUAGE_FRENCH_SWISS, "fr", "CH", 0 },
212 { LANGUAGE_GERMAN_SWISS, "de", "CH", 0 },
213 { LANGUAGE_GERMAN_AUSTRIAN, "de", "AT", 0 },
214 { LANGUAGE_ITALIAN_SWISS, "it", "CH", 0 },
215 { LANGUAGE_ALBANIAN, "sq", "AL", 0 },
216 { LANGUAGE_ARABIC_SAUDI_ARABIA, "ar", "SA", 0 },
217 { LANGUAGE_ARABIC_EGYPT, "ar", "EG", 0 },
218 { LANGUAGE_ARABIC_UAE, "ar", "AE", 0 },
219 { LANGUAGE_ARABIC_IRAQ, "ar", "IQ", 0 },
220 { LANGUAGE_ARABIC_LIBYA, "ar", "LY", 0 },
221 { LANGUAGE_ARABIC_ALGERIA, "ar", "DZ", 0 },
222 { LANGUAGE_ARABIC_MOROCCO, "ar", "MA", 0 },
223 { LANGUAGE_ARABIC_TUNISIA, "ar", "TN", 0 },
224 { LANGUAGE_ARABIC_OMAN, "ar", "OM", 0 },
225 { LANGUAGE_ARABIC_YEMEN, "ar", "YE", 0 },
226 { LANGUAGE_ARABIC_SYRIA, "ar", "SY", 0 },
227 { LANGUAGE_ARABIC_JORDAN, "ar", "JO", 0 },
228 { LANGUAGE_ARABIC_LEBANON, "ar", "LB", 0 },
229 { LANGUAGE_ARABIC_KUWAIT, "ar", "KW", 0 },
230 { LANGUAGE_ARABIC_BAHRAIN, "ar", "BH", 0 },
231 { LANGUAGE_ARABIC_QATAR, "ar", "QA", 0 },
232 { LANGUAGE_USER_ARABIC_CHAD, "ar", "TD", 0 },
233 { LANGUAGE_USER_ARABIC_COMOROS, "ar", "KM", 0 },
234 { LANGUAGE_USER_ARABIC_DJIBOUTI, "ar", "DJ", 0 },
235 { LANGUAGE_USER_ARABIC_ERITREA, "ar", "ER", 0 },
236 { LANGUAGE_USER_ARABIC_ISRAEL, "ar", "IL", 0 },
237 { LANGUAGE_USER_ARABIC_MAURITANIA, "ar", "MR", 0 },
238 { LANGUAGE_USER_ARABIC_PALESTINE, "ar", "PS", 0 },
239 { LANGUAGE_USER_ARABIC_SOMALIA, "ar", "SO", 0 },
240 { LANGUAGE_USER_ARABIC_SUDAN, "ar", "SD", 0 },
241 { LANGUAGE_ARABIC_PRIMARY_ONLY, "ar", "" , 0 },
242 { LANGUAGE_BASQUE, "eu", "" , 0 },
243 { LANGUAGE_BULGARIAN, "bg", "BG", 0 },
244 { LANGUAGE_CZECH, "cs", "CZ", 0 },
245 { LANGUAGE_CZECH, "cz", "" , kSAME },
246 { LANGUAGE_ENGLISH_JAMAICA, "en", "JM", 0 },
247 { LANGUAGE_ENGLISH_CARRIBEAN, "en", "BS", 0 }, // not 100%, because AG is Bahamas
248 { LANGUAGE_ENGLISH_BELIZE, "en", "BZ", 0 },
249 { LANGUAGE_ENGLISH_TRINIDAD, "en", "TT", 0 },
250 { LANGUAGE_ENGLISH_ZIMBABWE, "en", "ZW", 0 },
251 { LANGUAGE_ENGLISH_INDONESIA, "en", "ID", 0 },
252 { LANGUAGE_ESTONIAN, "et", "EE", 0 },
253 { LANGUAGE_FAEROESE, "fo", "FO", 0 },
254 { LANGUAGE_FARSI, "fa", "IR", 0 },
255 { LANGUAGE_FRENCH_LUXEMBOURG, "fr", "LU", 0 },
256 { LANGUAGE_FRENCH_MONACO, "fr", "MC", 0 },
257 { LANGUAGE_GERMAN_LUXEMBOURG, "de", "LU", 0 },
258 { LANGUAGE_GERMAN_LIECHTENSTEIN, "de", "LI", 0 },
259 { LANGUAGE_HEBREW, "he", "IL", 0 }, // new: old was "iw"
260 { LANGUAGE_HEBREW, "iw", "IL", kSAME }, // old: new is "he"
261 { LANGUAGE_HUNGARIAN, "hu", "HU", 0 },
262 { LANGUAGE_ICELANDIC, "is", "IS", 0 },
263 { LANGUAGE_INDONESIAN, "id", "ID", 0 }, // new: old was "in"
264 { LANGUAGE_INDONESIAN, "in", "ID", kSAME }, // old: new is "id"
265 { LANGUAGE_NORWEGIAN, "no", "NO", 0 },
266 { LANGUAGE_NORWEGIAN_BOKMAL, "nb", "NO", 0 },
267 { LANGUAGE_NORWEGIAN_BOKMAL_LSO, "nb", "" , 0 },
268 { LANGUAGE_NORWEGIAN_NYNORSK, "nn", "NO", 0 },
269 { LANGUAGE_NORWEGIAN_NYNORSK_LSO, "nn", "" , 0 },
270 { LANGUAGE_POLISH, "pl", "PL", 0 },
271 { LANGUAGE_RHAETO_ROMAN, "rm", "CH", 0 },
272 { LANGUAGE_ROMANIAN, "ro", "RO", 0 },
273 { LANGUAGE_ROMANIAN_MOLDOVA, "ro", "MD", 0 },
274 { LANGUAGE_SLOVAK, "sk", "SK", 0 },
275 { LANGUAGE_SLOVENIAN, "sl", "SI", 0 },
276 { LANGUAGE_SPANISH_MEXICAN, "es", "MX", 0 },
277 { LANGUAGE_SPANISH_GUATEMALA, "es", "GT", 0 },
278 { LANGUAGE_SPANISH_COSTARICA, "es", "CR", 0 },
279 { LANGUAGE_SPANISH_PANAMA, "es", "PA", 0 },
280 { LANGUAGE_SPANISH_DOMINICAN_REPUBLIC, "es", "DO", 0 },
281 { LANGUAGE_SPANISH_VENEZUELA, "es", "VE", 0 },
282 { LANGUAGE_SPANISH_COLOMBIA, "es", "CO", 0 },
283 { LANGUAGE_SPANISH_PERU, "es", "PE", 0 },
284 { LANGUAGE_SPANISH_ARGENTINA, "es", "AR", 0 },
285 { LANGUAGE_SPANISH_ECUADOR, "es", "EC", 0 },
286 { LANGUAGE_SPANISH_CHILE, "es", "CL", 0 },
287 { LANGUAGE_SPANISH_URUGUAY, "es", "UY", 0 },
288 { LANGUAGE_SPANISH_PARAGUAY, "es", "PY", 0 },
289 { LANGUAGE_SPANISH_BOLIVIA, "es", "BO", 0 },
290 { LANGUAGE_SPANISH_EL_SALVADOR, "es", "SV", 0 },
291 { LANGUAGE_SPANISH_HONDURAS, "es", "HN", 0 },
292 { LANGUAGE_SPANISH_NICARAGUA, "es", "NI", 0 },
293 { LANGUAGE_SPANISH_PUERTO_RICO, "es", "PR", 0 },
294 { LANGUAGE_SPANISH_UNITED_STATES, "es", "US", 0 },
295 { LANGUAGE_SPANISH_LATIN_AMERICA, "es", "" , 0 },
296 { LANGUAGE_TURKISH, "tr", "TR", 0 },
297 { LANGUAGE_UKRAINIAN, "uk", "UA", 0 },
298 { LANGUAGE_VIETNAMESE, "vi", "VN", 0 },
299 { LANGUAGE_LATVIAN, "lv", "LV", 0 },
300 { LANGUAGE_MACEDONIAN, "mk", "MK", 0 },
301 { LANGUAGE_MALAY_MALAYSIA, "ms", "MY", 0 },
302 { LANGUAGE_MALAY_BRUNEI_DARUSSALAM, "ms", "BN", 0 },
303 { LANGUAGE_ENGLISH_MALAYSIA, "en", "MY", 0 },
304 { LANGUAGE_THAI, "th", "TH", 0 },
305 { LANGUAGE_LITHUANIAN, "lt", "LT", 0 },
306 { LANGUAGE_LITHUANIAN_CLASSIC, "lt", "LT", 0 },
307 { LANGUAGE_CROATIAN, "hr", "HR", 0 }, // Croatian in Croatia
308 { LANGUAGE_CROATIAN_BOSNIA_HERZEGOVINA, "hr", "BA", 0 },
309 { LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA, "bs", "BA", 0 },
310 { LANGUAGE_BOSNIAN_LSO, "bs", "" , 0 }, // so what is 'bs' vs 'bs-Latn'?
311 { LANGUAGE_SERBIAN_CYRILLIC_SERBIA, "sr", "RS", 0 }, // Serbian Cyrillic in Serbia
312 { LANGUAGE_OBSOLETE_USER_SERBIAN_CYRILLIC_SERBIA, "sr", "RS", 0 },
313 { LANGUAGE_SERBIAN_CYRILLIC_SAM, "sr", "CS", 0 }, // Serbian Cyrillic in Serbia and Montenegro
314 { LANGUAGE_SERBIAN_CYRILLIC_SAM, "sr", "YU", kSAME }, // legacy Serbian Cyrillic in Serbia and Montenegro (former Yugoslavia); kludge, sr_CS not supported by ICU 2.6 (3.4 does)
315 { LANGUAGE_SERBIAN_CYRILLIC_MONTENEGRO, "sr", "ME", 0 },
316 { LANGUAGE_OBSOLETE_USER_SERBIAN_CYRILLIC_MONTENEGRO, "sr", "ME", 0 },
317 { LANGUAGE_SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "sr", "BA", 0 },
318 { LANGUAGE_SERBIAN_CYRILLIC_LSO, "sr", "" , 0 },
319 { LANGUAGE_SERBIAN_LATIN_SERBIA, "sh", "RS", kSAME }, // legacy kludge, is sr-Latn-RS now
320 { LANGUAGE_OBSOLETE_USER_SERBIAN_LATIN_SERBIA, "sh", "RS", kSAME }, // legacy kludge, is sr-Latn-RS now
321 { LANGUAGE_SERBIAN_LATIN_SAM, "sh", "CS", kSAME }, // legacy kludge, is sr-Latn-CS now
322 { LANGUAGE_SERBIAN_LATIN_SAM, "sh", "YU", kSAME }, // legacy kludge, is sr-Latn-YU now
323 { LANGUAGE_SERBIAN_LATIN_MONTENEGRO, "sh", "ME", kSAME }, // legacy kludge, is sr-Latn-ME now
324 { LANGUAGE_OBSOLETE_USER_SERBIAN_LATIN_MONTENEGRO, "sh", "ME", kSAME }, // legacy kludge, is sr-Latn-ME now
325 { LANGUAGE_SERBIAN_LATIN_BOSNIA_HERZEGOVINA, "sh", "BA", kSAME }, // legacy kludge, is sr-Latn-BA now
326 { LANGUAGE_SERBIAN_LATIN_LSO, "sh", "" , kSAME }, // legacy kludge, is sr-Latn now
327 { LANGUAGE_ARMENIAN, "hy", "AM", 0 },
328 { LANGUAGE_AZERI_LATIN, "az", "AZ", 0 }, // macrolanguage code
329 { LANGUAGE_UZBEK_LATIN, "uz", "UZ", 0 }, // macrolanguage code
330 { LANGUAGE_UZBEK_LATIN_LSO, "uz", "" , 0 }, // macrolanguage code
331 { LANGUAGE_BENGALI_BANGLADESH, "bn", "BD", 0 },
332 { LANGUAGE_BENGALI, "bn", "IN", 0 },
333 { LANGUAGE_BURMESE, "my", "MM", 0 },
334 { LANGUAGE_KAZAKH, "kk", "KZ", 0 },
335 { LANGUAGE_ENGLISH_INDIA, "en", "IN", 0 },
336 { LANGUAGE_URDU_INDIA, "ur", "IN", 0 },
337 { LANGUAGE_URDU_PAKISTAN, "ur", "PK", 0 },
338 { LANGUAGE_HINDI, "hi", "IN", 0 },
339 { LANGUAGE_GUJARATI, "gu", "IN", 0 },
340 { LANGUAGE_KANNADA, "kn", "IN", 0 },
341 { LANGUAGE_ASSAMESE, "as", "IN", 0 },
342 { LANGUAGE_KASHMIRI_INDIA, "ks", "IN", 0 },
343 { LANGUAGE_KASHMIRI, "ks", "" , kSAME }, // Kashmiri in "Jammu and Kashmir" ... no ISO3166 code for that
344 { LANGUAGE_MALAYALAM, "ml", "IN", 0 },
345 { LANGUAGE_MANIPURI, "mni", "IN", 0 },
346 { LANGUAGE_MARATHI, "mr", "IN", 0 },
347 { LANGUAGE_KONKANI, "kok", "IN", 0 },
348 { LANGUAGE_NEPALI, "ne", "NP", 0 },
349 { LANGUAGE_NEPALI_INDIA, "ne", "IN", 0 },
350 { LANGUAGE_ORIYA, "or", "IN", 0 },
351 { LANGUAGE_PUNJABI, "pa", "IN", 0 },
352 { LANGUAGE_SANSKRIT, "sa", "IN", 0 },
353 { LANGUAGE_TAMIL, "ta", "IN", 0 },
354 { LANGUAGE_TAMIL_SRI_LANKA, "ta", "LK", 0 },
355 { LANGUAGE_TELUGU, "te", "IN", 0 },
356 { LANGUAGE_PUNJABI_PAKISTAN, "pnb", "PK", 0 },
357 { LANGUAGE_PUNJABI_ARABIC_LSO, "pnb", "" , 0 },
358 { LANGUAGE_PUNJABI_PAKISTAN, "lah", "PK", kSAME }, // macrolanguage code, earlier preferred 'lah' over 'pa' for Western Panjabi, now there is 'pnb'
359 { LANGUAGE_PUNJABI_PAKISTAN, "pa", "PK", kSAME }, // MS maps this to 'pa-Arab-PK', but 'pa'='pan' Eastern Panjabi is not used in PK, only in IN
360 { LANGUAGE_SINDHI_PAKISTAN, "sd", "PK", kSAME }, // Arabic script
361 { LANGUAGE_SINDHI, "sd", "IN", 0 }, // TODO: there's Deva(nagari) and Arab(ic) script, MS maps this to 'sd-Deva-IN'
362 { LANGUAGE_BELARUSIAN, "be", "BY", 0 },
363 { LANGUAGE_CATALAN, "ca", "ES", 0 }, // Spain (default)
364 { LANGUAGE_CATALAN, "ca", "AD", 0 }, // Andorra
365 //LANGUAGE_CATALAN_VALENCIAN ca-ES-valencia Bcp47CountryEntry takes precedence
366 { LANGUAGE_CATALAN_VALENCIAN, "ca", "XV", kSAME }, // XV: ISO 3166 user-assigned; old workaround for UI localization only, in case it escaped to document content
367 { LANGUAGE_CATALAN_VALENCIAN, "qcv", "ES", kSAME }, // qcv: ISO 639-3 reserved-for-local-use; old UI localization quirk only, in case it escaped to document content
368 { LANGUAGE_FRENCH_CAMEROON, "fr", "CM", 0 },
369 { LANGUAGE_FRENCH_COTE_D_IVOIRE, "fr", "CI", 0 },
370 { LANGUAGE_FRENCH_MALI, "fr", "ML", 0 },
371 { LANGUAGE_FRENCH_SENEGAL, "fr", "SN", 0 },
372 { LANGUAGE_FRENCH_ZAIRE, "fr", "CD", 0 }, // Democratic Republic Of Congo
373 { LANGUAGE_FRENCH_MOROCCO, "fr", "MA", 0 },
374 { LANGUAGE_FRENCH_REUNION, "fr", "RE", 0 },
375 { LANGUAGE_FRENCH, "fr", "" , 0 }, // needed as a catcher before other "fr" entries!
376 { LANGUAGE_FRENCH_NORTH_AFRICA, "fr", "" , 0 },
377 { LANGUAGE_FRENCH_WEST_INDIES, "fr", "" , 0 }, // no ISO country code; MS "Neither defined nor reserved"
378 { LANGUAGE_FRISIAN_NETHERLANDS, "fy", "NL", 0 },
379 { LANGUAGE_GAELIC_IRELAND, "ga", "IE", 0 },
380 { LANGUAGE_GAELIC_SCOTLAND, "gd", "GB", 0 },
381 { LANGUAGE_GAELIC_SCOTLAND_LEGACY, "gd", "GB", 0 },
382 { LANGUAGE_GALICIAN, "gl", "ES", 0 },
383 { LANGUAGE_GEORGIAN, "ka", "GE", 0 },
384 { LANGUAGE_KHMER, "km", "KH", 0 },
385 { LANGUAGE_KIRGHIZ, "ky", "KG", 0 },
386 { LANGUAGE_LAO, "lo", "LA", 0 },
387 { LANGUAGE_MALTESE, "mt", "MT", 0 },
388 { LANGUAGE_MONGOLIAN_CYRILLIC_MONGOLIA, "mn", "MN", 0 }, // macrolanguage code; should be khk-MN; Cyrillic script
389 { LANGUAGE_MONGOLIAN_CYRILLIC_LSO, "mn", "" , 0 }, // macrolanguage code; should be khk; Cyrillic script
390 { LANGUAGE_RUSSIAN_MOLDOVA, "mo", "MD", 0 },
391 { LANGUAGE_SWAHILI, "sw", "KE", 0 },
392 { LANGUAGE_USER_SWAHILI_TANZANIA, "sw", "TZ", 0 },
393 { LANGUAGE_TAJIK, "tg", "TJ", 0 },
394 { LANGUAGE_TAJIK_LSO, "tg", "" , 0 },
395 { LANGUAGE_TIBETAN, "bo", "CN", 0 }, // CN politically correct?
396 { LANGUAGE_USER_TIBETAN_INDIA, "bo", "IN", 0 },
397 { LANGUAGE_USER_TIBETAN_BHUTAN, "bo", "BT", 0 }, // MS reserved, but with the ID error instead
398 { LANGUAGE_DZONGKHA, "dz", "BT", 0 },
399 { LANGUAGE_USER_DZONGKHA_MAP_LONLY, "dz", "" , 0 }, // because of the MS error, see lang.h
400 { LANGUAGE_TURKMEN, "tk", "TM", 0 },
401 { LANGUAGE_WELSH, "cy", "GB", 0 },
402 { LANGUAGE_SESOTHO, "st", "ZA", 0 },
403 { LANGUAGE_SEPEDI, "nso", "ZA", 0 },
404 { LANGUAGE_SEPEDI, "ns", "ZA", kSAME }, // fake "ns" for compatibility with existing OOo1.1.x localization to be able to read those documents
405 { LANGUAGE_TSONGA, "ts", "ZA", 0 },
406 { LANGUAGE_TSWANA, "tn", "ZA", 0 },
407 { LANGUAGE_ENGLISH_SAFRICA, "en", "ZA", 0 },
408 { LANGUAGE_AFRIKAANS, "af", "ZA", 0 },
409 { LANGUAGE_VENDA, "ve", "ZA", 0 }, // default 639-1
410 { LANGUAGE_VENDA, "ven", "ZA", kSAME }, // 639-2 may have been used temporarily since 2004-07-23
411 { LANGUAGE_XHOSA, "xh", "ZA", 0 },
412 { LANGUAGE_ZULU, "zu", "ZA", 0 },
413 // { LANGUAGE_QUECHUA_COLOMBIA, "quc", "CO", 0 }, // MS reserved, and looks wrong, quc would be in Guatemala, not Colombia
414 { LANGUAGE_QUECHUA_ECUADOR, "quz", "EC", 0 }, // MS
415 { LANGUAGE_QUECHUA_ECUADOR, "qu", "EC", kSAME }, // macrolanguage code
416 { LANGUAGE_QUECHUA_PERU, "quz", "PE", 0 }, // MS
417 { LANGUAGE_QUECHUA_PERU, "qu", "PE", kSAME }, // macrolanguage code
418 { LANGUAGE_QUECHUA_BOLIVIA, "qu", "BO", 0 }, // macrolanguage code, TODO instead: quh-BO or qul-BO; MS says quz-BO which is wrong
419 { LANGUAGE_PASHTO, "ps", "AF", 0 },
420 { LANGUAGE_OROMO, "om", "ET", 0 },
421 { LANGUAGE_DHIVEHI, "dv", "MV", 0 },
422 { LANGUAGE_UIGHUR_CHINA, "ug", "CN", 0 },
423 { LANGUAGE_TIGRIGNA_ETHIOPIA, "ti", "ET", 0 },
424 { LANGUAGE_TIGRIGNA_ERITREA, "ti", "ER", 0 },
425 { LANGUAGE_AMHARIC_ETHIOPIA, "am", "ET", 0 },
426 { LANGUAGE_GUARANI_PARAGUAY, "gug", "PY", 0 },
427 { LANGUAGE_HAWAIIAN_UNITED_STATES, "haw", "US", 0 },
428 { LANGUAGE_EDO, "bin", "NG", 0 },
429 { LANGUAGE_FULFULDE_NIGERIA, "fuv", "NG", 0 },
430 { LANGUAGE_FULFULDE_NIGERIA, "ff", "NG", kSAME }, // macrolanguage code
431 { LANGUAGE_FULFULDE_SENEGAL, "ff", "SN", 0 }, // macrolanguage code
432 { LANGUAGE_HAUSA_NIGERIA, "ha", "NG", kSAME },
433 { LANGUAGE_USER_HAUSA_GHANA, "ha", "GH", kSAME },
434 { LANGUAGE_IGBO_NIGERIA, "ig", "NG", 0 },
435 { LANGUAGE_KANURI_NIGERIA, "kr", "NG", 0 },
436 { LANGUAGE_YORUBA, "yo", "NG", 0 },
437 { LANGUAGE_SOMALI, "so", "SO", 0 },
438 { LANGUAGE_PAPIAMENTU, "pap", "AN", 0 },
439 { LANGUAGE_USER_PAPIAMENTU_ARUBA, "pap", "AW", 0 },
440 { LANGUAGE_USER_PAPIAMENTU_CURACAO, "pap", "CW", 0 },
441 { LANGUAGE_USER_PAPIAMENTU_BONAIRE, "pap", "BQ", 0 },
442 { LANGUAGE_ENGLISH_SINGAPORE, "en", "SG", 0 },
443 { LANGUAGE_USER_YIDDISH_US, "yi", "US", 0 },
444 { LANGUAGE_YIDDISH, "yi", "IL", 0 }, // new: old was "ji"
445 { LANGUAGE_YIDDISH, "ji", "IL", kSAME }, // old: new is "yi"
446 { LANGUAGE_SYRIAC, "syr", "TR", 0 }, // "TR" according to http://www.ethnologue.com/show_language.asp?code=SYC
447 { LANGUAGE_SINHALESE_SRI_LANKA, "si", "LK", 0 },
448 { LANGUAGE_CHEROKEE_UNITED_STATES, "chr", "US", kSAME },
449 { LANGUAGE_INUKTITUT_LATIN_CANADA, "iu", "CA", kSAME }, // macrolanguage code
450 { LANGUAGE_INUKTITUT_LATIN_LSO, "iu", "" , kSAME }, // macrolanguage code
451 { LANGUAGE_SAMI_NORTHERN_NORWAY, "se", "NO", 0 },
452 { LANGUAGE_SAMI_INARI, "smn", "FI", 0 },
453 { LANGUAGE_SAMI_INARI_LSO, "smn", "" , 0 },
454 { LANGUAGE_SAMI_LULE_NORWAY, "smj", "NO", 0 },
455 { LANGUAGE_SAMI_LULE_SWEDEN, "smj", "SE", 0 },
456 { LANGUAGE_SAMI_LULE_LSO, "smj", "" , 0 },
457 { LANGUAGE_SAMI_NORTHERN_FINLAND, "se", "FI", 0 },
458 { LANGUAGE_SAMI_NORTHERN_SWEDEN, "se", "SE", 0 },
459 { LANGUAGE_SAMI_SKOLT, "sms", "FI", 0 },
460 { LANGUAGE_SAMI_SKOLT_LSO, "sms", "" , 0 },
461 { LANGUAGE_SAMI_SOUTHERN_NORWAY, "sma", "NO", 0 },
462 { LANGUAGE_SAMI_SOUTHERN_SWEDEN, "sma", "SE", 0 },
463 { LANGUAGE_SAMI_SOUTHERN_LSO, "sma", "" , 0 },
464 { LANGUAGE_USER_SAMI_KILDIN_RUSSIA, "sjd", "RU", 0 },
465 { LANGUAGE_MAPUDUNGUN_CHILE, "arn", "CL", 0 },
466 { LANGUAGE_CORSICAN_FRANCE, "co", "FR", 0 },
467 { LANGUAGE_ALSATIAN_FRANCE, "gsw", "FR", 0 }, // 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.
468 { LANGUAGE_YAKUT_RUSSIA, "sah", "RU", 0 },
469 { LANGUAGE_MOHAWK_CANADA, "moh", "CA", 0 },
470 { LANGUAGE_BASHKIR_RUSSIA, "ba", "RU", 0 },
471 { LANGUAGE_KICHE_GUATEMALA, "qut", "GT", 0 },
472 { LANGUAGE_DARI_AFGHANISTAN, "prs", "AF", 0 },
473 { LANGUAGE_DARI_AFGHANISTAN, "gbz", "AF", kSAME }, // was an error
474 { LANGUAGE_WOLOF_SENEGAL, "wo", "SN", 0 },
475 { LANGUAGE_FILIPINO, "fil", "PH", 0 },
476 { LANGUAGE_USER_TAGALOG, "tl", "PH", 0 },
477 { LANGUAGE_ENGLISH_PHILIPPINES, "en", "PH", 0 },
478 { LANGUAGE_IBIBIO_NIGERIA, "ibb", "NG", 0 },
479 { LANGUAGE_YI, "ii", "CN", 0 },
480 { LANGUAGE_ENGLISH_ARAB_EMIRATES, "en", "AE", 0 }, // MS reserved
481 { LANGUAGE_ENGLISH_BAHRAIN, "en", "BH", 0 }, // MS reserved
482 { LANGUAGE_ENGLISH_EGYPT, "en", "EG", 0 }, // MS reserved
483 { LANGUAGE_ENGLISH_JORDAN, "en", "JO", 0 }, // MS reserved
484 { LANGUAGE_ENGLISH_KUWAIT, "en", "KW", 0 }, // MS reserved
485 { LANGUAGE_ENGLISH_TURKEY, "en", "TR", 0 }, // MS reserved
486 { LANGUAGE_ENGLISH_YEMEN, "en", "YE", 0 }, // MS reserved
487 { LANGUAGE_TAMAZIGHT_LATIN_ALGERIA, "kab", "DZ", 0 }, // In practice Kabyle is the language used for this
488 { LANGUAGE_OBSOLETE_USER_KABYLE, "kab", "DZ", 0 },
489 { LANGUAGE_TAMAZIGHT_LATIN_ALGERIA, "ber", "DZ", kSAME }, // In practice Algeria has standardized on Kabyle as the member of the "ber" collective which gets used there.
490 { LANGUAGE_TAMAZIGHT_TIFINAGH_MOROCCO, "tmz", "MA", kSAME },
491 { LANGUAGE_TAMAZIGHT_MOROCCO, "tmz", "MA", 0 }, // MS reserved
492 { LANGUAGE_TAMAZIGHT_TIFINAGH_MOROCCO, "ber", "MA", kSAME }, // Morocco is officially using Tifinagh for its Berber languages, old kludge to distinguish from LANGUAGE_TAMAZIGHT_LATIN_ALGERIA
493 { LANGUAGE_USER_LATIN_VATICAN, "la", "VA", 0 },
494 { LANGUAGE_OBSOLETE_USER_LATIN, "la", "VA", 0 },
495 { LANGUAGE_LATIN_LSO, "la", "" , 0 },
496 { LANGUAGE_USER_ESPERANTO, "eo", "" , 0 },
497 { LANGUAGE_USER_INTERLINGUA, "ia", "" , 0 },
498 { LANGUAGE_MAORI_NEW_ZEALAND, "mi", "NZ", 0 },
499 { LANGUAGE_OBSOLETE_USER_MAORI, "mi", "NZ", 0 },
500 { LANGUAGE_KINYARWANDA_RWANDA, "rw", "RW", 0 },
501 { LANGUAGE_OBSOLETE_USER_KINYARWANDA, "rw", "RW", 0 },
502 { LANGUAGE_UPPER_SORBIAN_GERMANY, "hsb", "DE", 0 }, // 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
503 { LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN,"hsb", "DE", 0 },
504 { LANGUAGE_LOWER_SORBIAN_GERMANY, "dsb", "DE", 0 }, // 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
505 { LANGUAGE_LOWER_SORBIAN_LSO, "dsb", "" , 0 },
506 { LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN,"dsb", "DE", 0 },
507 { LANGUAGE_OCCITAN_FRANCE, "oc", "FR", 0 },
508 { LANGUAGE_OBSOLETE_USER_OCCITAN, "oc", "FR", 0 },
509 { LANGUAGE_USER_KURDISH_TURKEY, "kmr", "TR", kSAME },
510 { LANGUAGE_USER_KURDISH_TURKEY, "ku", "TR", kSAME },
511 { LANGUAGE_USER_KURDISH_SYRIA, "kmr", "SY", kSAME },
512 { LANGUAGE_USER_KURDISH_SYRIA, "ku", "SY", kSAME },
513 { LANGUAGE_KURDISH_ARABIC_IRAQ, "ckb", "IQ", 0 },
514 { LANGUAGE_KURDISH_ARABIC_IRAQ, "ku", "IQ", kSAME },
515 { LANGUAGE_OBSOLETE_USER_KURDISH_IRAQ, "ku", "IQ", LANGUAGE_KURDISH_ARABIC_IRAQ },
516 { LANGUAGE_USER_KURDISH_SOUTHERN_IRAN, "sdh", "IR", 0 },
517 { LANGUAGE_USER_KURDISH_SOUTHERN_IRAQ, "sdh", "IQ", 0 },
518 { LANGUAGE_USER_KURDISH_IRAN, "ckb", "IR", 0 },
519 { LANGUAGE_USER_KURDISH_IRAN, "ku", "IR", kSAME },
520 { LANGUAGE_KURDISH_ARABIC_LSO, "ckb", "" , 0 },
521 { LANGUAGE_USER_SARDINIAN, "sc", "IT", 0 }, // macrolanguage code
522 { LANGUAGE_USER_SARDINIAN_CAMPIDANESE, "sro", "IT", 0 },
523 { LANGUAGE_USER_SARDINIAN_GALLURESE, "sdn", "IT", 0 },
524 { LANGUAGE_USER_SARDINIAN_LOGUDORESE, "src", "IT", 0 },
525 { LANGUAGE_USER_SARDINIAN_SASSARESE, "sdc", "IT", 0 },
526 { LANGUAGE_BRETON_FRANCE, "br", "FR", 0 },
527 { LANGUAGE_OBSOLETE_USER_BRETON, "br", "FR", 0 },
528 { LANGUAGE_KALAALLISUT_GREENLAND, "kl", "GL", 0 },
529 { LANGUAGE_OBSOLETE_USER_KALAALLISUT, "kl", "GL", 0 },
530 { LANGUAGE_USER_SWAZI, "ss", "ZA", 0 },
531 { LANGUAGE_USER_NDEBELE_SOUTH, "nr", "ZA", 0 },
532 { LANGUAGE_TSWANA_BOTSWANA, "tn", "BW", 0 },
533 { LANGUAGE_OBSOLETE_USER_TSWANA_BOTSWANA, "tn", "BW", 0 },
534 { LANGUAGE_USER_MOORE, "mos", "BF", 0 },
535 { LANGUAGE_USER_BAMBARA, "bm", "ML", 0 },
536 { LANGUAGE_USER_AKAN, "ak", "GH", 0 },
537 { LANGUAGE_LUXEMBOURGISH_LUXEMBOURG, "lb", "LU", 0 },
538 { LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH, "lb", "LU", 0 },
539 { LANGUAGE_USER_FRIULIAN, "fur", "IT", 0 },
540 { LANGUAGE_USER_FIJIAN, "fj", "FJ", 0 },
541 { LANGUAGE_USER_AFRIKAANS_NAMIBIA, "af", "NA", 0 },
542 { LANGUAGE_USER_ENGLISH_NAMIBIA, "en", "NA", 0 },
543 { LANGUAGE_USER_WALLOON, "wa", "BE", 0 },
544 { LANGUAGE_USER_COPTIC, "cop", "EG", 0 },
545 { LANGUAGE_USER_GASCON, "gsc", "FR", 0 },
546 { LANGUAGE_USER_GERMAN_BELGIUM, "de", "BE", 0 },
547 { LANGUAGE_USER_CHUVASH, "cv", "RU", 0 },
548 { LANGUAGE_USER_EWE_GHANA, "ee", "GH", 0 },
549 { LANGUAGE_USER_ENGLISH_GHANA, "en", "GH", 0 },
550 { LANGUAGE_USER_SANGO, "sg", "CF", 0 },
551 { LANGUAGE_USER_GANDA, "lg", "UG", 0 },
552 { LANGUAGE_USER_LINGALA_DRCONGO, "ln", "CD", 0 },
553 { LANGUAGE_USER_LOW_GERMAN, "nds", "DE", 0 },
554 { LANGUAGE_USER_HILIGAYNON, "hil", "PH", 0 },
555 { LANGUAGE_USER_ENGLISH_MALAWI, "en", "MW", 0 }, /* en default for MW */
556 { LANGUAGE_USER_NYANJA, "ny", "MW", 0 },
557 { LANGUAGE_USER_KASHUBIAN, "csb", "PL", 0 },
558 { LANGUAGE_USER_SPANISH_CUBA, "es", "CU", 0 },
559 { LANGUAGE_USER_QUECHUA_NORTH_BOLIVIA, "qul", "BO", 0 },
560 { LANGUAGE_USER_QUECHUA_SOUTH_BOLIVIA, "quh", "BO", 0 },
561 { LANGUAGE_USER_BODO_INDIA, "brx", "IN", 0 },
562 { LANGUAGE_USER_DOGRI_INDIA, "dgo", "IN", 0 },
563 { LANGUAGE_USER_MAITHILI_INDIA, "mai", "IN", 0 },
564 { LANGUAGE_USER_SANTALI_INDIA, "sat", "IN", 0 },
565 { LANGUAGE_USER_TETUN, "tet", "ID", 0 },
566 { LANGUAGE_USER_TETUN_TIMOR_LESTE, "tet", "TL", 0 },
567 { LANGUAGE_USER_TOK_PISIN, "tpi", "PG", 0 },
568 { LANGUAGE_USER_SHUSWAP, "shs", "CA", 0 },
569 { LANGUAGE_USER_ANCIENT_GREEK, "grc", "GR", 0 },
570 { LANGUAGE_USER_ASTURIAN, "ast", "ES", 0 },
571 { LANGUAGE_USER_LATGALIAN, "ltg", "LV", 0 },
572 { LANGUAGE_USER_MAORE, "swb", "YT", 0 },
573 { LANGUAGE_USER_BUSHI, "buc", "YT", 0 },
574 { LANGUAGE_USER_TAHITIAN, "ty", "PF", 0 },
575 { LANGUAGE_MALAGASY_PLATEAU, "plt", "MG", 0 },
576 { LANGUAGE_MALAGASY_PLATEAU, "mg", "MG", kSAME },
577 { LANGUAGE_OBSOLETE_USER_MALAGASY_PLATEAU, "plt", "MG", 0 },
578 { LANGUAGE_USER_BAFIA, "ksf", "CM", 0 },
579 { LANGUAGE_USER_GIKUYU, "ki", "KE", 0 },
580 { LANGUAGE_USER_RUSYN_UKRAINE, "rue", "UA", 0 },
581 { LANGUAGE_USER_RUSYN_SLOVAKIA, "rue", "SK", 0 },
582 { LANGUAGE_USER_LIMBU, "lif", "NP", 0 },
583 { LANGUAGE_USER_LOJBAN, "jbo", "" , 0 },
584 { LANGUAGE_USER_HAITIAN, "ht", "HT", 0 },
585 { LANGUAGE_FRENCH_HAITI, "fr", "HT", 0 },
586 { LANGUAGE_USER_BEEMBE, "beq", "CG", 0 },
587 { LANGUAGE_USER_BEKWEL, "bkw", "CG", 0 },
588 { LANGUAGE_USER_KITUBA, "mkw", "CG", 0 },
589 { LANGUAGE_USER_LARI, "ldi", "CG", 0 },
590 { LANGUAGE_USER_MBOCHI, "mdw", "CG", 0 },
591 { LANGUAGE_USER_TEKE_EBOO, "ebo", "CG", 0 },
592 { LANGUAGE_USER_TEKE_IBALI, "tek", "CG", 0 },
593 { LANGUAGE_USER_TEKE_TYEE, "tyx", "CG", 0 },
594 { LANGUAGE_USER_VILI, "vif", "CG", 0 },
595 { LANGUAGE_USER_PORTUGUESE_ANGOLA, "pt", "AO", 0 },
596 { LANGUAGE_USER_MANX, "gv", "GB", 0 },
597 { LANGUAGE_USER_ARAGONESE, "an", "ES", 0 },
598 { LANGUAGE_USER_KEYID, "qtz", "" , 0 }, // key id pseudolanguage used for UI testing
599 { LANGUAGE_USER_PALI_LATIN, "pli", "" , kSAME }, // Pali with Latin script, ISO 639-3 (sigh..) back-compat, Latin is not a default script though..
600 { LANGUAGE_USER_KYRGYZ_CHINA, "ky", "CN", 0 },
601 { LANGUAGE_USER_KOMI_ZYRIAN, "kpv", "RU", 0 },
602 { LANGUAGE_USER_KOMI_PERMYAK, "koi", "RU", 0 },
603 { LANGUAGE_USER_PITJANTJATJARA, "pjt", "AU", 0 },
604 { LANGUAGE_USER_ERZYA, "myv", "RU", 0 },
605 { LANGUAGE_USER_MARI_MEADOW, "mhr", "RU", 0 },
606 { LANGUAGE_USER_KHANTY, "kca", "RU", 0 },
607 { LANGUAGE_USER_LIVONIAN, "liv", "RU", 0 },
608 { LANGUAGE_USER_MOKSHA, "mdf", "RU", 0 },
609 { LANGUAGE_USER_MARI_HILL, "mrj", "RU", 0 },
610 { LANGUAGE_USER_NGANASAN, "nio", "RU", 0 },
611 { LANGUAGE_USER_OLONETS, "olo", "RU", 0 },
612 { LANGUAGE_USER_VEPS, "vep", "RU", 0 },
613 { LANGUAGE_USER_VORO, "vro", "EE", 0 },
614 { LANGUAGE_USER_NENETS, "yrk", "RU", 0 },
615 { LANGUAGE_USER_AKA, "axk", "CF", 0 },
616 { LANGUAGE_USER_AKA_CONGO, "axk", "CG", 0 },
617 { LANGUAGE_USER_DIBOLE, "bvx", "CG", 0 },
618 { LANGUAGE_USER_DOONDO, "dde", "CG", 0 },
619 { LANGUAGE_USER_KAAMBA, "xku", "CG", 0 },
620 { LANGUAGE_USER_KOONGO, "kng", "CD", 0 },
621 { LANGUAGE_USER_KOONGO_CONGO, "kng", "CG", 0 },
622 { LANGUAGE_USER_KUNYI, "njx", "CG", 0 },
623 { LANGUAGE_USER_NGUNGWEL, "ngz", "CG", 0 },
624 { LANGUAGE_USER_NJYEM, "njy", "CM", 0 },
625 { LANGUAGE_USER_NJYEM_CONGO, "njy", "CG", 0 },
626 { LANGUAGE_USER_PUNU, "puu", "GA", 0 },
627 { LANGUAGE_USER_PUNU_CONGO, "puu", "CG", 0 },
628 { LANGUAGE_USER_SUUNDI, "sdj", "CG", 0 },
629 { LANGUAGE_USER_TEKE_KUKUYA, "kkw", "CG", 0 },
630 { LANGUAGE_USER_TSAANGI, "tsa", "CG", 0 },
631 { LANGUAGE_USER_YAKA, "iyx", "CG", 0 },
632 { LANGUAGE_USER_YOMBE, "yom", "CD", 0 },
633 { LANGUAGE_USER_YOMBE_CONGO, "yom", "CG", 0 },
634 { LANGUAGE_USER_SIDAMA, "sid", "ET", 0 },
635 { LANGUAGE_USER_NKO, "nqo", "GN", 0 },
636 { LANGUAGE_USER_UDMURT, "udm", "RU", 0 },
637 { LANGUAGE_USER_CORNISH, "kw", "UK", 0 },
638 { LANGUAGE_USER_SAMI_PITE_SWEDEN, "sje", "SE", 0 },
639 { LANGUAGE_USER_NGAEBERE, "gym", "PA", 0 },
640 { LANGUAGE_USER_KUMYK, "kum", "RU", 0 },
641 { LANGUAGE_USER_NOGAI, "nog", "RU", 0 },
642 { LANGUAGE_USER_LADIN, "lld", "IT", 0 },
643 { LANGUAGE_USER_FRENCH_BURKINA_FASO, "fr", "BF", 0 },
644 { LANGUAGE_USER_PUINAVE, "pui", "CO", 0 },
645 { LANGUAGE_MULTIPLE, "mul", "" , 0 }, // multiple languages, many languages are used
646 { LANGUAGE_UNDETERMINED, "und", "" , 0 }, // undetermined language, language cannot be identified
647 { LANGUAGE_NONE, "zxx", "" , 0 }, // added to ISO 639-2 on 2006-01-11: Used to declare the absence of linguistic information
648 { LANGUAGE_DONTKNOW, "", "" , 0 } // marks end of table
651 static IsoLanguageScriptCountryEntry const aImplIsoLangScriptEntries[] =
653 // MS-LangID, ISO639-ISO15924, ISO3166, override
654 { LANGUAGE_SERBIAN_LATIN_SERBIA, "sr-Latn", "RS", 0 },
655 { LANGUAGE_OBSOLETE_USER_SERBIAN_LATIN_SERBIA, "sr-Latn", "RS", 0 },
656 { LANGUAGE_SERBIAN_LATIN_MONTENEGRO, "sr-Latn", "ME", 0 },
657 { LANGUAGE_OBSOLETE_USER_SERBIAN_LATIN_MONTENEGRO,"sr-Latn", "ME", 0 },
658 { LANGUAGE_SERBIAN_LATIN_BOSNIA_HERZEGOVINA, "sr-Latn", "BA", 0 },
659 { LANGUAGE_SERBIAN_LATIN_SAM, "sr-Latn", "CS", 0 }, // Serbian Latin in Serbia and Montenegro; note that not all applications may know about the 'CS' reusage mess, see https://en.wikipedia.org/wiki/ISO_3166-2:CS
660 { LANGUAGE_SERBIAN_LATIN_SAM, "sr-Latn", "YU", 0 }, // legacy Serbian Latin in Yugoslavia
661 { LANGUAGE_SERBIAN_LATIN_LSO, "sr-Latn", "" , 0 },
662 { LANGUAGE_SERBIAN_LATIN_NEUTRAL, "sr-Latn", "" , 0 }, // MS lists this as 'sr' only, what a mess
663 { LANGUAGE_SERBIAN_CYRILLIC_SERBIA, "sr-Cyrl", "RS", kSAME }, // MS
664 { LANGUAGE_SERBIAN_CYRILLIC_MONTENEGRO, "sr-Cyrl", "ME", kSAME }, // MS
665 { LANGUAGE_SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "sr-Cyrl", "BA", kSAME }, // MS
666 { LANGUAGE_SERBIAN_CYRILLIC_SAM, "sr-Cyrl", "CS", kSAME }, // MS
667 { LANGUAGE_SERBIAN_CYRILLIC_LSO, "sr-Cyrl", "" , kSAME }, // MS
668 { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "bs-Cyrl", "BA", 0 },
669 { LANGUAGE_BOSNIAN_CYRILLIC_LSO, "bs-Cyrl", "" , 0 },
670 { LANGUAGE_AZERI_CYRILLIC, "az-Cyrl", "AZ", 0 }, // macrolanguage code
671 { LANGUAGE_AZERI_CYRILLIC_LSO, "az-Cyrl", "" , 0 }, // macrolanguage code
672 { LANGUAGE_UZBEK_CYRILLIC, "uz-Cyrl", "UZ", 0 }, // macrolanguage code
673 { LANGUAGE_UZBEK_CYRILLIC_LSO, "uz-Cyrl", "" , 0 }, // macrolanguage code
674 { LANGUAGE_MONGOLIAN_CYRILLIC_MONGOLIA, "mn-Cyrl", "MN", 0 }, // macrolanguage code; should be khk-MN or khk-Cyrl-MN
675 { LANGUAGE_MONGOLIAN_CYRILLIC_LSO, "mn-Cyrl", "" , 0 }, // macrolanguage code; MS, should be khk or khk-Cyrl
676 { LANGUAGE_MONGOLIAN_MONGOLIAN_MONGOLIA, "mn-Mong", "MN", 0 }, // macrolanguage code; MS, should be khk-Mong-MN
677 { LANGUAGE_MONGOLIAN_MONGOLIAN_CHINA, "mn-Mong", "CN", 0 }, // macrolanguage code; MS, should actually be mvf-CN
678 { LANGUAGE_MONGOLIAN_MONGOLIAN_LSO, "mn-Mong", "" , 0 }, // macrolanguage code
679 { LANGUAGE_USER_PALI_LATIN, "pi-Latn", "" , 0 },
680 { LANGUAGE_USER_KARAKALPAK_LATIN, "kaa-Latn", "UZ", 0 },
681 { LANGUAGE_TAJIK, "tg-Cyrl", "TJ", 0 }, // MS
682 { LANGUAGE_TAJIK_LSO, "tg-Cyrl", "" , 0 }, // MS
683 { LANGUAGE_AZERI_LATIN, "az-Latn", "AZ", 0 }, // macrolanguage code; MS
684 { LANGUAGE_AZERI_LATIN_LSO, "az-Latn", "" , 0 }, // macrolanguage code; MS
685 { LANGUAGE_USER_YIDDISH_US, "yi-Hebr", "US", kSAME }, // macrolanguage code; MS, Hebr is suppress-script
686 { LANGUAGE_YIDDISH, "yi-Hebr", "IL", kSAME }, // macrolanguage code; MS, Hebr is suppress-script
687 { LANGUAGE_UZBEK_LATIN, "uz-Latn", "UZ", 0 }, // macrolanguage code
688 { LANGUAGE_UZBEK_LATIN_LSO, "uz-Latn", "" , 0 },
689 // { LANGUAGE_SINDHI, "sd-Deva", "IN", 0 }, // MS, TODO: see comment above in aImplIsoLangEntries
690 { LANGUAGE_SINDHI_PAKISTAN, "sd-Arab", "PK", 0 }, // MS
691 { LANGUAGE_SINDHI_ARABIC_LSO, "sd-Arab", "" , 0 },
692 { LANGUAGE_CHEROKEE_UNITED_STATES, "chr-Cher", "US", 0 }, // MS
693 { LANGUAGE_CHEROKEE_CHEROKEE_LSO, "chr-Cher", "" , 0 },
694 { LANGUAGE_INUKTITUT_SYLLABICS_CANADA, "iu-Cans", "CA", 0 }, // macrolanguage code, MS
695 { LANGUAGE_INUKTITUT_SYLLABICS_LSO, "iu-Cans", "" , 0 }, // macrolanguage code, MS
696 { LANGUAGE_INUKTITUT_LATIN_CANADA, "iu-Latn", "CA", 0 }, // macrolanguage code, MS
697 { LANGUAGE_INUKTITUT_LATIN_LSO, "iu-Latn", "" , 0 }, // macrolanguage code, MS
698 { LANGUAGE_TAMAZIGHT_TIFINAGH_MOROCCO, "tzm-Tfng", "MA", 0 },
699 { LANGUAGE_TAMAZIGHT_TIFINAGH_LSO, "tzm-Tfng", "" , 0 },
700 { LANGUAGE_KASHMIRI_INDIA, "ks-Deva", "IN", 0 }, // MS
701 { LANGUAGE_KASHMIRI, "ks-Arab", "" , 0 }, // MS, Kashmiri in "Jammu and Kashmir" ... no ISO3166 code for that
702 { LANGUAGE_HAUSA_NIGERIA, "ha-Latn", "NG", 0 }, // MS
703 { LANGUAGE_USER_HAUSA_GHANA, "ha-Latn", "GH", 0 },
704 { LANGUAGE_HAUSA_LATIN_LSO, "ha-Latn", "" , 0 },
705 { LANGUAGE_LATIN_LSO, "la-Latn", "" , kSAME }, // MS, though Latn is suppress-script
706 { LANGUAGE_TAI_NUA_CHINA, "tdd-Tale", "CN", 0 }, // MS reserved
707 { LANGUAGE_LU_CHINA, "khb-Talu", "CN", 0 }, // MS reserved
708 { LANGUAGE_KURDISH_ARABIC_IRAQ, "ku-Arab", "IQ", kSAME }, // macrolanguage code, MS
709 { LANGUAGE_KURDISH_ARABIC_LSO, "ku-Arab", "" , kSAME }, // macrolanguage code, MS
710 { LANGUAGE_USER_KURDISH_TURKEY, "kmr-Latn", "TR", 0 },
711 { LANGUAGE_USER_KURDISH_SYRIA, "kmr-Latn", "SY", 0 },
712 { LANGUAGE_PUNJABI_PAKISTAN, "pnb-Arab", "PK", 0 },
713 { LANGUAGE_PUNJABI_ARABIC_LSO, "pnb-Arab", "" , 0 },
714 { LANGUAGE_PUNJABI_PAKISTAN, "pa-Arab", "PK", 0 }, // MS, incorrect
715 { LANGUAGE_PUNJABI_ARABIC_LSO, "pa-Arab", "" , 0 }, // MS, incorrect
716 { LANGUAGE_TAMAZIGHT_LATIN_ALGERIA, "tzm-Latn", "DZ", kSAME }, // MS
717 { LANGUAGE_TAMAZIGHT_LATIN_LSO, "tzm-Latn", "" , 0 }, // MS
718 { LANGUAGE_FULFULDE_SENEGAL, "ff-Latn", "SN", 0 }, // macrolanguage code, MS
719 { LANGUAGE_FULFULDE_LATIN_LSO, "ff-Latn", "" , 0 }, // macrolanguage code
720 { LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA, "bs-Latn", "BA", kSAME }, // MS, though Latn is suppress-script
721 { LANGUAGE_BOSNIAN_LATIN_LSO, "bs-Latn", "" , LANGUAGE_BOSNIAN_LSO }, // MS, though Latn is suppress-script
722 { LANGUAGE_CHINESE_TRADITIONAL_LSO, "zh-Hant", "" , 0 },
723 { LANGUAGE_DONTKNOW, "", "" , 0 } // marks end of table
726 static Bcp47CountryEntry const aImplBcp47CountryEntries[] =
728 // MS-LangID full BCP47, ISO3166, ISO639-Variant or other fallback
729 { LANGUAGE_CATALAN_VALENCIAN, "ca-ES-valencia", "ES", "ca-valencia" },
730 { LANGUAGE_OBSOLETE_USER_CATALAN_VALENCIAN, "ca-ES-valencia", "ES", "" }, // In case MS format files using the old value escaped into the wild, map them back.
731 { LANGUAGE_USER_ENGLISH_UK_OED, "en-GB-oed", "GB", "" }, // grandfathered
732 // { LANGUAGE_YUE_CHINESE_HONGKONG, "zh-yue-HK", "HK", "" }, // MS reserved, prefer yue-HK; do not add unless LanguageTag::simpleExtract() can handle it to not call liblangtag for rsc!
733 { LANGUAGE_DONTKNOW, "", "", "" } // marks end of table
736 static IsoLanguageCountryEntry aLastResortFallbackEntry =
737 { LANGUAGE_ENGLISH_US, "en", "US", false };
739 OUString IsoLanguageCountryEntry::getTagString() const
741 if (maCountry[0])
742 return OUString( OUString::createFromAscii( maLanguage) + "-" + OUString::createFromAscii( maCountry));
743 else
744 return OUString::createFromAscii( maLanguage);
747 ::com::sun::star::lang::Locale IsoLanguageCountryEntry::getLocale() const
749 return lang::Locale( OUString::createFromAscii( maLanguage), OUString::createFromAscii( maCountry), OUString());
752 OUString IsoLanguageScriptCountryEntry::getTagString() const
754 if (maCountry[0])
755 return OUString( OUString::createFromAscii( maLanguageScript) + "-" + OUString::createFromAscii( maCountry));
756 else
757 return OUString::createFromAscii( maLanguageScript);
760 ::com::sun::star::lang::Locale IsoLanguageScriptCountryEntry::getLocale() const
762 return lang::Locale( I18NLANGTAG_QLT, OUString::createFromAscii( maCountry), getTagString());
765 bool IsoLanguageScriptCountryEntry::startsInIgnoreAsciiCase( const OUString & rStr ) const
767 return rStr.matchIgnoreAsciiCaseAsciiL( maLanguageScript, strlen( maLanguageScript), 0);
770 OUString Bcp47CountryEntry::getTagString() const
772 return OUString::createFromAscii( mpBcp47);
775 ::com::sun::star::lang::Locale Bcp47CountryEntry::getLocale() const
777 return lang::Locale( I18NLANGTAG_QLT, OUString::createFromAscii( maCountry), getTagString());
780 // -----------------------------------------------------------------------
782 // In this table are the countries which should mapped to a specific
783 // english language
784 static IsoLangEngEntry const aImplIsoLangEngEntries[] =
786 { LANGUAGE_ENGLISH_UK, "AO" }, // Angola
787 { LANGUAGE_ENGLISH_UK, "BJ" }, // Benin
788 { LANGUAGE_ENGLISH_UK, "BW" }, // Botswana
789 { LANGUAGE_ENGLISH_UK, "BI" }, // Burundi
790 { LANGUAGE_ENGLISH_UK, "CM" }, // Cameroon
791 { LANGUAGE_ENGLISH_UK, "GA" }, // Gabon
792 { LANGUAGE_ENGLISH_UK, "GM" }, // Gambia
793 { LANGUAGE_ENGLISH_UK, "GH" }, // Ghana
794 { LANGUAGE_ENGLISH_UK, "GN" }, // Guinea
795 { LANGUAGE_ENGLISH_UK, "LS" }, // Lesotho
796 { LANGUAGE_ENGLISH_UK, "MW" }, // Malawi
797 { LANGUAGE_ENGLISH_UK, "MT" }, // Malta
798 { LANGUAGE_ENGLISH_UK, "NA" }, // Namibia
799 { LANGUAGE_ENGLISH_UK, "NG" }, // Nigeria
800 { LANGUAGE_ENGLISH_UK, "UG" }, // Uganda
801 { LANGUAGE_ENGLISH_UK, "ZM" }, // Zambia
802 { LANGUAGE_ENGLISH_UK, "ZW" }, // Zimbabwe
803 { LANGUAGE_ENGLISH_UK, "SZ" }, // Swaziland
804 { LANGUAGE_ENGLISH_UK, "NG" }, // Sierra Leone
805 { LANGUAGE_ENGLISH_UK, "KN" }, // Saint Kitts and Nevis
806 { LANGUAGE_ENGLISH_UK, "SH" }, // St. Helena
807 { LANGUAGE_ENGLISH_UK, "IO" }, // British Indian Oceanic Territory
808 { LANGUAGE_ENGLISH_UK, "FK" }, // Falkland Islands
809 { LANGUAGE_ENGLISH_UK, "GI" }, // Gibraltar
810 { LANGUAGE_ENGLISH_UK, "KI" }, // Kiribati
811 { LANGUAGE_ENGLISH_UK, "VG" }, // Virgin Islands
812 { LANGUAGE_ENGLISH_UK, "MU" }, // Mauritius
813 { LANGUAGE_ENGLISH_UK, "FJ" }, // Fiji
814 { LANGUAGE_ENGLISH_US, "KI" }, // Kiribati
815 { LANGUAGE_ENGLISH_US, "LR" }, // Liberia
816 { LANGUAGE_ENGLISH_US, "GU" }, // Guam
817 { LANGUAGE_ENGLISH_US, "MH" }, // Marshall Islands
818 { LANGUAGE_ENGLISH_US, "PW" }, // Palau
819 { LANGUAGE_ENGLISH_CARRIBEAN, "AI" }, // Anguilla
820 { LANGUAGE_ENGLISH_CARRIBEAN, "AG" }, // Antigua and Barbuda
821 { LANGUAGE_ENGLISH_CARRIBEAN, "BS" }, // Bahamas
822 { LANGUAGE_ENGLISH_CARRIBEAN, "BB" }, // Barbedos
823 { LANGUAGE_ENGLISH_CARRIBEAN, "BM" }, // Bermuda
824 { LANGUAGE_ENGLISH_CARRIBEAN, "KY" }, // Cayman Islands
825 { LANGUAGE_ENGLISH_CARRIBEAN, "GD" }, // Grenada
826 { LANGUAGE_ENGLISH_CARRIBEAN, "DM" }, // Dominica
827 { LANGUAGE_ENGLISH_CARRIBEAN, "HT" }, // Haiti
828 { LANGUAGE_ENGLISH_CARRIBEAN, "MS" }, // Montserrat
829 { LANGUAGE_ENGLISH_CARRIBEAN, "FM" }, // Micronesia
830 { LANGUAGE_ENGLISH_CARRIBEAN, "VC" }, // St. Vincent / Grenadines
831 { LANGUAGE_ENGLISH_CARRIBEAN, "LC" }, // Saint Lucia
832 { LANGUAGE_ENGLISH_CARRIBEAN, "TC" }, // Turks & Caicos Islands
833 { LANGUAGE_ENGLISH_CARRIBEAN, "GY" }, // Guyana
834 { LANGUAGE_ENGLISH_CARRIBEAN, "TT" }, // Trinidad and Tobago
835 { LANGUAGE_ENGLISH_AUS, "CX" }, // Christmas Islands
836 { LANGUAGE_ENGLISH_AUS, "CC" }, // Cocos (Keeling) Islands
837 { LANGUAGE_ENGLISH_AUS, "NF" }, // Norfolk Island
838 { LANGUAGE_ENGLISH_AUS, "PG" }, // Papua New Guinea
839 { LANGUAGE_ENGLISH_AUS, "SB" }, // Solomon Islands
840 { LANGUAGE_ENGLISH_AUS, "TV" }, // Tuvalu
841 { LANGUAGE_ENGLISH_AUS, "NR" }, // Nauru
842 { LANGUAGE_ENGLISH_NZ, "CK" }, // Cook Islands
843 { LANGUAGE_ENGLISH_NZ, "NU" }, // Niue
844 { LANGUAGE_ENGLISH_NZ, "TK" }, // Tokelau
845 { LANGUAGE_ENGLISH_NZ, "TO" }, // Tonga
846 { LANGUAGE_DONTKNOW, "" } // marks end of table
849 // -----------------------------------------------------------------------
851 static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries[] =
853 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "BOK" }, // registered subtags for "no" in rfc1766
854 { LANGUAGE_NORWEGIAN_NYNORSK, "no", "NYN" }, // registered subtags for "no" in rfc1766
855 { LANGUAGE_SERBIAN_LATIN_SAM, "sr", "latin" },
856 { LANGUAGE_SERBIAN_CYRILLIC_SAM, "sr", "cyrillic" },
857 { LANGUAGE_AZERI_LATIN, "az", "latin" },
858 { LANGUAGE_AZERI_CYRILLIC, "az", "cyrillic" },
859 { LANGUAGE_DONTKNOW, "", "" } // marks end of table
862 // -----------------------------------------------------------------------
864 // in this table are only names to find the best language
865 static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries2[] =
867 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmaal" },
868 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmal" },
869 { LANGUAGE_NORWEGIAN_NYNORSK, "no", "nynorsk" },
870 { LANGUAGE_DONTKNOW, "", "" } // marks end of table
873 // -----------------------------------------------------------------------
875 // in this table are only names to find the best language
876 static IsoLangOtherEntry const aImplOtherEntries[] =
878 { LANGUAGE_ENGLISH_US, "c" },
879 { LANGUAGE_CHINESE, "chinese" },
880 { LANGUAGE_GERMAN, "german" },
881 { LANGUAGE_JAPANESE, "japanese" },
882 { LANGUAGE_KOREAN, "korean" },
883 { LANGUAGE_ENGLISH_US, "posix" },
884 { LANGUAGE_CHINESE_TRADITIONAL, "tchinese" },
885 { LANGUAGE_DONTKNOW, NULL } // marks end of table
889 // in this table are only privateuse names
890 static IsoLangOtherEntry const aImplPrivateUseEntries[] =
892 { LANGUAGE_USER_PRIV_NOTRANSLATE, "x-no-translate" }, //! not BCP47 but legacy in .xcu configmgr
893 { LANGUAGE_USER_PRIV_DEFAULT, "x-default" },
894 { LANGUAGE_USER_PRIV_COMMENT, "x-comment" },
895 { LANGUAGE_USER_PRIV_JOKER, "*" }, //! not BCP47 but transferable in configmgr
896 { LANGUAGE_DONTKNOW, NULL } // marks end of table
899 // =======================================================================
901 // static
902 void MsLangId::Conversion::convertLanguageToLocaleImpl( LanguageType nLang,
903 ::com::sun::star::lang::Locale & rLocale, bool bIgnoreOverride )
905 const IsoLanguageScriptCountryEntry* pScriptEntryOverride = NULL;
906 const IsoLanguageCountryEntry* pEntryOverride = NULL;
908 Label_Override_Lang_Locale:
910 // Search for LangID in BCP47
911 for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
912 pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
914 if (pBcp47Entry->mnLang == nLang)
916 rLocale.Language = I18NLANGTAG_QLT;
917 rLocale.Country = OUString::createFromAscii( pBcp47Entry->maCountry);
918 rLocale.Variant = pBcp47Entry->getTagString();
919 return;
923 // Search for LangID in ISO lll-Ssss-CC
924 for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
925 pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
927 if (pScriptEntry->mnLang == nLang)
929 if (bIgnoreOverride || !pScriptEntry->mnOverride)
931 rLocale.Language = I18NLANGTAG_QLT;
932 rLocale.Country = OUString::createFromAscii( pScriptEntry->maCountry);
933 rLocale.Variant = pScriptEntry->getTagString();
934 return;
936 else if (pScriptEntry->mnOverride && pScriptEntryOverride != pScriptEntry)
938 pScriptEntryOverride = pScriptEntry;
939 nLang = getOverrideLang( pScriptEntry->mnLang, pScriptEntry->mnOverride);
940 goto Label_Override_Lang_Locale;
945 // Search for LangID in ISO lll-CC
946 for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
947 pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
949 if (pEntry->mnLang == nLang)
951 if (bIgnoreOverride || !pEntry->mnOverride)
953 rLocale.Language = OUString::createFromAscii( pEntry->maLanguage );
954 rLocale.Country = OUString::createFromAscii( pEntry->maCountry );
955 rLocale.Variant = OUString();
956 return;
958 else if (pEntry->mnOverride && pEntryOverride != pEntry)
960 pEntryOverride = pEntry;
961 nLang = getOverrideLang( pEntry->mnLang, pEntry->mnOverride);
962 goto Label_Override_Lang_Locale;
967 // Look for privateuse definitions.
968 for (const IsoLangOtherEntry* pPrivateEntry = aImplPrivateUseEntries;
969 pPrivateEntry->mnLang != LANGUAGE_DONTKNOW; ++pPrivateEntry)
971 if (pPrivateEntry->mnLang == nLang)
973 rLocale.Language = I18NLANGTAG_QLT;
974 rLocale.Country = OUString();
975 rLocale.Variant = OUString::createFromAscii( pPrivateEntry->mpLanguage );
976 return;
980 // Not found. Passed rLocale argument remains unchanged.
983 // -----------------------------------------------------------------------
985 // static
986 com::sun::star::lang::Locale MsLangId::Conversion::getLocale( const IsoLanguageCountryEntry * pEntry )
988 if (pEntry->mnOverride)
990 lang::Locale aLocale;
991 convertLanguageToLocaleImpl( getOverrideLang( pEntry->mnLang, pEntry->mnOverride), aLocale, false);
992 return aLocale;
994 else
995 return pEntry->getLocale();
998 // static
999 com::sun::star::lang::Locale MsLangId::Conversion::getLocale( const IsoLanguageScriptCountryEntry * pEntry )
1001 if (pEntry->mnOverride)
1003 lang::Locale aLocale;
1004 convertLanguageToLocaleImpl( getOverrideLang( pEntry->mnLang, pEntry->mnOverride), aLocale, false);
1005 return aLocale;
1007 else
1008 return pEntry->getLocale();
1011 // static
1012 ::com::sun::star::lang::Locale MsLangId::Conversion::lookupFallbackLocale(
1013 const ::com::sun::star::lang::Locale & rLocale )
1015 // language is lower case in table
1016 OUString aLowerLang = rLocale.Language.toAsciiLowerCase();
1017 // country is upper case in table
1018 OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
1019 sal_Int32 nCountryLen = aUpperCountry.getLength();
1021 if (rLocale.Language == I18NLANGTAG_QLT)
1023 // Search in BCP47, only full match and one fallback, for other
1024 // fallbacks only LanguageTag can decide.
1025 for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
1026 pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
1028 if ( rLocale.Variant.equalsIgnoreAsciiCase( pBcp47Entry->getTagString()) ||
1029 rLocale.Variant.equalsIgnoreAsciiCaseAscii( pBcp47Entry->mpFallback))
1030 return pBcp47Entry->getLocale();
1033 // Search in ISO lll-Ssss-CC
1034 const IsoLanguageScriptCountryEntry* pFirstScript = NULL;
1035 for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
1036 pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
1038 if (pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
1040 if (rLocale.Variant.equalsIgnoreAsciiCase( pScriptEntry->getTagString()))
1041 return getLocale( pScriptEntry); // may override
1042 if (!pFirstScript)
1043 pFirstScript = pScriptEntry;
1046 // If at least a lll-Ssss matched, try that with country or use it as
1047 // fallback.
1048 if (pFirstScript)
1050 // Check for country only if there is more than lll-Ssss-CC in tag
1051 // string, else we would had matched it already.
1052 if (!aUpperCountry.isEmpty() && rLocale.Variant.getLength() > 11)
1054 for (const IsoLanguageScriptCountryEntry* pScriptEntry = pFirstScript;
1055 pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
1057 if (aUpperCountry.equalsAscii( pScriptEntry->maCountry) &&
1058 pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
1059 return getLocale( pScriptEntry); // may override
1062 return getLocale( pFirstScript); // may override
1065 // Extract language from tag string, country is used as present in
1066 // Locale because in the tables that follow we have only ISO 3166
1067 // countries and if that is in the tag string we also have it in the
1068 // Locale.
1069 sal_Int32 nIndex = 0;
1070 aLowerLang = rLocale.Variant.getToken( 0, '-', nIndex).toAsciiLowerCase();
1071 // Nothing with "x-..." or "i-..." or any 1 letter in lll-CC table that
1072 // follows.
1073 if (aLowerLang.getLength() == 1)
1074 return aLastResortFallbackEntry.getLocale();
1077 // Search for locale and remember first lang-only.
1078 const IsoLanguageCountryEntry* pFirstLang = NULL;
1079 const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
1080 for ( ; pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1082 if (aLowerLang.equalsAscii( pEntry->maLanguage))
1084 if (*pEntry->maCountry)
1086 if (nCountryLen && aUpperCountry.equalsAscii( pEntry->maCountry))
1087 return getLocale( pEntry); // may override
1089 else
1091 switch (pEntry->mnLang)
1093 // These are known to have no country assigned.
1094 case LANGUAGE_BASQUE:
1095 case LANGUAGE_USER_ESPERANTO:
1096 case LANGUAGE_USER_INTERLINGUA:
1097 case LANGUAGE_USER_LOJBAN:
1098 case LANGUAGE_KASHMIRI:
1099 case LANGUAGE_USER_KEYID:
1100 return getLocale( pEntry); // may override
1101 default:
1102 ; // nothing
1105 if (!pFirstLang)
1106 pFirstLang = pEntry;
1110 // Language not found at all => use default.
1111 if (!pFirstLang)
1112 return aLastResortFallbackEntry.getLocale();
1114 // Search for first entry of language with any country.
1115 pEntry = pFirstLang;
1116 for ( ; pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1118 if (aLowerLang.equalsAscii( pEntry->maLanguage))
1120 if (*pEntry->maCountry)
1121 return getLocale( pEntry); // may override
1125 return aLastResortFallbackEntry.getLocale();
1128 // =======================================================================
1130 // static
1131 LanguageType MsLangId::Conversion::convertPrivateUseToLanguage( const OUString& rPriv )
1133 for (const IsoLangOtherEntry* pPrivateEntry = aImplPrivateUseEntries;
1134 pPrivateEntry->mnLang != LANGUAGE_DONTKNOW; ++pPrivateEntry)
1136 if ( rPriv.equalsIgnoreAsciiCaseAscii( pPrivateEntry->mpLanguage ) )
1137 return pPrivateEntry->mnLang;
1139 return LANGUAGE_DONTKNOW;
1143 // static
1144 LanguageType MsLangId::Conversion::convertLocaleToLanguageImpl(
1145 const ::com::sun::star::lang::Locale& rLocale )
1147 if (rLocale.Language == I18NLANGTAG_QLT)
1149 // "x-..." private use and the nasty "*" joker
1150 if (rLocale.Variant.startsWithIgnoreAsciiCase( "x-") || (rLocale.Variant == "*"))
1151 return convertPrivateUseToLanguage( rLocale.Variant);
1153 // Search in BCP47
1154 for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
1155 pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
1157 if (rLocale.Variant.equalsIgnoreAsciiCase( pBcp47Entry->getTagString()))
1158 return pBcp47Entry->mnLang;
1161 // Search in ISO lll-Ssss-CC
1162 for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
1163 pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
1165 if (pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
1167 if (rLocale.Variant.equalsIgnoreAsciiCase( pScriptEntry->getTagString()))
1168 return getOverrideLang( pScriptEntry->mnLang, pScriptEntry->mnOverride);
1172 else
1174 // language is lower case in table
1175 OUString aLowerLang = rLocale.Language.toAsciiLowerCase();
1176 // country is upper case in table
1177 OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
1179 // Search in ISO lll-CC
1180 for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
1181 pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1183 if (aLowerLang.equalsAscii( pEntry->maLanguage) && aUpperCountry.equalsAscii( pEntry->maCountry))
1184 return getOverrideLang( pEntry->mnLang, pEntry->mnOverride);
1187 return LANGUAGE_DONTKNOW;
1191 // static
1192 ::com::sun::star::lang::Locale MsLangId::Conversion::getOverride( const ::com::sun::star::lang::Locale& rLocale )
1194 if (rLocale.Language == I18NLANGTAG_QLT)
1196 // "x-..." private use and the nasty "*" joker
1197 if (rLocale.Variant.startsWithIgnoreAsciiCase( "x-") || (rLocale.Variant == "*"))
1198 return rLocale; // no overrides
1200 // Search in BCP47
1201 for (const Bcp47CountryEntry* pBcp47Entry = aImplBcp47CountryEntries;
1202 pBcp47Entry->mnLang != LANGUAGE_DONTKNOW; ++pBcp47Entry)
1204 if (rLocale.Variant.equalsIgnoreAsciiCase( pBcp47Entry->getTagString()))
1205 return rLocale; // no overrides
1208 // Search in ISO lll-Ssss-CC
1209 for (const IsoLanguageScriptCountryEntry* pScriptEntry = aImplIsoLangScriptEntries;
1210 pScriptEntry->mnLang != LANGUAGE_DONTKNOW; ++pScriptEntry)
1212 if (pScriptEntry->startsInIgnoreAsciiCase( rLocale.Variant))
1214 if (rLocale.Variant.equalsIgnoreAsciiCase( pScriptEntry->getTagString()))
1215 return getLocale( pScriptEntry); // may override
1219 else
1221 // language is lower case in table
1222 OUString aLowerLang = rLocale.Language.toAsciiLowerCase();
1223 // country is upper case in table
1224 OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
1226 // Search in ISO lll-CC
1227 for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
1228 pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1230 if (aLowerLang.equalsAscii( pEntry->maLanguage) && aUpperCountry.equalsAscii( pEntry->maCountry))
1231 return getLocale( pEntry); // may override
1234 return lang::Locale();
1238 // static
1239 LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const OUString& rLang,
1240 const OUString& rCountry )
1242 // language is lower case in table
1243 OUString aLowerLang = rLang.toAsciiLowerCase();
1244 // country is upper case in table
1245 OUString aUpperCountry = rCountry.toAsciiUpperCase();
1247 // first look for exact match
1248 const IsoLanguageCountryEntry* pFirstLang = NULL;
1249 for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
1250 pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1252 if ( aLowerLang.equalsAscii( pEntry->maLanguage ) )
1254 if ( aUpperCountry.isEmpty() ||
1255 aUpperCountry.equalsAscii( pEntry->maCountry ) )
1256 return pEntry->mnLang;
1257 if ( !pFirstLang )
1258 pFirstLang = pEntry;
1259 else if ( !*pEntry->maCountry )
1260 pFirstLang = pEntry;
1264 // some eng countries should be mapped to a specific english language
1265 if ( aLowerLang == "en" )
1267 for (const IsoLangEngEntry* pEngEntry = aImplIsoLangEngEntries;
1268 pEngEntry->mnLang != LANGUAGE_DONTKNOW; ++pEngEntry)
1270 if ( aUpperCountry.equalsAscii( pEngEntry->maCountry ) )
1271 return pEngEntry->mnLang;
1275 // test for specific languages which are not used standard ISO 3166 codes
1276 for (const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
1277 pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW; ++pNoneStdEntry)
1279 if ( aLowerLang.equalsAscii( pNoneStdEntry->maLanguage ) )
1281 // The countries in this table are not all in upper case
1282 if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) )
1283 return pNoneStdEntry->mnLang;
1286 for (const IsoLangNoneStdEntry* pNoneStdEntry2 = aImplIsoNoneStdLangEntries2;
1287 pNoneStdEntry2->mnLang != LANGUAGE_DONTKNOW; ++pNoneStdEntry2)
1289 if ( aLowerLang.equalsAscii( pNoneStdEntry2->maLanguage ) )
1291 // The countries in this table are not all in upper case
1292 if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry2->maCountry ) )
1293 return pNoneStdEntry2->mnLang;
1297 // If the language is correct, then we return the default language
1298 if ( pFirstLang )
1299 return pFirstLang->mnLang;
1301 // if only the country is set, look for any entry matching the country
1302 // (to allow reading country and language in separate steps, in any order)
1303 if ( !rCountry.isEmpty() && rLang.isEmpty() )
1305 for (const IsoLanguageCountryEntry* pEntry2 = aImplIsoLangEntries;
1306 pEntry2->mnLang != LANGUAGE_DONTKNOW; ++pEntry2)
1308 if ( aUpperCountry.equalsAscii( pEntry2->maCountry ) )
1309 return pEntry2->mnLang;
1312 aLowerLang = aUpperCountry.toAsciiLowerCase();
1315 // Look for privateuse definitions.
1316 LanguageType nLang = convertPrivateUseToLanguage( aLowerLang);
1317 if (nLang != LANGUAGE_DONTKNOW)
1318 return nLang;
1320 // Now look for all other definitions, which are not standard
1321 for (const IsoLangOtherEntry* pOtherEntry = aImplOtherEntries;
1322 pOtherEntry->mnLang != LANGUAGE_DONTKNOW; ++pOtherEntry)
1324 if ( aLowerLang.equalsAscii( pOtherEntry->mpLanguage ) )
1325 return pOtherEntry->mnLang;
1328 return LANGUAGE_DONTKNOW;
1331 // -----------------------------------------------------------------------
1333 // static
1334 LanguageType MsLangId::Conversion::convertIsoNamesToLanguage( const OString& rLang,
1335 const OString& rCountry )
1337 OUString aLang = OStringToOUString( rLang, RTL_TEXTENCODING_ASCII_US);
1338 OUString aCountry = OStringToOUString( rCountry, RTL_TEXTENCODING_ASCII_US);
1339 return convertIsoNamesToLanguage( aLang, aCountry);
1342 // -----------------------------------------------------------------------
1344 struct IsoLangGLIBCModifiersEntry
1346 LanguageType mnLang;
1347 sal_Char maLanguage[4];
1348 sal_Char maCountry[3];
1349 sal_Char maAtString[9];
1352 static IsoLangGLIBCModifiersEntry const aImplIsoLangGLIBCModifiersEntries[] =
1354 // MS-LANGID codes ISO639-1/2/3 ISO3166 glibc modifier
1355 { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "bs", "BA", "cyrillic" },
1356 { LANGUAGE_USER_SERBIAN_LATIN_SERBIA, "sr", "RS", "latin" }, // Serbian Latin in Serbia
1357 { LANGUAGE_SERBIAN_LATIN_SAM, "sr", "CS", "latin" }, // Serbian Latin in Serbia and Montenegro
1358 { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO, "sr", "ME", "latin" }, // Serbian Latin in Montenegro
1359 { LANGUAGE_SERBIAN_LATIN_LSO, "sr", "", "latin" },
1360 { LANGUAGE_AZERI_CYRILLIC, "az", "AZ", "cyrillic" },
1361 { LANGUAGE_UZBEK_CYRILLIC, "uz", "UZ", "cyrillic" },
1362 { LANGUAGE_DONTKNOW, "", "", "" } // marks end of table
1365 // convert a unix locale string into LanguageType
1367 // static
1368 LanguageType MsLangId::convertUnxByteStringToLanguage(
1369 const OString& rString )
1371 OString aLang;
1372 OString aCountry;
1373 OString aAtString;
1375 sal_Int32 nLangSepPos = rString.indexOf( (sal_Char)'_' );
1376 sal_Int32 nCountrySepPos = rString.indexOf( (sal_Char)'.' );
1377 sal_Int32 nAtPos = rString.indexOf( (sal_Char)'@' );
1379 if (nCountrySepPos < 0)
1380 nCountrySepPos = nAtPos;
1381 if (nCountrySepPos < 0)
1382 nCountrySepPos = rString.getLength();
1384 if (nAtPos >= 0)
1385 aAtString = rString.copy( nAtPos+1 );
1387 if (((nLangSepPos >= 0) && (nLangSepPos > nCountrySepPos)) || (nLangSepPos < 0))
1389 // eg. "el.sun_eu_greek", "tchinese", "es.ISO8859-15"
1390 aLang = rString.copy( 0, nCountrySepPos );
1392 else if ( nLangSepPos >= 0 )
1394 // well formed iso names like "en_US.UTF-8", "sh_BA.ISO8859-2@bosnia"
1395 aLang = rString.copy( 0, nLangSepPos );
1396 aCountry = rString.copy( nLangSepPos+1, nCountrySepPos - nLangSepPos - 1);
1399 // if there is a glibc modifier, first look for exact match in modifier table
1400 if (!aAtString.isEmpty())
1402 // language is lower case in table
1403 OString aLowerLang = aLang.toAsciiLowerCase();
1404 // country is upper case in table
1405 OString aUpperCountry = aCountry.toAsciiUpperCase();
1406 for (const IsoLangGLIBCModifiersEntry* pGLIBCModifiersEntry = aImplIsoLangGLIBCModifiersEntries;
1407 pGLIBCModifiersEntry->mnLang != LANGUAGE_DONTKNOW; ++pGLIBCModifiersEntry)
1408 { // avoid embedded \0 warning
1409 if (aLowerLang.equals( static_cast< const char* >( pGLIBCModifiersEntry->maLanguage )) &&
1410 aAtString.equals( static_cast< const char* >( pGLIBCModifiersEntry->maAtString )))
1412 if (aUpperCountry.isEmpty() ||
1413 aUpperCountry.equals( static_cast< const char* >( pGLIBCModifiersEntry->maCountry )))
1415 return pGLIBCModifiersEntry->mnLang;
1421 return Conversion::convertIsoNamesToLanguage( aLang, aCountry );
1425 // static
1426 ::std::vector< MsLangId::LanguagetagMapping > MsLangId::getDefinedLanguagetags()
1428 ::std::vector< LanguagetagMapping > aVec;
1429 for (const Bcp47CountryEntry* pEntry = aImplBcp47CountryEntries;
1430 pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1432 aVec.push_back( LanguagetagMapping( pEntry->getTagString(), pEntry->mnLang));
1434 for (const IsoLanguageScriptCountryEntry* pEntry = aImplIsoLangScriptEntries;
1435 pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1437 aVec.push_back( LanguagetagMapping( pEntry->getTagString(), pEntry->mnLang));
1439 for (const IsoLanguageCountryEntry* pEntry = aImplIsoLangEntries;
1440 pEntry->mnLang != LANGUAGE_DONTKNOW; ++pEntry)
1442 aVec.push_back( LanguagetagMapping( pEntry->getTagString(), pEntry->mnLang));
1444 return aVec;
1447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */