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