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