merge the formfield patch from ooo-build
[ooovba.git] / i18npool / source / isolang / isolang.cxx
blob4f3d52b42f9c80532f67250ff7fcdf0e7475d363
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: isolang.cxx,v $
10 * $Revision: 1.16.24.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
33 #include <rtl/ustring.hxx>
34 #include <rtl/string.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <rtl/strbuf.hxx>
38 #include "i18npool/mslangid.hxx"
40 // =======================================================================
42 struct IsoLangEngEntry
44 LanguageType mnLang;
45 sal_Char maCountry[3];
48 struct IsoLangNoneStdEntry
50 LanguageType mnLang;
51 sal_Char maLangStr[4];
52 sal_Char maCountry[9];
55 struct IsoLangOtherEntry
57 LanguageType mnLang;
58 const sal_Char* mpLangStr;
61 // -----------------------------------------------------------------------
63 // Entries for languages are lower case, for countries upper case, as
64 // recommended by rfc4646 (obsoletes rfc3066 (obsoletes rfc1766)).
65 // convertIsoNamesToLanguage() is case insensitive
67 // Sort order: Most used first.
69 // The default entry for a LangID <-> ISO mapping has to be first. For
70 // conversion of legacy mappings one LangID can map to multiple ISO codes, and
71 // one ISO code combination can map to multiple LangIDs. For compatibility with
72 // already existing calls it can also be a sequence as follows:
74 // LANGUAGE_ENGLISH, "en", ""
75 // LANGUAGE_ENGLISH_US, "en", "US"
77 // Here, in a convertIsoNamesToLanguage() call "en-US" is converted to
78 // LANGUAGE_ENGLISH_US and "en" is converted to LANGUAGE_ENGLISH. A call with
79 // "en-ZZ" (not in table) would result in LANGUAGE_ENGLISH because the first
80 // entry matching the language and not having a country is returned, regardless
81 // of whether being sorted before or after other entries of the same language
82 // with some country. To obtain a _locale_ (not language only) in the order
83 // given, convertLocaleToLanguageWithFallback() must be called.
85 // If the sequence instead was
87 // LANGUAGE_ENGLISH_US, "en", "US"
88 // LANGUAGE_ENGLISH, "en", ""
90 // in a convertIsoNamesToLanguage() call "en-US" is still converted to
91 // LANGUAGE_ENGLISH_US, but "en" is _also_ converted to LANGUAGE_ENGLISH_US
92 // because no country was passed and it is the first entry to match the
93 // language, see code. A call with "en-ZZ" (not in table) would still result in
94 // LANGUAGE_ENGLISH.
96 /* erAck: 2007-07-05T20:01+0200 TODO: The entire suite's "primary language
97 * only" usage and locale fall back should be cleaned up and made consistent. I
98 * strongly doubt that most callers exactly expect the behavior described.
99 * Currently these primary LangIDs are used literally in OOo code:
100 * LANGUAGE_ENGLISH LANGUAGE_CHINESE LANGUAGE_MALAY
101 * LANGUAGE_AZERI LANGUAGE_URDU LANGUAGE_KASHMIRI
104 static MsLangId::IsoLangEntry const aImplIsoLangEntries[] =
106 // MS-LANGID codes ISO639-1/2/3 ISO3166
107 { LANGUAGE_ENGLISH, "en", "" },
108 { LANGUAGE_ENGLISH_US, "en", "US" },
109 { LANGUAGE_ENGLISH_UK, "en", "GB" },
110 { LANGUAGE_ENGLISH_AUS, "en", "AU" },
111 { LANGUAGE_ENGLISH_CAN, "en", "CA" },
112 { LANGUAGE_FRENCH, "fr", "FR" },
113 { LANGUAGE_FRENCH, "fr", "" },
114 { LANGUAGE_GERMAN, "de", "DE" },
115 { LANGUAGE_ITALIAN, "it", "IT" },
116 { LANGUAGE_DUTCH, "nl", "NL" },
117 { LANGUAGE_SPANISH_MODERN, "es", "ES" },
118 { LANGUAGE_SPANISH_DATED, "es", "ES" },
119 { LANGUAGE_PORTUGUESE, "pt", "PT" },
120 { LANGUAGE_PORTUGUESE_BRAZILIAN, "pt", "BR" },
121 { LANGUAGE_DANISH, "da", "DK" },
122 { LANGUAGE_GREEK, "el", "GR" },
123 { LANGUAGE_CHINESE, "zh", "" },
124 { LANGUAGE_CHINESE_SIMPLIFIED, "zh", "CN" },
125 { LANGUAGE_CHINESE_TRADITIONAL, "zh", "TW" },
126 { LANGUAGE_CHINESE_HONGKONG, "zh", "HK" },
127 { LANGUAGE_CHINESE_SINGAPORE, "zh", "SG" },
128 { LANGUAGE_CHINESE_MACAU, "zh", "MO" },
129 { LANGUAGE_ENGLISH_HONG_KONG_SAR, "en", "HK" },
130 { LANGUAGE_JAPANESE, "ja", "JP" },
131 { LANGUAGE_KOREAN, "ko", "KR" },
132 { LANGUAGE_KOREAN_JOHAB, "ko", "KR" },
133 { LANGUAGE_USER_KOREAN_NORTH, "ko", "KP" },
134 { LANGUAGE_SWEDISH, "sv", "SE" },
135 { LANGUAGE_SWEDISH_FINLAND, "sv", "FI" },
136 { LANGUAGE_FINNISH, "fi", "FI" },
137 { LANGUAGE_RUSSIAN, "ru", "RU" },
138 { LANGUAGE_TATAR, "tt", "RU" },
139 { LANGUAGE_ENGLISH_NZ, "en", "NZ" },
140 { LANGUAGE_ENGLISH_EIRE, "en", "IE" },
141 { LANGUAGE_DUTCH_BELGIAN, "nl", "BE" },
142 { LANGUAGE_FRENCH_BELGIAN, "fr", "BE" },
143 { LANGUAGE_FRENCH_CANADIAN, "fr", "CA" },
144 { LANGUAGE_FRENCH_SWISS, "fr", "CH" },
145 { LANGUAGE_GERMAN_SWISS, "de", "CH" },
146 { LANGUAGE_GERMAN_AUSTRIAN, "de", "AT" },
147 { LANGUAGE_ITALIAN_SWISS, "it", "CH" },
148 { LANGUAGE_ALBANIAN, "sq", "AL" },
149 { LANGUAGE_ARABIC_SAUDI_ARABIA, "ar", "SA" },
150 { LANGUAGE_ARABIC_EGYPT, "ar", "EG" },
151 { LANGUAGE_ARABIC_UAE, "ar", "AE" },
152 { LANGUAGE_ARABIC_IRAQ, "ar", "IQ" },
153 { LANGUAGE_ARABIC_LIBYA, "ar", "LY" },
154 { LANGUAGE_ARABIC_ALGERIA, "ar", "DZ" },
155 { LANGUAGE_ARABIC_MOROCCO, "ar", "MA" },
156 { LANGUAGE_ARABIC_TUNISIA, "ar", "TN" },
157 { LANGUAGE_ARABIC_OMAN, "ar", "OM" },
158 { LANGUAGE_ARABIC_YEMEN, "ar", "YE" },
159 { LANGUAGE_ARABIC_SYRIA, "ar", "SY" },
160 { LANGUAGE_ARABIC_JORDAN, "ar", "JO" },
161 { LANGUAGE_ARABIC_LEBANON, "ar", "LB" },
162 { LANGUAGE_ARABIC_KUWAIT, "ar", "KW" },
163 { LANGUAGE_ARABIC_BAHRAIN, "ar", "BH" },
164 { LANGUAGE_ARABIC_QATAR, "ar", "QA" },
165 { LANGUAGE_USER_ARABIC_CHAD, "ar", "TD" },
166 { LANGUAGE_USER_ARABIC_COMOROS, "ar", "KM" },
167 { LANGUAGE_USER_ARABIC_DJIBOUTI, "ar", "DJ" },
168 { LANGUAGE_USER_ARABIC_ERITREA, "ar", "ER" },
169 { LANGUAGE_USER_ARABIC_ISRAEL, "ar", "IL" },
170 { LANGUAGE_USER_ARABIC_MAURITANIA, "ar", "MR" },
171 { LANGUAGE_USER_ARABIC_PALESTINE, "ar", "PS" },
172 { LANGUAGE_USER_ARABIC_SOMALIA, "ar", "SO" },
173 { LANGUAGE_USER_ARABIC_SUDAN, "ar", "SD" },
174 { LANGUAGE_ARABIC_PRIMARY_ONLY, "ar", "" },
175 { LANGUAGE_BASQUE, "eu", "" },
176 { LANGUAGE_BULGARIAN, "bg", "BG" },
177 { LANGUAGE_CZECH, "cs", "CZ" },
178 { LANGUAGE_CZECH, "cz", "" },
179 { LANGUAGE_ENGLISH_JAMAICA, "en", "JM" },
180 { LANGUAGE_ENGLISH_CARRIBEAN, "en", "BS" }, // not 100%, because AG is Bahamas
181 { LANGUAGE_ENGLISH_BELIZE, "en", "BZ" },
182 { LANGUAGE_ENGLISH_TRINIDAD, "en", "TT" },
183 { LANGUAGE_ENGLISH_ZIMBABWE, "en", "ZW" },
184 { LANGUAGE_ENGLISH_INDONESIA, "en", "ID" },
185 { LANGUAGE_ESTONIAN, "et", "EE" },
186 { LANGUAGE_FAEROESE, "fo", "FO" },
187 { LANGUAGE_FARSI, "fa", "IR" },
188 { LANGUAGE_FRENCH_LUXEMBOURG, "fr", "LU" },
189 { LANGUAGE_FRENCH_MONACO, "fr", "MC" },
190 { LANGUAGE_GERMAN_LUXEMBOURG, "de", "LU" },
191 { LANGUAGE_GERMAN_LIECHTENSTEIN, "de", "LI" },
192 { LANGUAGE_HEBREW, "he", "IL" }, // new: old was "iw"
193 { LANGUAGE_HEBREW, "iw", "IL" }, // old: new is "he"
194 { LANGUAGE_HUNGARIAN, "hu", "HU" },
195 { LANGUAGE_ICELANDIC, "is", "IS" },
196 { LANGUAGE_INDONESIAN, "id", "ID" }, // new: old was "in"
197 { LANGUAGE_INDONESIAN, "in", "ID" }, // old: new is "id"
198 { LANGUAGE_NORWEGIAN, "no", "NO" },
199 { LANGUAGE_NORWEGIAN_BOKMAL, "nb", "NO" },
200 { LANGUAGE_NORWEGIAN_NYNORSK, "nn", "NO" },
201 { LANGUAGE_POLISH, "pl", "PL" },
202 { LANGUAGE_RHAETO_ROMAN, "rm", "CH" },
203 { LANGUAGE_ROMANIAN, "ro", "RO" },
204 { LANGUAGE_ROMANIAN_MOLDOVA, "ro", "MD" },
205 { LANGUAGE_SLOVAK, "sk", "SK" },
206 { LANGUAGE_SLOVENIAN, "sl", "SI" },
207 { LANGUAGE_SPANISH_MEXICAN, "es", "MX" },
208 { LANGUAGE_SPANISH_GUATEMALA, "es", "GT" },
209 { LANGUAGE_SPANISH_COSTARICA, "es", "CR" },
210 { LANGUAGE_SPANISH_PANAMA, "es", "PA" },
211 { LANGUAGE_SPANISH_DOMINICAN_REPUBLIC, "es", "DO" },
212 { LANGUAGE_SPANISH_VENEZUELA, "es", "VE" },
213 { LANGUAGE_SPANISH_COLOMBIA, "es", "CO" },
214 { LANGUAGE_SPANISH_PERU, "es", "PE" },
215 { LANGUAGE_SPANISH_ARGENTINA, "es", "AR" },
216 { LANGUAGE_SPANISH_ECUADOR, "es", "EC" },
217 { LANGUAGE_SPANISH_CHILE, "es", "CL" },
218 { LANGUAGE_SPANISH_URUGUAY, "es", "UY" },
219 { LANGUAGE_SPANISH_PARAGUAY, "es", "PY" },
220 { LANGUAGE_SPANISH_BOLIVIA, "es", "BO" },
221 { LANGUAGE_SPANISH_EL_SALVADOR, "es", "SV" },
222 { LANGUAGE_SPANISH_HONDURAS, "es", "HN" },
223 { LANGUAGE_SPANISH_NICARAGUA, "es", "NI" },
224 { LANGUAGE_SPANISH_PUERTO_RICO, "es", "PR" },
225 { LANGUAGE_SPANISH_UNITED_STATES, "es", "US" },
226 { LANGUAGE_SPANISH_LATIN_AMERICA, "es", "" },
227 { LANGUAGE_TURKISH, "tr", "TR" },
228 { LANGUAGE_UKRAINIAN, "uk", "UA" },
229 { LANGUAGE_VIETNAMESE, "vi", "VN" },
230 { LANGUAGE_LATVIAN, "lv", "LV" },
231 { LANGUAGE_MACEDONIAN, "mk", "MK" },
232 { LANGUAGE_MALAY, "ms", "" },
233 { LANGUAGE_MALAY_MALAYSIA, "ms", "MY" },
234 { LANGUAGE_MALAY_BRUNEI_DARUSSALAM, "ms", "BN" },
235 { LANGUAGE_ENGLISH_MALAYSIA, "en", "MY" },
236 { LANGUAGE_THAI, "th", "TH" },
237 { LANGUAGE_LITHUANIAN, "lt", "LT" },
238 { LANGUAGE_LITHUANIAN_CLASSIC, "lt", "LT" },
239 { LANGUAGE_CROATIAN, "hr", "HR" }, // Croatian in Croatia
240 { LANGUAGE_CROATIAN_BOSNIA_HERZEGOVINA, "hr", "BA" },
241 { LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA, "bs", "BA" },
242 // { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_AND_HERZEGOVINA, "bs", "BA" }, // script codes not supported yet
243 { LANGUAGE_USER_SERBIAN_CYRILLIC_SERBIA, "sr", "RS" }, // Serbian Cyrillic in Serbia
244 { 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)
245 { LANGUAGE_SERBIAN_CYRILLIC, "sr", "CS" }, // alias to be able to integrate localizations, rsc needs it
246 { LANGUAGE_USER_SERBIAN_CYRILLIC_MONTENEGRO, "sr", "ME" },
247 { LANGUAGE_SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "sr", "BA" },
248 { LANGUAGE_SERBIAN, "sr", "" }, // SERBIAN is only LID, MS-LCID not defined (was dupe of CROATIAN)
249 { LANGUAGE_USER_SERBIAN_LATIN_SERBIA, "sh", "RS" }, // Serbian Latin in Serbia; kludge, needed to be sr_Latn_RS instead, script codes not supported yet
250 { 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
251 { LANGUAGE_SERBIAN_LATIN, "sh", "CS" }, // Serbian Latin in Serbia and Montenegro; kludge, needed to be sr_Latn_CS instead, script codes not supported yet
252 { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO, "sh", "ME" }, // Serbian Latin in Montenegro; kludge, needed to be sr_Latn_ME instead, script codes not supported yet
253 { LANGUAGE_SERBIAN_LATIN_BOSNIA_HERZEGOVINA, "sh", "BA" },
254 { LANGUAGE_SERBIAN_LATIN_NEUTRAL, "sh", "" }, // kludge, needed to be sr_Latn instead, script codes not supported yet
255 { LANGUAGE_ARMENIAN, "hy", "AM" },
256 { LANGUAGE_AZERI, "az", "" },
257 { LANGUAGE_AZERI_LATIN, "az", "AZ" },
258 // { LANGUAGE_AZERI_CYRILLIC, "az", "AZ" }, // script codes not supported yet
259 { LANGUAGE_UZBEK_LATIN, "uz", "UZ" },
260 // { LANGUAGE_UZBEK_CYRILLIC, "uz", "UZ" }, // script codes not supported yet
261 { LANGUAGE_BENGALI_BANGLADESH, "bn", "BD" },
262 { LANGUAGE_BENGALI, "bn", "IN" },
263 { LANGUAGE_BURMESE, "my", "MM" },
264 { LANGUAGE_KAZAK, "kk", "KZ" },
265 { LANGUAGE_ENGLISH_INDIA, "en", "IN" },
266 { LANGUAGE_URDU, "ur", "" },
267 { LANGUAGE_URDU_INDIA, "ur", "IN" },
268 { LANGUAGE_URDU_PAKISTAN, "ur", "PK" },
269 { LANGUAGE_HINDI, "hi", "IN" },
270 { LANGUAGE_GUJARATI, "gu", "IN" },
271 { LANGUAGE_KANNADA, "kn", "IN" },
272 { LANGUAGE_ASSAMESE, "as", "IN" },
273 { LANGUAGE_KASHMIRI, "ks", "" },
274 { LANGUAGE_KASHMIRI_INDIA, "ks", "IN" },
275 { LANGUAGE_MALAYALAM, "ml", "IN" },
276 { LANGUAGE_MANIPURI, "mni", "IN" },
277 { LANGUAGE_MARATHI, "mr", "IN" },
278 { LANGUAGE_KONKANI, "kok", "IN" },
279 { LANGUAGE_NEPALI, "ne", "NP" },
280 { LANGUAGE_NEPALI_INDIA, "ne", "IN" },
281 { LANGUAGE_ORIYA, "or", "IN" },
282 { LANGUAGE_PUNJABI, "pa", "IN" },
283 { LANGUAGE_SANSKRIT, "sa", "IN" },
284 { LANGUAGE_SINDHI, "sd", "IN" },
285 { LANGUAGE_TAMIL, "ta", "IN" },
286 { LANGUAGE_TELUGU, "te", "IN" },
287 { LANGUAGE_PUNJABI_PAKISTAN, "lah", "PK" }, // preferring "lah" over "pa" for Western Punjabi, see http://www.ethnologue.com/show_language.asp?code=PNB
288 { LANGUAGE_PUNJABI_PAKISTAN, "pa", "PK" },
289 { LANGUAGE_SINDHI_PAKISTAN, "sd", "PK" },
290 { LANGUAGE_BELARUSIAN, "be", "BY" },
291 { LANGUAGE_CATALAN, "ca", "ES" }, // Spain (default)
292 { LANGUAGE_CATALAN, "ca", "AD" }, // Andorra
293 { LANGUAGE_USER_CATALAN_VALENCIAN, "ca", "XV" }, // XV: ISO 3166 user-assigned; workaround for UI localization only, do not use in document content!
294 { LANGUAGE_FRENCH_CAMEROON, "fr", "CM" },
295 { LANGUAGE_FRENCH_COTE_D_IVOIRE, "fr", "CI" },
296 { LANGUAGE_FRENCH_HAITI, "fr", "HT" },
297 { LANGUAGE_FRENCH_MALI, "fr", "ML" },
298 { LANGUAGE_FRENCH_SENEGAL, "fr", "SN" },
299 { LANGUAGE_FRENCH_ZAIRE, "fr", "CD" }, // Democratic Republic Of Congo
300 { LANGUAGE_FRENCH_MOROCCO, "fr", "MA" },
301 { LANGUAGE_FRENCH_REUNION, "fr", "RE" },
302 { LANGUAGE_FRENCH_NORTH_AFRICA, "fr", "" },
303 { LANGUAGE_FRENCH_WEST_INDIES, "fr", "" }, // unknown ISO country code
304 { LANGUAGE_FRISIAN_NETHERLANDS, "fy", "NL" },
305 { LANGUAGE_GAELIC_IRELAND, "ga", "IE" },
306 { LANGUAGE_GAELIC_SCOTLAND, "gd", "GB" },
307 { LANGUAGE_GALICIAN, "gl", "ES" },
308 { LANGUAGE_GEORGIAN, "ka", "GE" },
309 { LANGUAGE_KHMER, "km", "KH" },
310 { LANGUAGE_KIRGHIZ, "ky", "KG" },
311 { LANGUAGE_LAO, "lo", "LA" },
312 { LANGUAGE_MALTESE, "mt", "MT" },
313 { LANGUAGE_MONGOLIAN, "mn", "MN" }, // Cyrillic script
314 { LANGUAGE_MONGOLIAN_MONGOLIAN, "mn", "MN" },
315 { LANGUAGE_RUSSIAN_MOLDOVA, "mo", "MD" },
316 { LANGUAGE_SWAHILI, "sw", "KE" },
317 { LANGUAGE_USER_SWAHILI_TANZANIA, "sw", "TZ" },
318 { LANGUAGE_TAJIK, "tg", "TJ" },
319 { LANGUAGE_TIBETAN, "bo", "CN" }, // CN politically correct?
320 { LANGUAGE_DZONGKHA, "dz", "BT" },
321 { LANGUAGE_TURKMEN, "tk", "TM" },
322 { LANGUAGE_WELSH, "cy", "GB" },
323 { LANGUAGE_SESOTHO, "st", "ZA" },
324 { LANGUAGE_SEPEDI, "nso", "ZA" },
325 { LANGUAGE_SEPEDI, "ns", "ZA" }, // fake "ns" for compatibility with existing OOo1.1.x localization to be able to read those documents
326 { LANGUAGE_TSONGA, "ts", "ZA" },
327 { LANGUAGE_TSWANA, "tn", "ZA" },
328 { LANGUAGE_ENGLISH_SAFRICA, "en", "ZA" },
329 { LANGUAGE_AFRIKAANS, "af", "ZA" },
330 { LANGUAGE_VENDA, "ve", "ZA" }, // default 639-1
331 { LANGUAGE_VENDA, "ven", "ZA" }, // 639-2 may have been used temporarily since 2004-07-23
332 { LANGUAGE_XHOSA, "xh", "ZA" },
333 { LANGUAGE_ZULU, "zu", "ZA" },
334 { LANGUAGE_QUECHUA_ECUADOR, "qu", "EC" },
335 { LANGUAGE_QUECHUA_PERU, "qu", "PE" },
336 { LANGUAGE_QUECHUA_BOLIVIA, "qu", "BO" }, // macro: quh-BO, qul-BO
337 { LANGUAGE_PASHTO, "ps", "AF" },
338 { LANGUAGE_OROMO, "om", "ET" },
339 { LANGUAGE_DHIVEHI, "dv", "MV" },
340 { LANGUAGE_UIGHUR_CHINA, "ug", "CN" },
341 { LANGUAGE_TIGRIGNA_ETHIOPIA, "ti", "ET" },
342 { LANGUAGE_TIGRIGNA_ERITREA, "ti", "ER" },
343 { LANGUAGE_AMHARIC_ETHIOPIA, "am", "ET" },
344 { LANGUAGE_GUARANI_PARAGUAY, "gug", "PY" },
345 { LANGUAGE_HAWAIIAN_UNITED_STATES, "haw", "US" },
346 { LANGUAGE_EDO, "bin", "NG" },
347 { LANGUAGE_FULFULDE_NIGERIA, "ff", "NG" },
348 { LANGUAGE_HAUSA_NIGERIA, "ha", "NG" },
349 { LANGUAGE_USER_HAUSA_GHANA, "ha", "GH" },
350 { LANGUAGE_IGBO_NIGERIA, "ig", "NG" },
351 { LANGUAGE_KANURI_NIGERIA, "kr", "NG" },
352 { LANGUAGE_YORUBA, "yo", "NG" },
353 { LANGUAGE_SOMALI, "so", "SO" },
354 { LANGUAGE_PAPIAMENTU, "pap", "AN" },
355 { LANGUAGE_ENGLISH_SINGAPORE, "en", "SG" },
356 { LANGUAGE_YIDDISH, "yi", "IL" }, // new: old was "ji"
357 { LANGUAGE_YIDDISH, "ji", "IL" }, // old: new is "yi"
358 { LANGUAGE_SYRIAC, "syr", "TR" }, // "TR" according to http://www.ethnologue.com/show_language.asp?code=SYC
359 { LANGUAGE_SINHALESE_SRI_LANKA, "si", "LK" },
360 { LANGUAGE_CHEROKEE_UNITED_STATES, "chr", "US" },
361 { LANGUAGE_INUKTITUT_LATIN_CANADA, "iu", "CA" },
362 // { LANGUAGE_INUKTITUT_SYLLABICS_CANADA, "iu", "CA" }, // script codes not supported yet
363 { LANGUAGE_SAMI_NORTHERN_NORWAY, "se", "NO" },
364 { LANGUAGE_SAMI_INARI, "smn", "FI" },
365 { LANGUAGE_SAMI_LULE_NORWAY, "smj", "NO" },
366 { LANGUAGE_SAMI_LULE_SWEDEN, "smj", "SE" },
367 { LANGUAGE_SAMI_NORTHERN_FINLAND, "se", "FI" },
368 { LANGUAGE_SAMI_NORTHERN_SWEDEN, "se", "SE" },
369 { LANGUAGE_SAMI_SKOLT, "sms", "FI" },
370 { LANGUAGE_SAMI_SOUTHERN_NORWAY, "sma", "NO" },
371 { LANGUAGE_SAMI_SOUTHERN_SWEDEN, "sma", "SE" },
372 { LANGUAGE_USER_SAMI_KILDIN_RUSSIA, "sjd", "RU" },
373 { LANGUAGE_MAPUDUNGUN_CHILE, "arn", "CL" },
374 { LANGUAGE_CORSICAN_FRANCE, "co", "FR" },
375 { 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.
376 { LANGUAGE_YAKUT_RUSSIA, "sah", "RU" },
377 { LANGUAGE_MOHAWK_CANADA, "moh", "CA" },
378 { LANGUAGE_BASHKIR_RUSSIA, "ba", "RU" },
379 { LANGUAGE_KICHE_GUATEMALA, "qut", "GT" },
380 { LANGUAGE_DARI_AFGHANISTAN, "gbz", "AF" },
381 { LANGUAGE_WOLOF_SENEGAL, "wo", "SN" },
382 { LANGUAGE_FILIPINO, "fil", "PH" },
383 { LANGUAGE_USER_TAGALOG, "tl", "PH" },
384 { LANGUAGE_ENGLISH_PHILIPPINES, "en", "PH" },
385 // { LANGUAGE_IBIBIO_NIGERIA, "nic", "NG" }, // ISO "nic" is only a collective language code
386 { LANGUAGE_YI, "ii", "CN" },
387 // { LANGUAGE_TAMAZIGHT_LATIN, "ber", "" }, // ISO "ber" only collective!
388 // { LANGUAGE_TAMAZIGHT_ARABIC, "ber", "" }, // ISO "ber" only collective!
389 { LANGUAGE_LATIN, "la", "VA" },
390 { LANGUAGE_OBSOLETE_USER_LATIN, "la", "VA" },
391 { LANGUAGE_USER_ESPERANTO, "eo", "" },
392 { LANGUAGE_USER_INTERLINGUA, "ia", "" },
393 { LANGUAGE_MAORI_NEW_ZEALAND, "mi", "NZ" },
394 { LANGUAGE_OBSOLETE_USER_MAORI, "mi", "NZ" },
395 { LANGUAGE_KINYARWANDA_RWANDA, "rw", "RW" },
396 { LANGUAGE_OBSOLETE_USER_KINYARWANDA, "rw", "RW" },
397 { 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
398 { LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN,"hsb", "DE" },
399 { 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
400 { LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN,"dsb", "DE" },
401 { LANGUAGE_OCCITAN_FRANCE, "oc", "FR" },
402 { LANGUAGE_OBSOLETE_USER_OCCITAN, "oc", "FR" },
403 { LANGUAGE_USER_KURDISH_TURKEY, "ku", "TR" },
404 { LANGUAGE_USER_KURDISH_SYRIA, "ku", "SY" },
405 { LANGUAGE_USER_KURDISH_IRAQ, "ku", "IQ" },
406 { LANGUAGE_USER_KURDISH_IRAN, "ku", "IR" },
407 { LANGUAGE_USER_SARDINIAN, "sc", "IT" },
408 { LANGUAGE_BRETON_FRANCE, "br", "FR" },
409 { LANGUAGE_OBSOLETE_USER_BRETON, "br", "FR" },
410 { LANGUAGE_KALAALLISUT_GREENLAND, "kl", "GL" },
411 { LANGUAGE_OBSOLETE_USER_KALAALLISUT, "kl", "GL" },
412 { LANGUAGE_USER_SWAZI, "ss", "ZA" },
413 { LANGUAGE_USER_NDEBELE_SOUTH, "nr", "ZA" },
414 { LANGUAGE_USER_TSWANA_BOTSWANA, "tn", "BW" },
415 { LANGUAGE_USER_MOORE, "mos", "BF" },
416 { LANGUAGE_USER_BAMBARA, "bm", "ML" },
417 { LANGUAGE_USER_AKAN, "ak", "GH" },
418 { LANGUAGE_LUXEMBOURGISH_LUXEMBOURG, "lb", "LU" },
419 { LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH, "lb", "LU" },
420 { LANGUAGE_USER_FRIULIAN, "fur", "IT" },
421 { LANGUAGE_USER_FIJIAN, "fj", "FJ" },
422 { LANGUAGE_USER_AFRIKAANS_NAMIBIA, "af", "NA" },
423 { LANGUAGE_USER_ENGLISH_NAMIBIA, "en", "NA" },
424 { LANGUAGE_USER_WALLOON, "wa", "BE" },
425 { LANGUAGE_USER_COPTIC, "cop", "EG" },
426 { LANGUAGE_USER_GASCON, "gsc", "FR" },
427 { LANGUAGE_USER_GERMAN_BELGIUM, "de", "BE" },
428 { LANGUAGE_USER_CHUVASH, "cv", "RU" },
429 { LANGUAGE_USER_EWE_GHANA, "ee", "GH" },
430 { LANGUAGE_USER_ENGLISH_GHANA, "en", "GH" },
431 { LANGUAGE_USER_SANGO, "sg", "CF" },
432 { LANGUAGE_USER_GANDA, "lg", "UG" },
433 { LANGUAGE_USER_LINGALA_DRCONGO, "ln", "CD" },
434 { LANGUAGE_USER_LOW_GERMAN, "nds", "DE" },
435 { LANGUAGE_USER_HILIGAYNON, "hil", "PH" },
436 { LANGUAGE_USER_NYANJA, "ny", "MW" },
437 { LANGUAGE_USER_KASHUBIAN, "csb", "PL" },
438 { LANGUAGE_USER_SPANISH_CUBA, "es", "CU" },
439 { LANGUAGE_USER_QUECHUA_NORTH_BOLIVIA, "qul", "BO" },
440 { LANGUAGE_USER_QUECHUA_SOUTH_BOLIVIA, "quh", "BO" },
441 { LANGUAGE_USER_BODO_INDIA, "brx", "IN" },
442 { LANGUAGE_USER_DOGRI_INDIA, "dgo", "IN" },
443 { LANGUAGE_USER_MAITHILI_INDIA, "mai", "IN" },
444 { LANGUAGE_USER_SANTALI_INDIA, "sat", "IN" },
445 { LANGUAGE_USER_TETUN, "tet", "ID" },
446 { LANGUAGE_USER_TETUN_TIMOR_LESTE, "tet", "TL" },
447 { LANGUAGE_USER_TOK_PISIN, "tpi", "PG" },
448 { LANGUAGE_USER_SHUSWAP, "shs", "CA" },
449 { LANGUAGE_USER_ANCIENT_GREEK, "grc", "GR" },
450 { LANGUAGE_USER_ASTURIAN, "ast", "ES" },
451 { LANGUAGE_NONE, "zxx", "" }, // added to ISO 639-2 on 2006-01-11: Used to declare the absence of linguistic information
452 { LANGUAGE_DONTKNOW, "", "" } // marks end of table
455 static MsLangId::IsoLangEntry aLastResortFallbackEntry =
456 { LANGUAGE_ENGLISH_US, "en", "US" };
458 // -----------------------------------------------------------------------
460 // In this table are the countries which should mapped to a specific
461 // english language
462 static IsoLangEngEntry const aImplIsoLangEngEntries[] =
464 { LANGUAGE_ENGLISH_UK, "AO" }, // Angola
465 { LANGUAGE_ENGLISH_UK, "BJ" }, // Benin
466 { LANGUAGE_ENGLISH_UK, "BW" }, // Botswana
467 { LANGUAGE_ENGLISH_UK, "BI" }, // Burundi
468 { LANGUAGE_ENGLISH_UK, "CM" }, // Cameroon
469 { LANGUAGE_ENGLISH_UK, "GA" }, // Gabon
470 { LANGUAGE_ENGLISH_UK, "GM" }, // Gambia
471 { LANGUAGE_ENGLISH_UK, "GH" }, // Ghana
472 { LANGUAGE_ENGLISH_UK, "GN" }, // Guinea
473 { LANGUAGE_ENGLISH_UK, "LS" }, // Lesotho
474 { LANGUAGE_ENGLISH_UK, "MW" }, // Malawi
475 { LANGUAGE_ENGLISH_UK, "MT" }, // Malta
476 { LANGUAGE_ENGLISH_UK, "NA" }, // Namibia
477 { LANGUAGE_ENGLISH_UK, "NG" }, // Nigeria
478 { LANGUAGE_ENGLISH_UK, "UG" }, // Uganda
479 { LANGUAGE_ENGLISH_UK, "ZM" }, // Zambia
480 { LANGUAGE_ENGLISH_UK, "ZW" }, // Zimbabwe
481 { LANGUAGE_ENGLISH_UK, "SZ" }, // Swaziland
482 { LANGUAGE_ENGLISH_UK, "NG" }, // Sierra Leone
483 { LANGUAGE_ENGLISH_UK, "KN" }, // Saint Kitts and Nevis
484 { LANGUAGE_ENGLISH_UK, "SH" }, // St. Helena
485 { LANGUAGE_ENGLISH_UK, "IO" }, // British Indian Oceanic Territory
486 { LANGUAGE_ENGLISH_UK, "FK" }, // Falkland Islands
487 { LANGUAGE_ENGLISH_UK, "GI" }, // Gibraltar
488 { LANGUAGE_ENGLISH_UK, "KI" }, // Kiribati
489 { LANGUAGE_ENGLISH_UK, "VG" }, // Virgin Islands
490 { LANGUAGE_ENGLISH_UK, "MU" }, // Mauritius
491 { LANGUAGE_ENGLISH_UK, "FJ" }, // Fiji
492 { LANGUAGE_ENGLISH_US, "KI" }, // Kiribati
493 { LANGUAGE_ENGLISH_US, "LR" }, // Liberia
494 { LANGUAGE_ENGLISH_US, "GU" }, // Guam
495 { LANGUAGE_ENGLISH_US, "MH" }, // Marshall Islands
496 { LANGUAGE_ENGLISH_US, "PW" }, // Palau
497 { LANGUAGE_ENGLISH_CARRIBEAN, "AI" }, // Anguilla
498 { LANGUAGE_ENGLISH_CARRIBEAN, "AG" }, // Antigua and Barbuda
499 { LANGUAGE_ENGLISH_CARRIBEAN, "BS" }, // Bahamas
500 { LANGUAGE_ENGLISH_CARRIBEAN, "BB" }, // Barbedos
501 { LANGUAGE_ENGLISH_CARRIBEAN, "BM" }, // Bermuda
502 { LANGUAGE_ENGLISH_CARRIBEAN, "KY" }, // Cayman Islands
503 { LANGUAGE_ENGLISH_CARRIBEAN, "GD" }, // Grenada
504 { LANGUAGE_ENGLISH_CARRIBEAN, "DM" }, // Dominica
505 { LANGUAGE_ENGLISH_CARRIBEAN, "HT" }, // Haiti
506 { LANGUAGE_ENGLISH_CARRIBEAN, "MS" }, // Montserrat
507 { LANGUAGE_ENGLISH_CARRIBEAN, "FM" }, // Micronesia
508 { LANGUAGE_ENGLISH_CARRIBEAN, "VC" }, // St. Vincent / Grenadines
509 { LANGUAGE_ENGLISH_CARRIBEAN, "LC" }, // Saint Lucia
510 { LANGUAGE_ENGLISH_CARRIBEAN, "TC" }, // Turks & Caicos Islands
511 { LANGUAGE_ENGLISH_CARRIBEAN, "GY" }, // Guyana
512 { LANGUAGE_ENGLISH_CARRIBEAN, "TT" }, // Trinidad and Tobago
513 { LANGUAGE_ENGLISH_AUS, "CX" }, // Christmas Islands
514 { LANGUAGE_ENGLISH_AUS, "CC" }, // Cocos (Keeling) Islands
515 { LANGUAGE_ENGLISH_AUS, "NF" }, // Norfolk Island
516 { LANGUAGE_ENGLISH_AUS, "PG" }, // Papua New Guinea
517 { LANGUAGE_ENGLISH_AUS, "SB" }, // Solomon Islands
518 { LANGUAGE_ENGLISH_AUS, "TV" }, // Tuvalu
519 { LANGUAGE_ENGLISH_AUS, "NR" }, // Nauru
520 { LANGUAGE_ENGLISH_NZ, "CK" }, // Cook Islands
521 { LANGUAGE_ENGLISH_NZ, "NU" }, // Niue
522 { LANGUAGE_ENGLISH_NZ, "TK" }, // Tokelau
523 { LANGUAGE_ENGLISH_NZ, "TO" }, // Tonga
524 { LANGUAGE_DONTKNOW, "" } // marks end of table
527 // -----------------------------------------------------------------------
529 static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries[] =
531 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "BOK" }, // registered subtags for "no" in rfc1766
532 { LANGUAGE_NORWEGIAN_NYNORSK, "no", "NYN" }, // registered subtags for "no" in rfc1766
533 { LANGUAGE_SERBIAN_LATIN, "sr", "latin" },
534 { LANGUAGE_SERBIAN_CYRILLIC, "sr", "cyrillic" },
535 { LANGUAGE_AZERI_LATIN, "az", "latin" },
536 { LANGUAGE_AZERI_CYRILLIC, "az", "cyrillic" },
537 { LANGUAGE_DONTKNOW, "", "" } // marks end of table
540 // -----------------------------------------------------------------------
542 // in this table are only names to find the best language
543 static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries2[] =
545 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmaal" },
546 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmal" },
547 { LANGUAGE_NORWEGIAN_NYNORSK, "no", "nynorsk" },
548 { LANGUAGE_DONTKNOW, "", "" } // marks end of table
551 // -----------------------------------------------------------------------
553 // in this table are only names to find the best language
554 static IsoLangOtherEntry const aImplOtherEntries[] =
556 { LANGUAGE_ENGLISH_US, "c" },
557 { LANGUAGE_CHINESE, "chinese" },
558 { LANGUAGE_GERMAN, "german" },
559 { LANGUAGE_JAPANESE, "japanese" },
560 { LANGUAGE_KOREAN, "korean" },
561 { LANGUAGE_ENGLISH_US, "posix" },
562 { LANGUAGE_CHINESE_TRADITIONAL, "tchinese" },
563 { LANGUAGE_DONTKNOW, NULL } // marks end of table
566 // =======================================================================
568 // static
569 void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
570 rtl::OUString& rLangStr, rtl::OUString& rCountry )
572 if ( nLang == LANGUAGE_SYSTEM )
573 nLang = MsLangId::getSystemLanguage();
575 // Search for LangID (in this table we find only defined ISO combinations)
576 const IsoLangEntry* pEntry = aImplIsoLangEntries;
579 if ( pEntry->mnLang == nLang )
581 rLangStr = rtl::OUString::createFromAscii( pEntry->maLangStr );
582 rCountry = rtl::OUString::createFromAscii( pEntry->maCountry );
583 return;
585 ++pEntry;
587 while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
589 // Search for LangID if we didn't find a specific ISO combination.
590 // All entries in this table are allowed for mime specifications,
591 // but not defined ISO combinations.
592 const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
595 if ( pNoneStdEntry->mnLang == nLang )
597 rLangStr = rtl::OUString::createFromAscii( pNoneStdEntry->maLangStr );
598 rCountry = rtl::OUString::createFromAscii( pNoneStdEntry->maCountry );
599 return;
601 ++pNoneStdEntry;
603 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
605 // not found
606 rLangStr = rtl::OUString();
607 rCountry = rtl::OUString();
610 // -----------------------------------------------------------------------
612 // static
613 void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
614 rtl::OString& rLangStr, rtl::OString& rCountry )
616 if ( nLang == LANGUAGE_SYSTEM )
617 nLang = MsLangId::getSystemLanguage();
619 // Search for LangID (in this table we find only defined ISO combinations)
620 const IsoLangEntry* pEntry = aImplIsoLangEntries;
623 if ( pEntry->mnLang == nLang )
625 rLangStr = rtl::OString( pEntry->maLangStr );
626 rCountry = rtl::OString( pEntry->maCountry );
627 return;
629 ++pEntry;
631 while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
633 // Search for LangID if we didn't find a specific ISO combination.
634 // All entries in this table are allowed for mime specifications,
635 // but not defined ISO combinations.
636 const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
639 if ( pNoneStdEntry->mnLang == nLang )
641 rLangStr = rtl::OString( pNoneStdEntry->maLangStr );
642 rCountry = rtl::OString( pNoneStdEntry->maCountry );
643 return;
645 ++pNoneStdEntry;
647 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
649 // not found
650 rLangStr = rtl::OString();
651 rCountry = rtl::OString();
654 // -----------------------------------------------------------------------
656 static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry( LanguageType nLang )
658 LanguageType nPrimary = MsLangId::getPrimaryLanguage( nLang);
660 // Search for LangID and remember first lang-only.
661 const MsLangId::IsoLangEntry* pFirstPrimary = NULL;
662 const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries;
665 if (pEntry->mnLang == nLang)
667 if (*pEntry->maCountry)
668 return *pEntry;
669 switch (nLang)
671 // These are known to have no country assigned.
672 case LANGUAGE_BASQUE:
673 case LANGUAGE_USER_ESPERANTO:
674 case LANGUAGE_USER_INTERLINGUA:
675 return *pEntry;
676 default:
677 ; // nothing
680 if (!pFirstPrimary &&
681 MsLangId::getPrimaryLanguage( pEntry->mnLang) == nPrimary)
682 pFirstPrimary = pEntry;
683 ++pEntry;
685 while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
687 // Language not found at all => use default.
688 if (!pFirstPrimary)
689 return aLastResortFallbackEntry;
691 // Search for first entry of primary language with any country.
692 pEntry = pFirstPrimary;
695 if (MsLangId::getPrimaryLanguage( pEntry->mnLang) == nLang)
697 if (*pEntry->maCountry)
698 return *pEntry;
700 ++pEntry;
702 while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
704 return aLastResortFallbackEntry;
707 // static
708 LanguageType MsLangId::lookupFallbackLanguage( LanguageType nLang )
710 return lcl_lookupFallbackEntry( nLang).mnLang;
714 // static
715 ::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale( LanguageType nLang )
717 const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( nLang);
718 return ::com::sun::star::lang::Locale(
719 rtl::OUString::createFromAscii( rEntry.maLangStr),
720 rtl::OUString::createFromAscii( rEntry.maCountry),
721 rtl::OUString());
724 // -----------------------------------------------------------------------
726 static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry(
727 const ::com::sun::star::lang::Locale & rLocale )
729 // language is lower case in table
730 rtl::OUString aLowerLang = rLocale.Language.toAsciiLowerCase();
731 // country is upper case in table
732 rtl::OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
733 sal_Int32 nCountryLen = aUpperCountry.getLength();
735 // Search for locale and remember first lang-only.
736 const MsLangId::IsoLangEntry* pFirstLang = NULL;
737 const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries;
740 if (aLowerLang.equalsAscii( pEntry->maLangStr))
742 if (*pEntry->maCountry)
744 if (nCountryLen && aUpperCountry.equalsAscii( pEntry->maCountry))
745 return *pEntry;
747 else
749 switch (pEntry->mnLang)
751 // These are known to have no country assigned.
752 case LANGUAGE_BASQUE:
753 case LANGUAGE_USER_ESPERANTO:
754 case LANGUAGE_USER_INTERLINGUA:
755 return *pEntry;
756 default:
757 ; // nothing
760 if (!pFirstLang)
761 pFirstLang = pEntry;
763 ++pEntry;
765 while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
767 // Language not found at all => use default.
768 if (!pFirstLang)
769 return aLastResortFallbackEntry;
771 // Search for first entry of language with any country.
772 pEntry = pFirstLang;
775 if (aLowerLang.equalsAscii( pEntry->maLangStr))
777 if (*pEntry->maCountry)
778 return *pEntry;
780 ++pEntry;
782 while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
784 return aLastResortFallbackEntry;
787 // static
788 LanguageType MsLangId::lookupFallbackLanguage(
789 const ::com::sun::star::lang::Locale & rLocale )
791 return lcl_lookupFallbackEntry( rLocale).mnLang;
795 // static
796 ::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale(
797 const ::com::sun::star::lang::Locale & rLocale )
799 const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( rLocale);
800 return ::com::sun::star::lang::Locale(
801 rtl::OUString::createFromAscii( rEntry.maLangStr),
802 rtl::OUString::createFromAscii( rEntry.maCountry),
803 rtl::OUString());
806 // -----------------------------------------------------------------------
808 // static
809 rtl::OUString MsLangId::convertLanguageToIsoString( LanguageType nLang,
810 sal_Unicode cSep )
812 rtl::OUString aLangStr;
813 rtl::OUString aCountry;
814 convertLanguageToIsoNames( nLang, aLangStr, aCountry );
815 if ( aCountry.getLength() )
817 rtl::OUStringBuffer aBuf( aLangStr);
818 aBuf.append( cSep );
819 aBuf.append( aCountry );
820 return aBuf.makeStringAndClear();
822 else
823 return aLangStr;
826 // -----------------------------------------------------------------------
828 // static
829 rtl::OString MsLangId::convertLanguageToIsoByteString( LanguageType nLang,
830 sal_Char cSep )
832 rtl::OString aLangStr;
833 rtl::OString aCountry;
834 convertLanguageToIsoNames( nLang, aLangStr, aCountry );
835 if ( aCountry.getLength() )
837 rtl::OStringBuffer aBuf( aLangStr);
838 aBuf.append( cSep );
839 aBuf.append( aCountry );
840 return aBuf.makeStringAndClear();
842 return aLangStr;
845 // =======================================================================
847 // static
848 LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OUString& rLang,
849 const rtl::OUString& rCountry )
851 // language is lower case in table
852 rtl::OUString aLowerLang = rLang.toAsciiLowerCase();
853 // country is upper case in table
854 rtl::OUString aUpperCountry = rCountry.toAsciiUpperCase();
856 // first look for exact match
857 const IsoLangEntry* pFirstLang = NULL;
858 const IsoLangEntry* pEntry = aImplIsoLangEntries;
861 if ( aLowerLang.equalsAscii( pEntry->maLangStr ) )
863 if ( !aUpperCountry.getLength() ||
864 aUpperCountry.equalsAscii( pEntry->maCountry ) )
865 return pEntry->mnLang;
866 if ( !pFirstLang )
867 pFirstLang = pEntry;
868 else if ( !*pEntry->maCountry )
869 pFirstLang = pEntry;
871 ++pEntry;
873 while ( pEntry->mnLang != LANGUAGE_DONTKNOW );
875 // some eng countries should be mapped to a specific english language
876 if ( aLowerLang.equalsAscii( "en" ) )
878 const IsoLangEngEntry* pEngEntry = aImplIsoLangEngEntries;
881 if ( aUpperCountry.equalsAscii( pEngEntry->maCountry ) )
882 return pEngEntry->mnLang;
883 ++pEngEntry;
885 while ( pEngEntry->mnLang != LANGUAGE_DONTKNOW );
888 // test for specific languages which are not used standard ISO 3166 codes
889 const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
892 if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) )
894 // The countries in this table are not all in upper case
895 if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) )
896 return pNoneStdEntry->mnLang;
898 ++pNoneStdEntry;
900 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
901 pNoneStdEntry = aImplIsoNoneStdLangEntries2;
904 if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) )
906 // The countries in this table are not all in upper case
907 if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) )
908 return pNoneStdEntry->mnLang;
910 ++pNoneStdEntry;
912 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
914 // If the language is correct, than we return the default language
915 if ( pFirstLang )
916 return pFirstLang->mnLang;
918 // if only the country is set, look for any entry matching the country
919 // (to allow reading country and language in separate steps, in any order)
920 if ( rCountry.getLength() && !rLang.getLength() )
922 const IsoLangEntry* pEntry2 = aImplIsoLangEntries;
925 if ( aUpperCountry.equalsAscii( pEntry2->maCountry ) )
926 return pEntry2->mnLang;
927 ++pEntry2;
929 while ( pEntry2->mnLang != LANGUAGE_DONTKNOW );
931 aLowerLang = aUpperCountry.toAsciiLowerCase();
934 // Now look for all other definitions, which are not standard
935 const IsoLangOtherEntry* pOtherEntry = aImplOtherEntries;
938 if ( aLowerLang.equalsAscii( pOtherEntry->mpLangStr ) )
939 return pOtherEntry->mnLang;
940 ++pOtherEntry;
942 while ( pOtherEntry->mnLang != LANGUAGE_DONTKNOW );
944 return LANGUAGE_DONTKNOW;
947 // -----------------------------------------------------------------------
949 // static
950 LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OString& rLang,
951 const rtl::OString& rCountry )
953 rtl::OUString aLang = OStringToOUString( rLang, RTL_TEXTENCODING_ASCII_US);
954 rtl::OUString aCountry = OStringToOUString( rCountry, RTL_TEXTENCODING_ASCII_US);
955 return convertIsoNamesToLanguage( aLang, aCountry);
958 // -----------------------------------------------------------------------
960 // static
961 LanguageType MsLangId::convertIsoStringToLanguage(
962 const rtl::OUString& rString, sal_Unicode cSep )
964 rtl::OUString aLang;
965 rtl::OUString aCountry;
966 sal_Int32 nSepPos = rString.indexOf( cSep );
967 if ( nSepPos >= 0 )
969 aLang = rString.copy( 0, nSepPos );
970 aCountry = rString.copy( nSepPos+1 );
972 else
973 aLang = rString;
975 return convertIsoNamesToLanguage( aLang, aCountry );
978 // -----------------------------------------------------------------------
980 // static
981 LanguageType MsLangId::convertIsoByteStringToLanguage(
982 const rtl::OString& rString, sal_Char cSep )
984 rtl::OString aLang;
985 rtl::OString aCountry;
986 sal_Int32 nSepPos = rString.indexOf( cSep );
987 if ( nSepPos >= 0 )
989 aLang = rString.copy( 0, nSepPos );
990 aCountry = rString.copy( nSepPos+1 );
992 else
993 aLang = rString;
995 return convertIsoNamesToLanguage( aLang, aCountry );
998 // -----------------------------------------------------------------------
999 // convert a unix locale string into LanguageType
1001 // static
1002 LanguageType MsLangId::convertUnxByteStringToLanguage(
1003 const rtl::OString& rString )
1005 rtl::OString aLang;
1006 rtl::OString aCountry;
1008 sal_Int32 nLangSepPos = rString.indexOf( (sal_Char)'_' );
1009 sal_Int32 nCountrySepPos = rString.indexOf( (sal_Char)'.' );
1011 if (nCountrySepPos < 0)
1012 nCountrySepPos = rString.indexOf( (sal_Char)'@' );
1013 if (nCountrySepPos < 0)
1014 nCountrySepPos = rString.getLength();
1016 if ( ((nLangSepPos >= 0) && (nLangSepPos > nCountrySepPos))
1017 || ((nLangSepPos < 0)) )
1019 // eg. "el.sun_eu_greek", "tchinese", "es.ISO8859-15"
1020 aLang = rString.copy( 0, nCountrySepPos );
1022 else if ( nLangSepPos >= 0 )
1024 // well formed iso names like "en_US.UTF-8", "sh_BA.ISO8859-2@bosnia"
1025 aLang = rString.copy( 0, nLangSepPos );
1026 aCountry = rString.copy( nLangSepPos+1, nCountrySepPos - nLangSepPos - 1);
1029 return convertIsoNamesToLanguage( aLang, aCountry );
1032 // -----------------------------------------------------------------------
1033 // pass one IsoLangEntry to the outer world of the resource compiler
1035 // static
1036 const MsLangId::IsoLangEntry* MsLangId::getIsoLangEntry( size_t nIndex )
1038 if (nIndex < sizeof( aImplIsoLangEntries) / sizeof( IsoLangEntry))
1039 return &aImplIsoLangEntries[ nIndex];
1040 return 0;