1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <rtl/ustring.hxx>
30 #include <rtl/string.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <rtl/strbuf.hxx>
34 #include "i18npool/mslangid.hxx"
36 // =======================================================================
38 struct IsoLangEngEntry
41 sal_Char maCountry
[3];
44 struct IsoLangNoneStdEntry
47 sal_Char maLangStr
[4];
48 sal_Char maCountry
[9];
51 struct IsoLangOtherEntry
54 const sal_Char
* mpLangStr
;
57 // -----------------------------------------------------------------------
59 // Entries for languages are lower case, for countries upper case, as
60 // recommended by rfc4646 (obsoletes rfc3066 (obsoletes rfc1766)).
61 // convertIsoNamesToLanguage() is case insensitive
63 // Sort order: Most used first.
65 // The default entry for a LangID <-> ISO mapping has to be first. For
66 // conversion of legacy mappings one LangID can map to multiple ISO codes, and
67 // one ISO code combination can map to multiple LangIDs. For compatibility with
68 // already existing calls it can also be a sequence as follows:
70 // LANGUAGE_ENGLISH, "en", ""
71 // LANGUAGE_ENGLISH_US, "en", "US"
73 // Here, in a convertIsoNamesToLanguage() call "en-US" is converted to
74 // LANGUAGE_ENGLISH_US and "en" is converted to LANGUAGE_ENGLISH. A call with
75 // "en-ZZ" (not in table) would result in LANGUAGE_ENGLISH because the first
76 // entry matching the language and not having a country is returned, regardless
77 // of whether being sorted before or after other entries of the same language
78 // with some country. To obtain a _locale_ (not language only) in the order
79 // given, convertLocaleToLanguageWithFallback() must be called.
81 // If the sequence instead was
83 // LANGUAGE_ENGLISH_US, "en", "US"
84 // LANGUAGE_ENGLISH, "en", ""
86 // in a convertIsoNamesToLanguage() call "en-US" is still converted to
87 // LANGUAGE_ENGLISH_US, but "en" is _also_ converted to LANGUAGE_ENGLISH_US
88 // because no country was passed and it is the first entry to match the
89 // language, see code. A call with "en-ZZ" (not in table) would still result in
92 /* erAck: 2007-07-05T20:01+0200 TODO: The entire suite's "primary language
93 * only" usage and locale fall back should be cleaned up and made consistent. I
94 * strongly doubt that most callers exactly expect the behavior described.
95 * Currently these primary LangIDs are used literally in OOo code:
96 * LANGUAGE_ENGLISH LANGUAGE_CHINESE LANGUAGE_MALAY
97 * LANGUAGE_AZERI LANGUAGE_URDU LANGUAGE_KASHMIRI
100 static MsLangId::IsoLangEntry
const aImplIsoLangEntries
[] =
102 // MS-LANGID codes ISO639-1/2/3 ISO3166
103 { LANGUAGE_ENGLISH
, "en", "" },
104 { LANGUAGE_ENGLISH_US
, "en", "US" },
105 { LANGUAGE_ENGLISH_UK
, "en", "GB" },
106 { LANGUAGE_ENGLISH_AUS
, "en", "AU" },
107 { LANGUAGE_ENGLISH_CAN
, "en", "CA" },
108 { LANGUAGE_FRENCH
, "fr", "FR" },
109 { LANGUAGE_FRENCH
, "fr", "" },
110 { LANGUAGE_GERMAN
, "de", "DE" },
111 { LANGUAGE_ITALIAN
, "it", "IT" },
112 { LANGUAGE_DUTCH
, "nl", "NL" },
113 { LANGUAGE_SPANISH_MODERN
, "es", "ES" },
114 { LANGUAGE_SPANISH_DATED
, "es", "ES" },
115 { LANGUAGE_PORTUGUESE
, "pt", "PT" },
116 { LANGUAGE_PORTUGUESE_BRAZILIAN
, "pt", "BR" },
117 { LANGUAGE_DANISH
, "da", "DK" },
118 { LANGUAGE_GREEK
, "el", "GR" },
119 { LANGUAGE_CHINESE
, "zh", "" },
120 { LANGUAGE_CHINESE_SIMPLIFIED
, "zh", "CN" },
121 { LANGUAGE_CHINESE_TRADITIONAL
, "zh", "TW" },
122 { LANGUAGE_CHINESE_HONGKONG
, "zh", "HK" },
123 { LANGUAGE_CHINESE_SINGAPORE
, "zh", "SG" },
124 { LANGUAGE_CHINESE_MACAU
, "zh", "MO" },
125 { LANGUAGE_ENGLISH_HONG_KONG_SAR
, "en", "HK" },
126 { LANGUAGE_JAPANESE
, "ja", "JP" },
127 { LANGUAGE_KOREAN
, "ko", "KR" },
128 { LANGUAGE_KOREAN_JOHAB
, "ko", "KR" },
129 { LANGUAGE_USER_KOREAN_NORTH
, "ko", "KP" },
130 { LANGUAGE_SWEDISH
, "sv", "SE" },
131 { LANGUAGE_SWEDISH_FINLAND
, "sv", "FI" },
132 { LANGUAGE_FINNISH
, "fi", "FI" },
133 { LANGUAGE_RUSSIAN
, "ru", "RU" },
134 { LANGUAGE_TATAR
, "tt", "RU" },
135 { LANGUAGE_ENGLISH_NZ
, "en", "NZ" },
136 { LANGUAGE_ENGLISH_EIRE
, "en", "IE" },
137 { LANGUAGE_DUTCH_BELGIAN
, "nl", "BE" },
138 { LANGUAGE_FRENCH_BELGIAN
, "fr", "BE" },
139 { LANGUAGE_FRENCH_CANADIAN
, "fr", "CA" },
140 { LANGUAGE_FRENCH_SWISS
, "fr", "CH" },
141 { LANGUAGE_GERMAN_SWISS
, "de", "CH" },
142 { LANGUAGE_GERMAN_AUSTRIAN
, "de", "AT" },
143 { LANGUAGE_ITALIAN_SWISS
, "it", "CH" },
144 { LANGUAGE_ALBANIAN
, "sq", "AL" },
145 { LANGUAGE_ARABIC_SAUDI_ARABIA
, "ar", "SA" },
146 { LANGUAGE_ARABIC_EGYPT
, "ar", "EG" },
147 { LANGUAGE_ARABIC_UAE
, "ar", "AE" },
148 { LANGUAGE_ARABIC_IRAQ
, "ar", "IQ" },
149 { LANGUAGE_ARABIC_LIBYA
, "ar", "LY" },
150 { LANGUAGE_ARABIC_ALGERIA
, "ar", "DZ" },
151 { LANGUAGE_ARABIC_MOROCCO
, "ar", "MA" },
152 { LANGUAGE_ARABIC_TUNISIA
, "ar", "TN" },
153 { LANGUAGE_ARABIC_OMAN
, "ar", "OM" },
154 { LANGUAGE_ARABIC_YEMEN
, "ar", "YE" },
155 { LANGUAGE_ARABIC_SYRIA
, "ar", "SY" },
156 { LANGUAGE_ARABIC_JORDAN
, "ar", "JO" },
157 { LANGUAGE_ARABIC_LEBANON
, "ar", "LB" },
158 { LANGUAGE_ARABIC_KUWAIT
, "ar", "KW" },
159 { LANGUAGE_ARABIC_BAHRAIN
, "ar", "BH" },
160 { LANGUAGE_ARABIC_QATAR
, "ar", "QA" },
161 { LANGUAGE_USER_ARABIC_CHAD
, "ar", "TD" },
162 { LANGUAGE_USER_ARABIC_COMOROS
, "ar", "KM" },
163 { LANGUAGE_USER_ARABIC_DJIBOUTI
, "ar", "DJ" },
164 { LANGUAGE_USER_ARABIC_ERITREA
, "ar", "ER" },
165 { LANGUAGE_USER_ARABIC_ISRAEL
, "ar", "IL" },
166 { LANGUAGE_USER_ARABIC_MAURITANIA
, "ar", "MR" },
167 { LANGUAGE_USER_ARABIC_PALESTINE
, "ar", "PS" },
168 { LANGUAGE_USER_ARABIC_SOMALIA
, "ar", "SO" },
169 { LANGUAGE_USER_ARABIC_SUDAN
, "ar", "SD" },
170 { LANGUAGE_ARABIC_PRIMARY_ONLY
, "ar", "" },
171 { LANGUAGE_BASQUE
, "eu", "" },
172 { LANGUAGE_BULGARIAN
, "bg", "BG" },
173 { LANGUAGE_CZECH
, "cs", "CZ" },
174 { LANGUAGE_CZECH
, "cz", "" },
175 { LANGUAGE_ENGLISH_JAMAICA
, "en", "JM" },
176 { LANGUAGE_ENGLISH_CARRIBEAN
, "en", "BS" }, // not 100%, because AG is Bahamas
177 { LANGUAGE_ENGLISH_BELIZE
, "en", "BZ" },
178 { LANGUAGE_ENGLISH_TRINIDAD
, "en", "TT" },
179 { LANGUAGE_ENGLISH_ZIMBABWE
, "en", "ZW" },
180 { LANGUAGE_ENGLISH_INDONESIA
, "en", "ID" },
181 { LANGUAGE_ESTONIAN
, "et", "EE" },
182 { LANGUAGE_FAEROESE
, "fo", "FO" },
183 { LANGUAGE_FARSI
, "fa", "IR" },
184 { LANGUAGE_FRENCH_LUXEMBOURG
, "fr", "LU" },
185 { LANGUAGE_FRENCH_MONACO
, "fr", "MC" },
186 { LANGUAGE_GERMAN_LUXEMBOURG
, "de", "LU" },
187 { LANGUAGE_GERMAN_LIECHTENSTEIN
, "de", "LI" },
188 { LANGUAGE_HEBREW
, "he", "IL" }, // new: old was "iw"
189 { LANGUAGE_HEBREW
, "iw", "IL" }, // old: new is "he"
190 { LANGUAGE_HUNGARIAN
, "hu", "HU" },
191 { LANGUAGE_ICELANDIC
, "is", "IS" },
192 { LANGUAGE_INDONESIAN
, "id", "ID" }, // new: old was "in"
193 { LANGUAGE_INDONESIAN
, "in", "ID" }, // old: new is "id"
194 { LANGUAGE_NORWEGIAN
, "no", "NO" },
195 { LANGUAGE_NORWEGIAN_BOKMAL
, "nb", "NO" },
196 { LANGUAGE_NORWEGIAN_NYNORSK
, "nn", "NO" },
197 { LANGUAGE_POLISH
, "pl", "PL" },
198 { LANGUAGE_RHAETO_ROMAN
, "rm", "CH" },
199 { LANGUAGE_ROMANIAN
, "ro", "RO" },
200 { LANGUAGE_ROMANIAN_MOLDOVA
, "ro", "MD" },
201 { LANGUAGE_SLOVAK
, "sk", "SK" },
202 { LANGUAGE_SLOVENIAN
, "sl", "SI" },
203 { LANGUAGE_SPANISH_MEXICAN
, "es", "MX" },
204 { LANGUAGE_SPANISH_GUATEMALA
, "es", "GT" },
205 { LANGUAGE_SPANISH_COSTARICA
, "es", "CR" },
206 { LANGUAGE_SPANISH_PANAMA
, "es", "PA" },
207 { LANGUAGE_SPANISH_DOMINICAN_REPUBLIC
, "es", "DO" },
208 { LANGUAGE_SPANISH_VENEZUELA
, "es", "VE" },
209 { LANGUAGE_SPANISH_COLOMBIA
, "es", "CO" },
210 { LANGUAGE_SPANISH_PERU
, "es", "PE" },
211 { LANGUAGE_SPANISH_ARGENTINA
, "es", "AR" },
212 { LANGUAGE_SPANISH_ECUADOR
, "es", "EC" },
213 { LANGUAGE_SPANISH_CHILE
, "es", "CL" },
214 { LANGUAGE_SPANISH_URUGUAY
, "es", "UY" },
215 { LANGUAGE_SPANISH_PARAGUAY
, "es", "PY" },
216 { LANGUAGE_SPANISH_BOLIVIA
, "es", "BO" },
217 { LANGUAGE_SPANISH_EL_SALVADOR
, "es", "SV" },
218 { LANGUAGE_SPANISH_HONDURAS
, "es", "HN" },
219 { LANGUAGE_SPANISH_NICARAGUA
, "es", "NI" },
220 { LANGUAGE_SPANISH_PUERTO_RICO
, "es", "PR" },
221 { LANGUAGE_SPANISH_UNITED_STATES
, "es", "US" },
222 { LANGUAGE_SPANISH_LATIN_AMERICA
, "es", "" },
223 { LANGUAGE_TURKISH
, "tr", "TR" },
224 { LANGUAGE_UKRAINIAN
, "uk", "UA" },
225 { LANGUAGE_VIETNAMESE
, "vi", "VN" },
226 { LANGUAGE_LATVIAN
, "lv", "LV" },
227 { LANGUAGE_MACEDONIAN
, "mk", "MK" },
228 { LANGUAGE_MALAY
, "ms", "" },
229 { LANGUAGE_MALAY_MALAYSIA
, "ms", "MY" },
230 { LANGUAGE_MALAY_BRUNEI_DARUSSALAM
, "ms", "BN" },
231 { LANGUAGE_ENGLISH_MALAYSIA
, "en", "MY" },
232 { LANGUAGE_THAI
, "th", "TH" },
233 { LANGUAGE_LITHUANIAN
, "lt", "LT" },
234 { LANGUAGE_LITHUANIAN_CLASSIC
, "lt", "LT" },
235 { LANGUAGE_CROATIAN
, "hr", "HR" }, // Croatian in Croatia
236 { LANGUAGE_CROATIAN_BOSNIA_HERZEGOVINA
, "hr", "BA" },
237 { LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA
, "bs", "BA" },
238 // { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_AND_HERZEGOVINA, "bs", "BA" }, // script codes not supported yet
239 { LANGUAGE_USER_SERBIAN_CYRILLIC_SERBIA
, "sr", "RS" }, // Serbian Cyrillic in Serbia
240 { 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)
241 { LANGUAGE_SERBIAN_CYRILLIC
, "sr", "CS" }, // alias to be able to integrate localizations, rsc needs it
242 { LANGUAGE_USER_SERBIAN_CYRILLIC_MONTENEGRO
, "sr", "ME" },
243 { LANGUAGE_SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA
, "sr", "BA" },
244 { LANGUAGE_SERBIAN
, "sr", "" }, // SERBIAN is only LID, MS-LCID not defined (was dupe of CROATIAN)
245 { LANGUAGE_USER_SERBIAN_LATIN_SERBIA
, "sh", "RS" }, // Serbian Latin in Serbia; kludge, needed to be sr_Latn_RS instead, script codes not supported yet
246 { 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
247 { LANGUAGE_SERBIAN_LATIN
, "sh", "CS" }, // Serbian Latin in Serbia and Montenegro; kludge, needed to be sr_Latn_CS instead, script codes not supported yet
248 { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO
, "sh", "ME" }, // Serbian Latin in Montenegro; kludge, needed to be sr_Latn_ME instead, script codes not supported yet
249 { LANGUAGE_SERBIAN_LATIN_BOSNIA_HERZEGOVINA
, "sh", "BA" },
250 { LANGUAGE_SERBIAN_LATIN_NEUTRAL
, "sh", "" }, // kludge, needed to be sr_Latn instead, script codes not supported yet
251 { LANGUAGE_ARMENIAN
, "hy", "AM" },
252 { LANGUAGE_AZERI
, "az", "" },
253 { LANGUAGE_AZERI_LATIN
, "az", "AZ" },
254 // { LANGUAGE_AZERI_CYRILLIC, "az", "AZ" }, // script codes not supported yet
255 { LANGUAGE_UZBEK_LATIN
, "uz", "UZ" },
256 // { LANGUAGE_UZBEK_CYRILLIC, "uz", "UZ" }, // script codes not supported yet
257 { LANGUAGE_BENGALI_BANGLADESH
, "bn", "BD" },
258 { LANGUAGE_BENGALI
, "bn", "IN" },
259 { LANGUAGE_BURMESE
, "my", "MM" },
260 { LANGUAGE_KAZAK
, "kk", "KZ" },
261 { LANGUAGE_ENGLISH_INDIA
, "en", "IN" },
262 { LANGUAGE_URDU
, "ur", "" },
263 { LANGUAGE_URDU_INDIA
, "ur", "IN" },
264 { LANGUAGE_URDU_PAKISTAN
, "ur", "PK" },
265 { LANGUAGE_HINDI
, "hi", "IN" },
266 { LANGUAGE_GUJARATI
, "gu", "IN" },
267 { LANGUAGE_KANNADA
, "kn", "IN" },
268 { LANGUAGE_ASSAMESE
, "as", "IN" },
269 { LANGUAGE_KASHMIRI
, "ks", "" },
270 { LANGUAGE_KASHMIRI_INDIA
, "ks", "IN" },
271 { LANGUAGE_MALAYALAM
, "ml", "IN" },
272 { LANGUAGE_MANIPURI
, "mni", "IN" },
273 { LANGUAGE_MARATHI
, "mr", "IN" },
274 { LANGUAGE_KONKANI
, "kok", "IN" },
275 { LANGUAGE_NEPALI
, "ne", "NP" },
276 { LANGUAGE_NEPALI_INDIA
, "ne", "IN" },
277 { LANGUAGE_ORIYA
, "or", "IN" },
278 { LANGUAGE_PUNJABI
, "pa", "IN" },
279 { LANGUAGE_SANSKRIT
, "sa", "IN" },
280 { LANGUAGE_SINDHI
, "sd", "IN" },
281 { LANGUAGE_TAMIL
, "ta", "IN" },
282 { LANGUAGE_TELUGU
, "te", "IN" },
283 { LANGUAGE_PUNJABI_PAKISTAN
, "lah", "PK" }, // preferring "lah" over "pa" for Western Punjabi, see http://www.ethnologue.com/show_language.asp?code=PNB
284 { LANGUAGE_PUNJABI_PAKISTAN
, "pa", "PK" },
285 { LANGUAGE_SINDHI_PAKISTAN
, "sd", "PK" },
286 { LANGUAGE_BELARUSIAN
, "be", "BY" },
287 { LANGUAGE_CATALAN
, "ca", "ES" }, // Spain (default)
288 { LANGUAGE_CATALAN
, "ca", "AD" }, // Andorra
289 { LANGUAGE_USER_CATALAN_VALENCIAN
, "ca", "XV" }, // XV: ISO 3166 user-assigned; workaround for UI localization only, do not use in document content!
290 { LANGUAGE_CATALAN
, "qcv", "ES" }, // qcv: ISO 639-3 reserved-for-local-use; UI localization quirk only, do not use in document content!
291 // { LANGUAGE_USER_CATALAN_VALENCIAN, "ca", "ES" }, // In case MS format files escaped into the wild, map them back.
292 { LANGUAGE_FRENCH_CAMEROON
, "fr", "CM" },
293 { LANGUAGE_FRENCH_COTE_D_IVOIRE
, "fr", "CI" },
294 { LANGUAGE_FRENCH_MALI
, "fr", "ML" },
295 { LANGUAGE_FRENCH_SENEGAL
, "fr", "SN" },
296 { LANGUAGE_FRENCH_ZAIRE
, "fr", "CD" }, // Democratic Republic Of Congo
297 { LANGUAGE_FRENCH_MOROCCO
, "fr", "MA" },
298 { LANGUAGE_FRENCH_REUNION
, "fr", "RE" },
299 { LANGUAGE_FRENCH_NORTH_AFRICA
, "fr", "" },
300 { LANGUAGE_FRENCH_WEST_INDIES
, "fr", "" }, // unknown ISO country code
301 { LANGUAGE_FRISIAN_NETHERLANDS
, "fy", "NL" },
302 { LANGUAGE_GAELIC_IRELAND
, "ga", "IE" },
303 { LANGUAGE_GAELIC_SCOTLAND
, "gd", "GB" },
304 { LANGUAGE_GALICIAN
, "gl", "ES" },
305 { LANGUAGE_GEORGIAN
, "ka", "GE" },
306 { LANGUAGE_KHMER
, "km", "KH" },
307 { LANGUAGE_KIRGHIZ
, "ky", "KG" },
308 { LANGUAGE_LAO
, "lo", "LA" },
309 { LANGUAGE_MALTESE
, "mt", "MT" },
310 { LANGUAGE_MONGOLIAN
, "mn", "MN" }, // Cyrillic script
311 { LANGUAGE_MONGOLIAN_MONGOLIAN
, "mn", "MN" },
312 { LANGUAGE_RUSSIAN_MOLDOVA
, "mo", "MD" },
313 { LANGUAGE_SWAHILI
, "sw", "KE" },
314 { LANGUAGE_USER_SWAHILI_TANZANIA
, "sw", "TZ" },
315 { LANGUAGE_TAJIK
, "tg", "TJ" },
316 { LANGUAGE_TIBETAN
, "bo", "CN" }, // CN politically correct?
317 { LANGUAGE_DZONGKHA
, "dz", "BT" },
318 { LANGUAGE_TURKMEN
, "tk", "TM" },
319 { LANGUAGE_WELSH
, "cy", "GB" },
320 { LANGUAGE_SESOTHO
, "st", "ZA" },
321 { LANGUAGE_SEPEDI
, "nso", "ZA" },
322 { LANGUAGE_SEPEDI
, "ns", "ZA" }, // fake "ns" for compatibility with existing OOo1.1.x localization to be able to read those documents
323 { LANGUAGE_TSONGA
, "ts", "ZA" },
324 { LANGUAGE_TSWANA
, "tn", "ZA" },
325 { LANGUAGE_ENGLISH_SAFRICA
, "en", "ZA" },
326 { LANGUAGE_AFRIKAANS
, "af", "ZA" },
327 { LANGUAGE_VENDA
, "ve", "ZA" }, // default 639-1
328 { LANGUAGE_VENDA
, "ven", "ZA" }, // 639-2 may have been used temporarily since 2004-07-23
329 { LANGUAGE_XHOSA
, "xh", "ZA" },
330 { LANGUAGE_ZULU
, "zu", "ZA" },
331 { LANGUAGE_QUECHUA_ECUADOR
, "qu", "EC" },
332 { LANGUAGE_QUECHUA_PERU
, "qu", "PE" },
333 { LANGUAGE_QUECHUA_BOLIVIA
, "qu", "BO" }, // macro: quh-BO, qul-BO
334 { LANGUAGE_PASHTO
, "ps", "AF" },
335 { LANGUAGE_OROMO
, "om", "ET" },
336 { LANGUAGE_DHIVEHI
, "dv", "MV" },
337 { LANGUAGE_UIGHUR_CHINA
, "ug", "CN" },
338 { LANGUAGE_TIGRIGNA_ETHIOPIA
, "ti", "ET" },
339 { LANGUAGE_TIGRIGNA_ERITREA
, "ti", "ER" },
340 { LANGUAGE_AMHARIC_ETHIOPIA
, "am", "ET" },
341 { LANGUAGE_GUARANI_PARAGUAY
, "gug", "PY" },
342 { LANGUAGE_HAWAIIAN_UNITED_STATES
, "haw", "US" },
343 { LANGUAGE_EDO
, "bin", "NG" },
344 { LANGUAGE_FULFULDE_NIGERIA
, "ff", "NG" },
345 { LANGUAGE_HAUSA_NIGERIA
, "ha", "NG" },
346 { LANGUAGE_USER_HAUSA_GHANA
, "ha", "GH" },
347 { LANGUAGE_IGBO_NIGERIA
, "ig", "NG" },
348 { LANGUAGE_KANURI_NIGERIA
, "kr", "NG" },
349 { LANGUAGE_YORUBA
, "yo", "NG" },
350 { LANGUAGE_SOMALI
, "so", "SO" },
351 { LANGUAGE_PAPIAMENTU
, "pap", "AN" },
352 { LANGUAGE_USER_PAPIAMENTU_ARUBA
, "pap", "AW" },
353 { LANGUAGE_ENGLISH_SINGAPORE
, "en", "SG" },
354 { LANGUAGE_USER_YIDDISH_US
, "yi", "US" },
355 { LANGUAGE_YIDDISH
, "yi", "IL" }, // new: old was "ji"
356 { LANGUAGE_YIDDISH
, "ji", "IL" }, // old: new is "yi"
357 { LANGUAGE_SYRIAC
, "syr", "TR" }, // "TR" according to http://www.ethnologue.com/show_language.asp?code=SYC
358 { LANGUAGE_SINHALESE_SRI_LANKA
, "si", "LK" },
359 { LANGUAGE_CHEROKEE_UNITED_STATES
, "chr", "US" },
360 { LANGUAGE_INUKTITUT_LATIN_CANADA
, "iu", "CA" },
361 // { LANGUAGE_INUKTITUT_SYLLABICS_CANADA, "iu", "CA" }, // script codes not supported yet
362 { LANGUAGE_SAMI_NORTHERN_NORWAY
, "se", "NO" },
363 { LANGUAGE_SAMI_INARI
, "smn", "FI" },
364 { LANGUAGE_SAMI_LULE_NORWAY
, "smj", "NO" },
365 { LANGUAGE_SAMI_LULE_SWEDEN
, "smj", "SE" },
366 { LANGUAGE_SAMI_NORTHERN_FINLAND
, "se", "FI" },
367 { LANGUAGE_SAMI_NORTHERN_SWEDEN
, "se", "SE" },
368 { LANGUAGE_SAMI_SKOLT
, "sms", "FI" },
369 { LANGUAGE_SAMI_SOUTHERN_NORWAY
, "sma", "NO" },
370 { LANGUAGE_SAMI_SOUTHERN_SWEDEN
, "sma", "SE" },
371 { LANGUAGE_USER_SAMI_KILDIN_RUSSIA
, "sjd", "RU" },
372 { LANGUAGE_MAPUDUNGUN_CHILE
, "arn", "CL" },
373 { LANGUAGE_CORSICAN_FRANCE
, "co", "FR" },
374 { 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.
375 { LANGUAGE_YAKUT_RUSSIA
, "sah", "RU" },
376 { LANGUAGE_MOHAWK_CANADA
, "moh", "CA" },
377 { LANGUAGE_BASHKIR_RUSSIA
, "ba", "RU" },
378 { LANGUAGE_KICHE_GUATEMALA
, "qut", "GT" },
379 { LANGUAGE_DARI_AFGHANISTAN
, "gbz", "AF" },
380 { LANGUAGE_WOLOF_SENEGAL
, "wo", "SN" },
381 { LANGUAGE_FILIPINO
, "fil", "PH" },
382 { LANGUAGE_USER_TAGALOG
, "tl", "PH" },
383 { LANGUAGE_ENGLISH_PHILIPPINES
, "en", "PH" },
384 // { LANGUAGE_IBIBIO_NIGERIA, "nic", "NG" }, // ISO "nic" is only a collective language code
385 { LANGUAGE_YI
, "ii", "CN" },
386 { LANGUAGE_TAMAZIGHT_LATIN
, "kab", "DZ" }, // In practice Kabyle is the language used for this
387 { LANGUAGE_OBSOLETE_USER_KABYLE
, "kab", "DZ" },
388 { LANGUAGE_TAMAZIGHT_LATIN
, "ber", "DZ" }, // In practice Algeria has standardized on Kabyle as the member of the "ber" collective which gets used there.
389 { 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
390 // { LANGUAGE_TAMAZIGHT_ARABIC, "ber", "" }, // ISO "ber" only collective!
391 { LANGUAGE_LATIN
, "la", "VA" },
392 { LANGUAGE_OBSOLETE_USER_LATIN
, "la", "VA" },
393 { LANGUAGE_USER_ESPERANTO
, "eo", "" },
394 { LANGUAGE_USER_INTERLINGUA
, "ia", "" },
395 { LANGUAGE_MAORI_NEW_ZEALAND
, "mi", "NZ" },
396 { LANGUAGE_OBSOLETE_USER_MAORI
, "mi", "NZ" },
397 { LANGUAGE_KINYARWANDA_RWANDA
, "rw", "RW" },
398 { LANGUAGE_OBSOLETE_USER_KINYARWANDA
, "rw", "RW" },
399 { 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
400 { LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN
,"hsb", "DE" },
401 { 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
402 { LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN
,"dsb", "DE" },
403 { LANGUAGE_OCCITAN_FRANCE
, "oc", "FR" },
404 { LANGUAGE_OBSOLETE_USER_OCCITAN
, "oc", "FR" },
405 { LANGUAGE_USER_KURDISH_TURKEY
, "ku", "TR" },
406 { LANGUAGE_USER_KURDISH_SYRIA
, "ku", "SY" },
407 { LANGUAGE_USER_KURDISH_IRAQ
, "ku", "IQ" },
408 { LANGUAGE_USER_KURDISH_IRAN
, "ku", "IR" },
409 { LANGUAGE_USER_SARDINIAN
, "sc", "IT" }, // macrolanguage code
410 { LANGUAGE_USER_SARDINIAN_CAMPIDANESE
, "sro", "IT" },
411 { LANGUAGE_USER_SARDINIAN_GALLURESE
, "sdn", "IT" },
412 { LANGUAGE_USER_SARDINIAN_LOGUDORESE
, "src", "IT" },
413 { LANGUAGE_USER_SARDINIAN_SASSARESE
, "sdc", "IT" },
414 { LANGUAGE_BRETON_FRANCE
, "br", "FR" },
415 { LANGUAGE_OBSOLETE_USER_BRETON
, "br", "FR" },
416 { LANGUAGE_KALAALLISUT_GREENLAND
, "kl", "GL" },
417 { LANGUAGE_OBSOLETE_USER_KALAALLISUT
, "kl", "GL" },
418 { LANGUAGE_USER_SWAZI
, "ss", "ZA" },
419 { LANGUAGE_USER_NDEBELE_SOUTH
, "nr", "ZA" },
420 { LANGUAGE_USER_TSWANA_BOTSWANA
, "tn", "BW" },
421 { LANGUAGE_USER_MOORE
, "mos", "BF" },
422 { LANGUAGE_USER_BAMBARA
, "bm", "ML" },
423 { LANGUAGE_USER_AKAN
, "ak", "GH" },
424 { LANGUAGE_LUXEMBOURGISH_LUXEMBOURG
, "lb", "LU" },
425 { LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH
, "lb", "LU" },
426 { LANGUAGE_USER_FRIULIAN
, "fur", "IT" },
427 { LANGUAGE_USER_FIJIAN
, "fj", "FJ" },
428 { LANGUAGE_USER_AFRIKAANS_NAMIBIA
, "af", "NA" },
429 { LANGUAGE_USER_ENGLISH_NAMIBIA
, "en", "NA" },
430 { LANGUAGE_USER_WALLOON
, "wa", "BE" },
431 { LANGUAGE_USER_COPTIC
, "cop", "EG" },
432 { LANGUAGE_USER_GASCON
, "gsc", "FR" },
433 { LANGUAGE_USER_GERMAN_BELGIUM
, "de", "BE" },
434 { LANGUAGE_USER_CHUVASH
, "cv", "RU" },
435 { LANGUAGE_USER_EWE_GHANA
, "ee", "GH" },
436 { LANGUAGE_USER_ENGLISH_GHANA
, "en", "GH" },
437 { LANGUAGE_USER_SANGO
, "sg", "CF" },
438 { LANGUAGE_USER_GANDA
, "lg", "UG" },
439 { LANGUAGE_USER_LINGALA_DRCONGO
, "ln", "CD" },
440 { LANGUAGE_USER_LOW_GERMAN
, "nds", "DE" },
441 { LANGUAGE_USER_HILIGAYNON
, "hil", "PH" },
442 { LANGUAGE_USER_ENGLISH_MALAWI
, "en", "MW" }, /* en default for MW */
443 { LANGUAGE_USER_NYANJA
, "ny", "MW" },
444 { LANGUAGE_USER_KASHUBIAN
, "csb", "PL" },
445 { LANGUAGE_USER_SPANISH_CUBA
, "es", "CU" },
446 { LANGUAGE_USER_QUECHUA_NORTH_BOLIVIA
, "qul", "BO" },
447 { LANGUAGE_USER_QUECHUA_SOUTH_BOLIVIA
, "quh", "BO" },
448 { LANGUAGE_USER_BODO_INDIA
, "brx", "IN" },
449 { LANGUAGE_USER_DOGRI_INDIA
, "dgo", "IN" },
450 { LANGUAGE_USER_MAITHILI_INDIA
, "mai", "IN" },
451 { LANGUAGE_USER_SANTALI_INDIA
, "sat", "IN" },
452 { LANGUAGE_USER_TETUN
, "tet", "ID" },
453 { LANGUAGE_USER_TETUN_TIMOR_LESTE
, "tet", "TL" },
454 { LANGUAGE_USER_TOK_PISIN
, "tpi", "PG" },
455 { LANGUAGE_USER_SHUSWAP
, "shs", "CA" },
456 { LANGUAGE_USER_ANCIENT_GREEK
, "grc", "GR" },
457 { LANGUAGE_USER_ASTURIAN
, "ast", "ES" },
458 { LANGUAGE_USER_LATGALIAN
, "ltg", "LV" },
459 { LANGUAGE_USER_MAORE
, "swb", "YT" },
460 { LANGUAGE_USER_BUSHI
, "buc", "YT" },
461 { LANGUAGE_USER_TAHITIAN
, "ty", "PF" },
462 { LANGUAGE_USER_MALAGASY_PLATEAU
, "plt", "MG" },
463 { LANGUAGE_USER_MALAGASY_PLATEAU
, "mg", "MG" },
464 { LANGUAGE_USER_BAFIA
, "ksf", "CM" },
465 { LANGUAGE_USER_GIKUYU
, "ki", "KE" },
466 { LANGUAGE_USER_RUSYN_UKRAINE
, "rue", "UA" },
467 { LANGUAGE_USER_RUSYN_SLOVAKIA
, "rue", "SK" },
468 { LANGUAGE_USER_LIMBU
, "lif", "NP" },
469 { LANGUAGE_USER_LOJBAN
, "jbo", "" },
470 { LANGUAGE_USER_HAITIAN
, "ht", "HT" },
471 { LANGUAGE_FRENCH_HAITI
, "fr", "HT" },
472 { LANGUAGE_USER_BEEMBE
, "beq", "CG" },
473 { LANGUAGE_USER_BEKWEL
, "bkw", "CG" },
474 { LANGUAGE_USER_KITUBA
, "mkw", "CG" },
475 { LANGUAGE_USER_LARI
, "ldi", "CG" },
476 { LANGUAGE_USER_MBOCHI
, "mdw", "CG" },
477 { LANGUAGE_USER_TEKE_EBOO
, "ebo", "CG" },
478 { LANGUAGE_USER_TEKE_IBALI
, "tek", "CG" },
479 { LANGUAGE_USER_TEKE_TYEE
, "tyx", "CG" },
480 { LANGUAGE_USER_VILI
, "vif", "CG" },
481 { LANGUAGE_USER_PORTUGUESE_ANGOLA
, "pt", "AO" },
482 { LANGUAGE_USER_MANX
, "gv", "GB" },
483 { LANGUAGE_USER_ARAGONESE
, "an", "ES" },
484 { LANGUAGE_USER_KEYID
, "qtz", "" }, // key id pseudolanguage used for UI testing
485 { LANGUAGE_USER_PALI_LATIN
, "pli", "" }, // Pali with Latin script
486 { LANGUAGE_USER_KYRGYZ_CHINA
, "ky", "CN" },
487 { LANGUAGE_USER_KOMI_ZYRIAN
, "kpv", "RU" },
488 { LANGUAGE_USER_KOMI_PERMYAK
, "koi", "RU" },
489 { LANGUAGE_USER_PITJANTJATJARA
, "pjt", "AU" },
490 { LANGUAGE_USER_ERZYA
, "myv", "RU" },
491 { LANGUAGE_USER_MARI_MEADOW
, "mhr", "RU" },
492 { LANGUAGE_NONE
, "zxx", "" }, // added to ISO 639-2 on 2006-01-11: Used to declare the absence of linguistic information
493 { LANGUAGE_DONTKNOW
, "", "" } // marks end of table
496 static MsLangId::IsoLangEntry aLastResortFallbackEntry
=
497 { LANGUAGE_ENGLISH_US
, "en", "US" };
499 // -----------------------------------------------------------------------
501 // In this table are the countries which should mapped to a specific
503 static IsoLangEngEntry
const aImplIsoLangEngEntries
[] =
505 { LANGUAGE_ENGLISH_UK
, "AO" }, // Angola
506 { LANGUAGE_ENGLISH_UK
, "BJ" }, // Benin
507 { LANGUAGE_ENGLISH_UK
, "BW" }, // Botswana
508 { LANGUAGE_ENGLISH_UK
, "BI" }, // Burundi
509 { LANGUAGE_ENGLISH_UK
, "CM" }, // Cameroon
510 { LANGUAGE_ENGLISH_UK
, "GA" }, // Gabon
511 { LANGUAGE_ENGLISH_UK
, "GM" }, // Gambia
512 { LANGUAGE_ENGLISH_UK
, "GH" }, // Ghana
513 { LANGUAGE_ENGLISH_UK
, "GN" }, // Guinea
514 { LANGUAGE_ENGLISH_UK
, "LS" }, // Lesotho
515 { LANGUAGE_ENGLISH_UK
, "MW" }, // Malawi
516 { LANGUAGE_ENGLISH_UK
, "MT" }, // Malta
517 { LANGUAGE_ENGLISH_UK
, "NA" }, // Namibia
518 { LANGUAGE_ENGLISH_UK
, "NG" }, // Nigeria
519 { LANGUAGE_ENGLISH_UK
, "UG" }, // Uganda
520 { LANGUAGE_ENGLISH_UK
, "ZM" }, // Zambia
521 { LANGUAGE_ENGLISH_UK
, "ZW" }, // Zimbabwe
522 { LANGUAGE_ENGLISH_UK
, "SZ" }, // Swaziland
523 { LANGUAGE_ENGLISH_UK
, "NG" }, // Sierra Leone
524 { LANGUAGE_ENGLISH_UK
, "KN" }, // Saint Kitts and Nevis
525 { LANGUAGE_ENGLISH_UK
, "SH" }, // St. Helena
526 { LANGUAGE_ENGLISH_UK
, "IO" }, // British Indian Oceanic Territory
527 { LANGUAGE_ENGLISH_UK
, "FK" }, // Falkland Islands
528 { LANGUAGE_ENGLISH_UK
, "GI" }, // Gibraltar
529 { LANGUAGE_ENGLISH_UK
, "KI" }, // Kiribati
530 { LANGUAGE_ENGLISH_UK
, "VG" }, // Virgin Islands
531 { LANGUAGE_ENGLISH_UK
, "MU" }, // Mauritius
532 { LANGUAGE_ENGLISH_UK
, "FJ" }, // Fiji
533 { LANGUAGE_ENGLISH_US
, "KI" }, // Kiribati
534 { LANGUAGE_ENGLISH_US
, "LR" }, // Liberia
535 { LANGUAGE_ENGLISH_US
, "GU" }, // Guam
536 { LANGUAGE_ENGLISH_US
, "MH" }, // Marshall Islands
537 { LANGUAGE_ENGLISH_US
, "PW" }, // Palau
538 { LANGUAGE_ENGLISH_CARRIBEAN
, "AI" }, // Anguilla
539 { LANGUAGE_ENGLISH_CARRIBEAN
, "AG" }, // Antigua and Barbuda
540 { LANGUAGE_ENGLISH_CARRIBEAN
, "BS" }, // Bahamas
541 { LANGUAGE_ENGLISH_CARRIBEAN
, "BB" }, // Barbedos
542 { LANGUAGE_ENGLISH_CARRIBEAN
, "BM" }, // Bermuda
543 { LANGUAGE_ENGLISH_CARRIBEAN
, "KY" }, // Cayman Islands
544 { LANGUAGE_ENGLISH_CARRIBEAN
, "GD" }, // Grenada
545 { LANGUAGE_ENGLISH_CARRIBEAN
, "DM" }, // Dominica
546 { LANGUAGE_ENGLISH_CARRIBEAN
, "HT" }, // Haiti
547 { LANGUAGE_ENGLISH_CARRIBEAN
, "MS" }, // Montserrat
548 { LANGUAGE_ENGLISH_CARRIBEAN
, "FM" }, // Micronesia
549 { LANGUAGE_ENGLISH_CARRIBEAN
, "VC" }, // St. Vincent / Grenadines
550 { LANGUAGE_ENGLISH_CARRIBEAN
, "LC" }, // Saint Lucia
551 { LANGUAGE_ENGLISH_CARRIBEAN
, "TC" }, // Turks & Caicos Islands
552 { LANGUAGE_ENGLISH_CARRIBEAN
, "GY" }, // Guyana
553 { LANGUAGE_ENGLISH_CARRIBEAN
, "TT" }, // Trinidad and Tobago
554 { LANGUAGE_ENGLISH_AUS
, "CX" }, // Christmas Islands
555 { LANGUAGE_ENGLISH_AUS
, "CC" }, // Cocos (Keeling) Islands
556 { LANGUAGE_ENGLISH_AUS
, "NF" }, // Norfolk Island
557 { LANGUAGE_ENGLISH_AUS
, "PG" }, // Papua New Guinea
558 { LANGUAGE_ENGLISH_AUS
, "SB" }, // Solomon Islands
559 { LANGUAGE_ENGLISH_AUS
, "TV" }, // Tuvalu
560 { LANGUAGE_ENGLISH_AUS
, "NR" }, // Nauru
561 { LANGUAGE_ENGLISH_NZ
, "CK" }, // Cook Islands
562 { LANGUAGE_ENGLISH_NZ
, "NU" }, // Niue
563 { LANGUAGE_ENGLISH_NZ
, "TK" }, // Tokelau
564 { LANGUAGE_ENGLISH_NZ
, "TO" }, // Tonga
565 { LANGUAGE_DONTKNOW
, "" } // marks end of table
568 // -----------------------------------------------------------------------
570 static IsoLangNoneStdEntry
const aImplIsoNoneStdLangEntries
[] =
572 { LANGUAGE_NORWEGIAN_BOKMAL
, "no", "BOK" }, // registered subtags for "no" in rfc1766
573 { LANGUAGE_NORWEGIAN_NYNORSK
, "no", "NYN" }, // registered subtags for "no" in rfc1766
574 { LANGUAGE_SERBIAN_LATIN
, "sr", "latin" },
575 { LANGUAGE_SERBIAN_CYRILLIC
, "sr", "cyrillic" },
576 { LANGUAGE_AZERI_LATIN
, "az", "latin" },
577 { LANGUAGE_AZERI_CYRILLIC
, "az", "cyrillic" },
578 { LANGUAGE_DONTKNOW
, "", "" } // marks end of table
581 // -----------------------------------------------------------------------
583 // in this table are only names to find the best language
584 static IsoLangNoneStdEntry
const aImplIsoNoneStdLangEntries2
[] =
586 { LANGUAGE_NORWEGIAN_BOKMAL
, "no", "bokmaal" },
587 { LANGUAGE_NORWEGIAN_BOKMAL
, "no", "bokmal" },
588 { LANGUAGE_NORWEGIAN_NYNORSK
, "no", "nynorsk" },
589 { LANGUAGE_DONTKNOW
, "", "" } // marks end of table
592 // -----------------------------------------------------------------------
594 // in this table are only names to find the best language
595 static IsoLangOtherEntry
const aImplOtherEntries
[] =
597 { LANGUAGE_ENGLISH_US
, "c" },
598 { LANGUAGE_CHINESE
, "chinese" },
599 { LANGUAGE_GERMAN
, "german" },
600 { LANGUAGE_JAPANESE
, "japanese" },
601 { LANGUAGE_KOREAN
, "korean" },
602 { LANGUAGE_ENGLISH_US
, "posix" },
603 { LANGUAGE_CHINESE_TRADITIONAL
, "tchinese" },
604 { LANGUAGE_DONTKNOW
, NULL
} // marks end of table
607 // =======================================================================
610 void MsLangId::convertLanguageToIsoNames( LanguageType nLang
,
611 rtl::OUString
& rLangStr
, rtl::OUString
& rCountry
)
613 if ( nLang
== LANGUAGE_SYSTEM
)
614 nLang
= MsLangId::getSystemLanguage();
616 // Search for LangID (in this table we find only defined ISO combinations)
617 const IsoLangEntry
* pEntry
= aImplIsoLangEntries
;
620 if ( pEntry
->mnLang
== nLang
)
622 rLangStr
= rtl::OUString::createFromAscii( pEntry
->maLangStr
);
623 rCountry
= rtl::OUString::createFromAscii( pEntry
->maCountry
);
628 while ( pEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
630 // Search for LangID if we didn't find a specific ISO combination.
631 // All entries in this table are allowed for mime specifications,
632 // but not defined ISO combinations.
633 const IsoLangNoneStdEntry
* pNoneStdEntry
= aImplIsoNoneStdLangEntries
;
636 if ( pNoneStdEntry
->mnLang
== nLang
)
638 rLangStr
= rtl::OUString::createFromAscii( pNoneStdEntry
->maLangStr
);
639 rCountry
= rtl::OUString::createFromAscii( pNoneStdEntry
->maCountry
);
644 while ( pNoneStdEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
647 rLangStr
= rtl::OUString();
648 rCountry
= rtl::OUString();
651 // -----------------------------------------------------------------------
654 void MsLangId::convertLanguageToIsoNames( LanguageType nLang
,
655 rtl::OString
& rLangStr
, rtl::OString
& rCountry
)
657 if ( nLang
== LANGUAGE_SYSTEM
)
658 nLang
= MsLangId::getSystemLanguage();
660 // Search for LangID (in this table we find only defined ISO combinations)
661 const IsoLangEntry
* pEntry
= aImplIsoLangEntries
;
664 if ( pEntry
->mnLang
== nLang
)
665 { // avoid embedded \0 warning
666 rLangStr
= rtl::OString( static_cast< const char* >( pEntry
->maLangStr
));
667 rCountry
= rtl::OString( static_cast< const char* >( pEntry
->maCountry
));
672 while ( pEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
674 // Search for LangID if we didn't find a specific ISO combination.
675 // All entries in this table are allowed for mime specifications,
676 // but not defined ISO combinations.
677 const IsoLangNoneStdEntry
* pNoneStdEntry
= aImplIsoNoneStdLangEntries
;
680 if ( pNoneStdEntry
->mnLang
== nLang
)
681 { // avoid embedded \0 warning
682 rLangStr
= rtl::OString( static_cast< const char* >( pNoneStdEntry
->maLangStr
));
683 rCountry
= rtl::OString( static_cast< const char* >( pNoneStdEntry
->maCountry
));
688 while ( pNoneStdEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
691 rLangStr
= rtl::OString();
692 rCountry
= rtl::OString();
695 // -----------------------------------------------------------------------
697 static const MsLangId::IsoLangEntry
& lcl_lookupFallbackEntry( LanguageType nLang
)
699 LanguageType nPrimary
= MsLangId::getPrimaryLanguage( nLang
);
701 // Search for LangID and remember first lang-only.
702 const MsLangId::IsoLangEntry
* pFirstPrimary
= NULL
;
703 const MsLangId::IsoLangEntry
* pEntry
= aImplIsoLangEntries
;
706 if (pEntry
->mnLang
== nLang
)
708 if (*pEntry
->maCountry
)
712 // These are known to have no country assigned.
713 case LANGUAGE_BASQUE
:
714 case LANGUAGE_USER_ESPERANTO
:
715 case LANGUAGE_USER_INTERLINGUA
:
716 case LANGUAGE_USER_LOJBAN
:
722 if (!pFirstPrimary
&&
723 MsLangId::getPrimaryLanguage( pEntry
->mnLang
) == nPrimary
)
724 pFirstPrimary
= pEntry
;
727 while ( pEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
729 // Language not found at all => use default.
731 return aLastResortFallbackEntry
;
733 // Search for first entry of primary language with any country.
734 pEntry
= pFirstPrimary
;
737 if (MsLangId::getPrimaryLanguage( pEntry
->mnLang
) == nLang
)
739 if (*pEntry
->maCountry
)
744 while ( pEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
746 return aLastResortFallbackEntry
;
750 LanguageType
MsLangId::lookupFallbackLanguage( LanguageType nLang
)
752 return lcl_lookupFallbackEntry( nLang
).mnLang
;
757 ::com::sun::star::lang::Locale
MsLangId::lookupFallbackLocale( LanguageType nLang
)
759 const MsLangId::IsoLangEntry
& rEntry
= lcl_lookupFallbackEntry( nLang
);
760 return ::com::sun::star::lang::Locale(
761 rtl::OUString::createFromAscii( rEntry
.maLangStr
),
762 rtl::OUString::createFromAscii( rEntry
.maCountry
),
766 // -----------------------------------------------------------------------
768 static const MsLangId::IsoLangEntry
& lcl_lookupFallbackEntry(
769 const ::com::sun::star::lang::Locale
& rLocale
)
771 // language is lower case in table
772 rtl::OUString aLowerLang
= rLocale
.Language
.toAsciiLowerCase();
773 // country is upper case in table
774 rtl::OUString aUpperCountry
= rLocale
.Country
.toAsciiUpperCase();
775 sal_Int32 nCountryLen
= aUpperCountry
.getLength();
777 // Search for locale and remember first lang-only.
778 const MsLangId::IsoLangEntry
* pFirstLang
= NULL
;
779 const MsLangId::IsoLangEntry
* pEntry
= aImplIsoLangEntries
;
782 if (aLowerLang
.equalsAscii( pEntry
->maLangStr
))
784 if (*pEntry
->maCountry
)
786 if (nCountryLen
&& aUpperCountry
.equalsAscii( pEntry
->maCountry
))
791 switch (pEntry
->mnLang
)
793 // These are known to have no country assigned.
794 case LANGUAGE_BASQUE
:
795 case LANGUAGE_USER_ESPERANTO
:
796 case LANGUAGE_USER_INTERLINGUA
:
797 case LANGUAGE_USER_LOJBAN
:
808 while ( pEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
810 // Language not found at all => use default.
812 return aLastResortFallbackEntry
;
814 // Search for first entry of language with any country.
818 if (aLowerLang
.equalsAscii( pEntry
->maLangStr
))
820 if (*pEntry
->maCountry
)
825 while ( pEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
827 return aLastResortFallbackEntry
;
831 LanguageType
MsLangId::lookupFallbackLanguage(
832 const ::com::sun::star::lang::Locale
& rLocale
)
834 return lcl_lookupFallbackEntry( rLocale
).mnLang
;
839 ::com::sun::star::lang::Locale
MsLangId::lookupFallbackLocale(
840 const ::com::sun::star::lang::Locale
& rLocale
)
842 const MsLangId::IsoLangEntry
& rEntry
= lcl_lookupFallbackEntry( rLocale
);
843 return ::com::sun::star::lang::Locale(
844 rtl::OUString::createFromAscii( rEntry
.maLangStr
),
845 rtl::OUString::createFromAscii( rEntry
.maCountry
),
849 // -----------------------------------------------------------------------
852 rtl::OUString
MsLangId::convertLanguageToIsoString( LanguageType nLang
,
855 rtl::OUString aLangStr
;
856 rtl::OUString aCountry
;
857 convertLanguageToIsoNames( nLang
, aLangStr
, aCountry
);
858 if ( !aCountry
.isEmpty() )
860 rtl::OUStringBuffer
aBuf( aLangStr
);
862 aBuf
.append( aCountry
);
863 return aBuf
.makeStringAndClear();
869 // -----------------------------------------------------------------------
872 rtl::OString
MsLangId::convertLanguageToIsoByteString( LanguageType nLang
,
875 rtl::OString aLangStr
;
876 rtl::OString aCountry
;
877 convertLanguageToIsoNames( nLang
, aLangStr
, aCountry
);
878 if ( !aCountry
.isEmpty() )
880 rtl::OStringBuffer
aBuf( aLangStr
);
882 aBuf
.append( aCountry
);
883 return aBuf
.makeStringAndClear();
888 // =======================================================================
891 LanguageType
MsLangId::convertIsoNamesToLanguage( const rtl::OUString
& rLang
,
892 const rtl::OUString
& rCountry
)
894 // language is lower case in table
895 rtl::OUString aLowerLang
= rLang
.toAsciiLowerCase();
896 // country is upper case in table
897 rtl::OUString aUpperCountry
= rCountry
.toAsciiUpperCase();
899 // first look for exact match
900 const IsoLangEntry
* pFirstLang
= NULL
;
901 const IsoLangEntry
* pEntry
= aImplIsoLangEntries
;
904 if ( aLowerLang
.equalsAscii( pEntry
->maLangStr
) )
906 if ( aUpperCountry
.isEmpty() ||
907 aUpperCountry
.equalsAscii( pEntry
->maCountry
) )
908 return pEntry
->mnLang
;
911 else if ( !*pEntry
->maCountry
)
916 while ( pEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
918 // some eng countries should be mapped to a specific english language
919 if ( aLowerLang
== "en" )
921 const IsoLangEngEntry
* pEngEntry
= aImplIsoLangEngEntries
;
924 if ( aUpperCountry
.equalsAscii( pEngEntry
->maCountry
) )
925 return pEngEntry
->mnLang
;
928 while ( pEngEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
931 // test for specific languages which are not used standard ISO 3166 codes
932 const IsoLangNoneStdEntry
* pNoneStdEntry
= aImplIsoNoneStdLangEntries
;
935 if ( aLowerLang
.equalsAscii( pNoneStdEntry
->maLangStr
) )
937 // The countries in this table are not all in upper case
938 if ( aUpperCountry
.equalsIgnoreAsciiCaseAscii( pNoneStdEntry
->maCountry
) )
939 return pNoneStdEntry
->mnLang
;
943 while ( pNoneStdEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
944 pNoneStdEntry
= aImplIsoNoneStdLangEntries2
;
947 if ( aLowerLang
.equalsAscii( pNoneStdEntry
->maLangStr
) )
949 // The countries in this table are not all in upper case
950 if ( aUpperCountry
.equalsIgnoreAsciiCaseAscii( pNoneStdEntry
->maCountry
) )
951 return pNoneStdEntry
->mnLang
;
955 while ( pNoneStdEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
957 // If the language is correct, than we return the default language
959 return pFirstLang
->mnLang
;
961 // if only the country is set, look for any entry matching the country
962 // (to allow reading country and language in separate steps, in any order)
963 if ( !rCountry
.isEmpty() && rLang
.isEmpty() )
965 const IsoLangEntry
* pEntry2
= aImplIsoLangEntries
;
968 if ( aUpperCountry
.equalsAscii( pEntry2
->maCountry
) )
969 return pEntry2
->mnLang
;
972 while ( pEntry2
->mnLang
!= LANGUAGE_DONTKNOW
);
974 aLowerLang
= aUpperCountry
.toAsciiLowerCase();
977 // Now look for all other definitions, which are not standard
978 const IsoLangOtherEntry
* pOtherEntry
= aImplOtherEntries
;
981 if ( aLowerLang
.equalsAscii( pOtherEntry
->mpLangStr
) )
982 return pOtherEntry
->mnLang
;
985 while ( pOtherEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
987 return LANGUAGE_DONTKNOW
;
990 // -----------------------------------------------------------------------
993 LanguageType
MsLangId::convertIsoNamesToLanguage( const rtl::OString
& rLang
,
994 const rtl::OString
& rCountry
)
996 rtl::OUString aLang
= OStringToOUString( rLang
, RTL_TEXTENCODING_ASCII_US
);
997 rtl::OUString aCountry
= OStringToOUString( rCountry
, RTL_TEXTENCODING_ASCII_US
);
998 return convertIsoNamesToLanguage( aLang
, aCountry
);
1001 // -----------------------------------------------------------------------
1004 LanguageType
MsLangId::convertIsoStringToLanguage(
1005 const rtl::OUString
& rString
, sal_Unicode cSep
)
1007 rtl::OUString aLang
;
1008 rtl::OUString aCountry
;
1009 sal_Int32 nSepPos
= rString
.indexOf( cSep
);
1012 aLang
= rString
.copy( 0, nSepPos
);
1013 aCountry
= rString
.copy( nSepPos
+1 );
1018 return convertIsoNamesToLanguage( aLang
, aCountry
);
1021 // -----------------------------------------------------------------------
1023 struct IsoLangGLIBCModifiersEntry
1025 LanguageType mnLang
;
1026 sal_Char maLangStr
[4];
1027 sal_Char maCountry
[3];
1028 sal_Char maAtString
[9];
1031 static IsoLangGLIBCModifiersEntry
const aImplIsoLangGLIBCModifiersEntries
[] =
1033 // MS-LANGID codes ISO639-1/2/3 ISO3166 glibc modifier
1034 { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_HERZEGOVINA
, "bs", "BA", "cyrillic" },
1035 { LANGUAGE_USER_SERBIAN_LATIN_SERBIA
, "sr", "RS", "latin" }, // Serbian Latin in Serbia
1036 { LANGUAGE_SERBIAN_LATIN
, "sr", "CS", "latin" }, // Serbian Latin in Serbia and Montenegro
1037 { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO
, "sr", "ME", "latin" }, // Serbian Latin in Montenegro
1038 { LANGUAGE_SERBIAN_LATIN_NEUTRAL
, "sr", "", "latin" },
1039 { LANGUAGE_AZERI_CYRILLIC
, "az", "AZ", "cyrillic" },
1040 { LANGUAGE_UZBEK_CYRILLIC
, "uz", "UZ", "cyrillic" },
1041 { LANGUAGE_DONTKNOW
, "", "", "" } // marks end of table
1044 // convert a unix locale string into LanguageType
1047 LanguageType
MsLangId::convertUnxByteStringToLanguage(
1048 const rtl::OString
& rString
)
1051 rtl::OString aCountry
;
1052 rtl::OString aAtString
;
1054 sal_Int32 nLangSepPos
= rString
.indexOf( (sal_Char
)'_' );
1055 sal_Int32 nCountrySepPos
= rString
.indexOf( (sal_Char
)'.' );
1056 sal_Int32 nAtPos
= rString
.indexOf( (sal_Char
)'@' );
1058 if (nCountrySepPos
< 0)
1059 nCountrySepPos
= nAtPos
;
1060 if (nCountrySepPos
< 0)
1061 nCountrySepPos
= rString
.getLength();
1064 aAtString
= rString
.copy( nAtPos
+1 );
1066 if ( ((nLangSepPos
>= 0) && (nLangSepPos
> nCountrySepPos
))
1067 || ((nLangSepPos
< 0)) )
1069 // eg. "el.sun_eu_greek", "tchinese", "es.ISO8859-15"
1070 aLang
= rString
.copy( 0, nCountrySepPos
);
1072 else if ( nLangSepPos
>= 0 )
1074 // well formed iso names like "en_US.UTF-8", "sh_BA.ISO8859-2@bosnia"
1075 aLang
= rString
.copy( 0, nLangSepPos
);
1076 aCountry
= rString
.copy( nLangSepPos
+1, nCountrySepPos
- nLangSepPos
- 1);
1079 // if there is a glibc modifier, first look for exact match in modifier table
1080 if (!aAtString
.isEmpty())
1082 // language is lower case in table
1083 rtl::OString aLowerLang
= aLang
.toAsciiLowerCase();
1084 // country is upper case in table
1085 rtl::OString aUpperCountry
= aCountry
.toAsciiUpperCase();
1086 const IsoLangGLIBCModifiersEntry
* pGLIBCModifiersEntry
= aImplIsoLangGLIBCModifiersEntries
;
1088 { // avoid embedded \0 warning
1089 if (( aLowerLang
.equals( static_cast< const char* >( pGLIBCModifiersEntry
->maLangStr
))) &&
1090 ( aAtString
.equals( static_cast< const char* >( pGLIBCModifiersEntry
->maAtString
))))
1092 if ( aUpperCountry
.isEmpty() ||
1093 aUpperCountry
.equals( static_cast< const char* >( pGLIBCModifiersEntry
->maCountry
)))
1095 return pGLIBCModifiersEntry
->mnLang
;
1098 ++pGLIBCModifiersEntry
;
1100 while ( pGLIBCModifiersEntry
->mnLang
!= LANGUAGE_DONTKNOW
);
1103 return convertIsoNamesToLanguage( aLang
, aCountry
);
1106 // -----------------------------------------------------------------------
1107 // pass one IsoLangEntry to the outer world of the resource compiler
1110 const MsLangId::IsoLangEntry
* MsLangId::getIsoLangEntry( size_t nIndex
)
1112 if (nIndex
< SAL_N_ELEMENTS(aImplIsoLangEntries
))
1113 return &aImplIsoLangEntries
[ nIndex
];
1117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */