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, "ca", "XV" }, // XV: ISO 3166 user-assigned; workaround for UI localization only, do not use in document content! 287 { LANGUAGE_CATALAN, "qcv", "ES" }, // qcv: ISO 639-3 reserved-for-local-use; UI localization quirk only, do not use in document content! 288 // { LANGUAGE_USER_CATALAN_VALENCIAN, "ca", "ES" }, // In case MS format files escaped into the wild, map them back. 289 { LANGUAGE_FRENCH_CAMEROON, "fr", "CM" }, 290 { LANGUAGE_FRENCH_COTE_D_IVOIRE, "fr", "CI" }, 291 { LANGUAGE_FRENCH_MALI, "fr", "ML" }, 292 { LANGUAGE_FRENCH_SENEGAL, "fr", "SN" }, 293 { LANGUAGE_FRENCH_ZAIRE, "fr", "CD" }, // Democratic Republic Of Congo 294 { LANGUAGE_FRENCH_MOROCCO, "fr", "MA" }, 295 { LANGUAGE_FRENCH_REUNION, "fr", "RE" }, 296 { LANGUAGE_FRENCH_NORTH_AFRICA, "fr", "" }, 297 { LANGUAGE_FRENCH_WEST_INDIES, "fr", "" }, // unknown ISO country code 298 { LANGUAGE_FRISIAN_NETHERLANDS, "fy", "NL" }, 299 { LANGUAGE_GAELIC_IRELAND, "ga", "IE" }, 300 { LANGUAGE_GAELIC_SCOTLAND, "gd", "GB" }, 301 { LANGUAGE_GALICIAN, "gl", "ES" }, 302 { LANGUAGE_GEORGIAN, "ka", "GE" }, 303 { LANGUAGE_KHMER, "km", "KH" }, 304 { LANGUAGE_KIRGHIZ, "ky", "KG" }, 305 { LANGUAGE_LAO, "lo", "LA" }, 306 { LANGUAGE_MALTESE, "mt", "MT" }, 307 { LANGUAGE_MONGOLIAN, "mn", "MN" }, // Cyrillic script 308 { LANGUAGE_MONGOLIAN_MONGOLIAN, "mn", "MN" }, 309 { LANGUAGE_RUSSIAN_MOLDOVA, "mo", "MD" }, 310 { LANGUAGE_SWAHILI, "sw", "KE" }, 311 { LANGUAGE_USER_SWAHILI_TANZANIA, "sw", "TZ" }, 312 { LANGUAGE_TAJIK, "tg", "TJ" }, 313 { LANGUAGE_TIBETAN, "bo", "CN" }, // CN politically correct? 314 { LANGUAGE_DZONGKHA, "dz", "BT" }, 315 { LANGUAGE_TURKMEN, "tk", "TM" }, 316 { LANGUAGE_WELSH, "cy", "GB" }, 317 { LANGUAGE_SESOTHO, "st", "ZA" }, 318 { LANGUAGE_SEPEDI, "nso", "ZA" }, 319 { LANGUAGE_SEPEDI, "ns", "ZA" }, // fake "ns" for compatibility with existing OOo1.1.x localization to be able to read those documents 320 { LANGUAGE_TSONGA, "ts", "ZA" }, 321 { LANGUAGE_TSWANA, "tn", "ZA" }, 322 { LANGUAGE_ENGLISH_SAFRICA, "en", "ZA" }, 323 { LANGUAGE_AFRIKAANS, "af", "ZA" }, 324 { LANGUAGE_VENDA, "ve", "ZA" }, // default 639-1 325 { LANGUAGE_VENDA, "ven", "ZA" }, // 639-2 may have been used temporarily since 2004-07-23 326 { LANGUAGE_XHOSA, "xh", "ZA" }, 327 { LANGUAGE_ZULU, "zu", "ZA" }, 328 { LANGUAGE_QUECHUA_ECUADOR, "qu", "EC" }, 329 { LANGUAGE_QUECHUA_PERU, "qu", "PE" }, 330 { LANGUAGE_QUECHUA_BOLIVIA, "qu", "BO" }, // macro: quh-BO, qul-BO 331 { LANGUAGE_PASHTO, "ps", "AF" }, 332 { LANGUAGE_OROMO, "om", "ET" }, 333 { LANGUAGE_DHIVEHI, "dv", "MV" }, 334 { LANGUAGE_UIGHUR_CHINA, "ug", "CN" }, 335 { LANGUAGE_TIGRIGNA_ETHIOPIA, "ti", "ET" }, 336 { LANGUAGE_TIGRIGNA_ERITREA, "ti", "ER" }, 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_FRENCH_HAITI, "fr", "HT" }, 465 { LANGUAGE_NONE, "zxx", "" }, // added to ISO 639-2 on 2006-01-11: Used to declare the absence of linguistic information 466 { LANGUAGE_DONTKNOW, "", "" } // marks end of table 467 }; 468 469 static MsLangId::IsoLangEntry aLastResortFallbackEntry = 470 { LANGUAGE_ENGLISH_US, "en", "US" }; 471 472 // ----------------------------------------------------------------------- 473 474 // In this table are the countries which should mapped to a specific 475 // english language 476 static IsoLangEngEntry const aImplIsoLangEngEntries[] = 477 { 478 { LANGUAGE_ENGLISH_UK, "AO" }, // Angola 479 { LANGUAGE_ENGLISH_UK, "BJ" }, // Benin 480 { LANGUAGE_ENGLISH_UK, "BW" }, // Botswana 481 { LANGUAGE_ENGLISH_UK, "BI" }, // Burundi 482 { LANGUAGE_ENGLISH_UK, "CM" }, // Cameroon 483 { LANGUAGE_ENGLISH_UK, "GA" }, // Gabon 484 { LANGUAGE_ENGLISH_UK, "GM" }, // Gambia 485 { LANGUAGE_ENGLISH_UK, "GH" }, // Ghana 486 { LANGUAGE_ENGLISH_UK, "GN" }, // Guinea 487 { LANGUAGE_ENGLISH_UK, "LS" }, // Lesotho 488 { LANGUAGE_ENGLISH_UK, "MW" }, // Malawi 489 { LANGUAGE_ENGLISH_UK, "MT" }, // Malta 490 { LANGUAGE_ENGLISH_UK, "NA" }, // Namibia 491 { LANGUAGE_ENGLISH_UK, "NG" }, // Nigeria 492 { LANGUAGE_ENGLISH_UK, "UG" }, // Uganda 493 { LANGUAGE_ENGLISH_UK, "ZM" }, // Zambia 494 { LANGUAGE_ENGLISH_UK, "ZW" }, // Zimbabwe 495 { LANGUAGE_ENGLISH_UK, "SZ" }, // Swaziland 496 { LANGUAGE_ENGLISH_UK, "NG" }, // Sierra Leone 497 { LANGUAGE_ENGLISH_UK, "KN" }, // Saint Kitts and Nevis 498 { LANGUAGE_ENGLISH_UK, "SH" }, // St. Helena 499 { LANGUAGE_ENGLISH_UK, "IO" }, // British Indian Oceanic Territory 500 { LANGUAGE_ENGLISH_UK, "FK" }, // Falkland Islands 501 { LANGUAGE_ENGLISH_UK, "GI" }, // Gibraltar 502 { LANGUAGE_ENGLISH_UK, "KI" }, // Kiribati 503 { LANGUAGE_ENGLISH_UK, "VG" }, // Virgin Islands 504 { LANGUAGE_ENGLISH_UK, "MU" }, // Mauritius 505 { LANGUAGE_ENGLISH_UK, "FJ" }, // Fiji 506 { LANGUAGE_ENGLISH_US, "KI" }, // Kiribati 507 { LANGUAGE_ENGLISH_US, "LR" }, // Liberia 508 { LANGUAGE_ENGLISH_US, "GU" }, // Guam 509 { LANGUAGE_ENGLISH_US, "MH" }, // Marshall Islands 510 { LANGUAGE_ENGLISH_US, "PW" }, // Palau 511 { LANGUAGE_ENGLISH_CARRIBEAN, "AI" }, // Anguilla 512 { LANGUAGE_ENGLISH_CARRIBEAN, "AG" }, // Antigua and Barbuda 513 { LANGUAGE_ENGLISH_CARRIBEAN, "BS" }, // Bahamas 514 { LANGUAGE_ENGLISH_CARRIBEAN, "BB" }, // Barbedos 515 { LANGUAGE_ENGLISH_CARRIBEAN, "BM" }, // Bermuda 516 { LANGUAGE_ENGLISH_CARRIBEAN, "KY" }, // Cayman Islands 517 { LANGUAGE_ENGLISH_CARRIBEAN, "GD" }, // Grenada 518 { LANGUAGE_ENGLISH_CARRIBEAN, "DM" }, // Dominica 519 { LANGUAGE_ENGLISH_CARRIBEAN, "HT" }, // Haiti 520 { LANGUAGE_ENGLISH_CARRIBEAN, "MS" }, // Montserrat 521 { LANGUAGE_ENGLISH_CARRIBEAN, "FM" }, // Micronesia 522 { LANGUAGE_ENGLISH_CARRIBEAN, "VC" }, // St. Vincent / Grenadines 523 { LANGUAGE_ENGLISH_CARRIBEAN, "LC" }, // Saint Lucia 524 { LANGUAGE_ENGLISH_CARRIBEAN, "TC" }, // Turks & Caicos Islands 525 { LANGUAGE_ENGLISH_CARRIBEAN, "GY" }, // Guyana 526 { LANGUAGE_ENGLISH_CARRIBEAN, "TT" }, // Trinidad and Tobago 527 { LANGUAGE_ENGLISH_AUS, "CX" }, // Christmas Islands 528 { LANGUAGE_ENGLISH_AUS, "CC" }, // Cocos (Keeling) Islands 529 { LANGUAGE_ENGLISH_AUS, "NF" }, // Norfolk Island 530 { LANGUAGE_ENGLISH_AUS, "PG" }, // Papua New Guinea 531 { LANGUAGE_ENGLISH_AUS, "SB" }, // Solomon Islands 532 { LANGUAGE_ENGLISH_AUS, "TV" }, // Tuvalu 533 { LANGUAGE_ENGLISH_AUS, "NR" }, // Nauru 534 { LANGUAGE_ENGLISH_NZ, "CK" }, // Cook Islands 535 { LANGUAGE_ENGLISH_NZ, "NU" }, // Niue 536 { LANGUAGE_ENGLISH_NZ, "TK" }, // Tokelau 537 { LANGUAGE_ENGLISH_NZ, "TO" }, // Tonga 538 { LANGUAGE_DONTKNOW, "" } // marks end of table 539 }; 540 541 // ----------------------------------------------------------------------- 542 543 static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries[] = 544 { 545 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "BOK" }, // registered subtags for "no" in rfc1766 546 { LANGUAGE_NORWEGIAN_NYNORSK, "no", "NYN" }, // registered subtags for "no" in rfc1766 547 { LANGUAGE_SERBIAN_LATIN, "sr", "latin" }, 548 { LANGUAGE_SERBIAN_CYRILLIC, "sr", "cyrillic" }, 549 { LANGUAGE_AZERI_LATIN, "az", "latin" }, 550 { LANGUAGE_AZERI_CYRILLIC, "az", "cyrillic" }, 551 { LANGUAGE_DONTKNOW, "", "" } // marks end of table 552 }; 553 554 // ----------------------------------------------------------------------- 555 556 // in this table are only names to find the best language 557 static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries2[] = 558 { 559 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmaal" }, 560 { LANGUAGE_NORWEGIAN_BOKMAL, "no", "bokmal" }, 561 { LANGUAGE_NORWEGIAN_NYNORSK, "no", "nynorsk" }, 562 { LANGUAGE_DONTKNOW, "", "" } // marks end of table 563 }; 564 565 // ----------------------------------------------------------------------- 566 567 // in this table are only names to find the best language 568 static IsoLangOtherEntry const aImplOtherEntries[] = 569 { 570 { LANGUAGE_ENGLISH_US, "c" }, 571 { LANGUAGE_CHINESE, "chinese" }, 572 { LANGUAGE_GERMAN, "german" }, 573 { LANGUAGE_JAPANESE, "japanese" }, 574 { LANGUAGE_KOREAN, "korean" }, 575 { LANGUAGE_ENGLISH_US, "posix" }, 576 { LANGUAGE_CHINESE_TRADITIONAL, "tchinese" }, 577 { LANGUAGE_DONTKNOW, NULL } // marks end of table 578 }; 579 580 // ======================================================================= 581 582 // static 583 void MsLangId::convertLanguageToIsoNames( LanguageType nLang, 584 rtl::OUString& rLangStr, rtl::OUString& rCountry ) 585 { 586 if ( nLang == LANGUAGE_SYSTEM ) 587 nLang = MsLangId::getSystemLanguage(); 588 589 // Search for LangID (in this table we find only defined ISO combinations) 590 const IsoLangEntry* pEntry = aImplIsoLangEntries; 591 do 592 { 593 if ( pEntry->mnLang == nLang ) 594 { 595 rLangStr = rtl::OUString::createFromAscii( pEntry->maLangStr ); 596 rCountry = rtl::OUString::createFromAscii( pEntry->maCountry ); 597 return; 598 } 599 ++pEntry; 600 } 601 while ( pEntry->mnLang != LANGUAGE_DONTKNOW ); 602 603 // Search for LangID if we didn't find a specific ISO combination. 604 // All entries in this table are allowed for mime specifications, 605 // but not defined ISO combinations. 606 const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries; 607 do 608 { 609 if ( pNoneStdEntry->mnLang == nLang ) 610 { 611 rLangStr = rtl::OUString::createFromAscii( pNoneStdEntry->maLangStr ); 612 rCountry = rtl::OUString::createFromAscii( pNoneStdEntry->maCountry ); 613 return; 614 } 615 ++pNoneStdEntry; 616 } 617 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW ); 618 619 // not found 620 rLangStr = rtl::OUString(); 621 rCountry = rtl::OUString(); 622 } 623 624 // ----------------------------------------------------------------------- 625 626 // static 627 void MsLangId::convertLanguageToIsoNames( LanguageType nLang, 628 rtl::OString& rLangStr, rtl::OString& rCountry ) 629 { 630 if ( nLang == LANGUAGE_SYSTEM ) 631 nLang = MsLangId::getSystemLanguage(); 632 633 // Search for LangID (in this table we find only defined ISO combinations) 634 const IsoLangEntry* pEntry = aImplIsoLangEntries; 635 do 636 { 637 if ( pEntry->mnLang == nLang ) 638 { 639 rLangStr = rtl::OString( pEntry->maLangStr ); 640 rCountry = rtl::OString( pEntry->maCountry ); 641 return; 642 } 643 ++pEntry; 644 } 645 while ( pEntry->mnLang != LANGUAGE_DONTKNOW ); 646 647 // Search for LangID if we didn't find a specific ISO combination. 648 // All entries in this table are allowed for mime specifications, 649 // but not defined ISO combinations. 650 const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries; 651 do 652 { 653 if ( pNoneStdEntry->mnLang == nLang ) 654 { 655 rLangStr = rtl::OString( pNoneStdEntry->maLangStr ); 656 rCountry = rtl::OString( pNoneStdEntry->maCountry ); 657 return; 658 } 659 ++pNoneStdEntry; 660 } 661 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW ); 662 663 // not found 664 rLangStr = rtl::OString(); 665 rCountry = rtl::OString(); 666 } 667 668 // ----------------------------------------------------------------------- 669 670 static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry( LanguageType nLang ) 671 { 672 LanguageType nPrimary = MsLangId::getPrimaryLanguage( nLang); 673 674 // Search for LangID and remember first lang-only. 675 const MsLangId::IsoLangEntry* pFirstPrimary = NULL; 676 const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries; 677 do 678 { 679 if (pEntry->mnLang == nLang) 680 { 681 if (*pEntry->maCountry) 682 return *pEntry; 683 switch (nLang) 684 { 685 // These are known to have no country assigned. 686 case LANGUAGE_BASQUE: 687 case LANGUAGE_USER_ESPERANTO: 688 case LANGUAGE_USER_INTERLINGUA: 689 case LANGUAGE_USER_LOJBAN: 690 return *pEntry; 691 default: 692 ; // nothing 693 } 694 } 695 if (!pFirstPrimary && 696 MsLangId::getPrimaryLanguage( pEntry->mnLang) == nPrimary) 697 pFirstPrimary = pEntry; 698 ++pEntry; 699 } 700 while ( pEntry->mnLang != LANGUAGE_DONTKNOW ); 701 702 // Language not found at all => use default. 703 if (!pFirstPrimary) 704 return aLastResortFallbackEntry; 705 706 // Search for first entry of primary language with any country. 707 pEntry = pFirstPrimary; 708 do 709 { 710 if (MsLangId::getPrimaryLanguage( pEntry->mnLang) == nLang) 711 { 712 if (*pEntry->maCountry) 713 return *pEntry; 714 } 715 ++pEntry; 716 } 717 while ( pEntry->mnLang != LANGUAGE_DONTKNOW ); 718 719 return aLastResortFallbackEntry; 720 } 721 722 // static 723 LanguageType MsLangId::lookupFallbackLanguage( LanguageType nLang ) 724 { 725 return lcl_lookupFallbackEntry( nLang).mnLang; 726 } 727 728 729 // static 730 ::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale( LanguageType nLang ) 731 { 732 const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( nLang); 733 return ::com::sun::star::lang::Locale( 734 rtl::OUString::createFromAscii( rEntry.maLangStr), 735 rtl::OUString::createFromAscii( rEntry.maCountry), 736 rtl::OUString()); 737 } 738 739 // ----------------------------------------------------------------------- 740 741 static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry( 742 const ::com::sun::star::lang::Locale & rLocale ) 743 { 744 // language is lower case in table 745 rtl::OUString aLowerLang = rLocale.Language.toAsciiLowerCase(); 746 // country is upper case in table 747 rtl::OUString aUpperCountry = rLocale.Country.toAsciiUpperCase(); 748 sal_Int32 nCountryLen = aUpperCountry.getLength(); 749 750 // Search for locale and remember first lang-only. 751 const MsLangId::IsoLangEntry* pFirstLang = NULL; 752 const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries; 753 do 754 { 755 if (aLowerLang.equalsAscii( pEntry->maLangStr)) 756 { 757 if (*pEntry->maCountry) 758 { 759 if (nCountryLen && aUpperCountry.equalsAscii( pEntry->maCountry)) 760 return *pEntry; 761 } 762 else 763 { 764 switch (pEntry->mnLang) 765 { 766 // These are known to have no country assigned. 767 case LANGUAGE_BASQUE: 768 case LANGUAGE_USER_ESPERANTO: 769 case LANGUAGE_USER_INTERLINGUA: 770 case LANGUAGE_USER_LOJBAN: 771 return *pEntry; 772 default: 773 ; // nothing 774 } 775 } 776 if (!pFirstLang) 777 pFirstLang = pEntry; 778 } 779 ++pEntry; 780 } 781 while ( pEntry->mnLang != LANGUAGE_DONTKNOW ); 782 783 // Language not found at all => use default. 784 if (!pFirstLang) 785 return aLastResortFallbackEntry; 786 787 // Search for first entry of language with any country. 788 pEntry = pFirstLang; 789 do 790 { 791 if (aLowerLang.equalsAscii( pEntry->maLangStr)) 792 { 793 if (*pEntry->maCountry) 794 return *pEntry; 795 } 796 ++pEntry; 797 } 798 while ( pEntry->mnLang != LANGUAGE_DONTKNOW ); 799 800 return aLastResortFallbackEntry; 801 } 802 803 // static 804 LanguageType MsLangId::lookupFallbackLanguage( 805 const ::com::sun::star::lang::Locale & rLocale ) 806 { 807 return lcl_lookupFallbackEntry( rLocale).mnLang; 808 } 809 810 811 // static 812 ::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale( 813 const ::com::sun::star::lang::Locale & rLocale ) 814 { 815 const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( rLocale); 816 return ::com::sun::star::lang::Locale( 817 rtl::OUString::createFromAscii( rEntry.maLangStr), 818 rtl::OUString::createFromAscii( rEntry.maCountry), 819 rtl::OUString()); 820 } 821 822 // ----------------------------------------------------------------------- 823 824 // static 825 rtl::OUString MsLangId::convertLanguageToIsoString( LanguageType nLang, 826 sal_Unicode cSep ) 827 { 828 rtl::OUString aLangStr; 829 rtl::OUString aCountry; 830 convertLanguageToIsoNames( nLang, aLangStr, aCountry ); 831 if ( aCountry.getLength() ) 832 { 833 rtl::OUStringBuffer aBuf( aLangStr); 834 aBuf.append( cSep ); 835 aBuf.append( aCountry ); 836 return aBuf.makeStringAndClear(); 837 } 838 else 839 return aLangStr; 840 } 841 842 // ----------------------------------------------------------------------- 843 844 // static 845 rtl::OString MsLangId::convertLanguageToIsoByteString( LanguageType nLang, 846 sal_Char cSep ) 847 { 848 rtl::OString aLangStr; 849 rtl::OString aCountry; 850 convertLanguageToIsoNames( nLang, aLangStr, aCountry ); 851 if ( aCountry.getLength() ) 852 { 853 rtl::OStringBuffer aBuf( aLangStr); 854 aBuf.append( cSep ); 855 aBuf.append( aCountry ); 856 return aBuf.makeStringAndClear(); 857 } 858 return aLangStr; 859 } 860 861 // ======================================================================= 862 863 // static 864 LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OUString& rLang, 865 const rtl::OUString& rCountry ) 866 { 867 // language is lower case in table 868 rtl::OUString aLowerLang = rLang.toAsciiLowerCase(); 869 // country is upper case in table 870 rtl::OUString aUpperCountry = rCountry.toAsciiUpperCase(); 871 872 // first look for exact match 873 const IsoLangEntry* pFirstLang = NULL; 874 const IsoLangEntry* pEntry = aImplIsoLangEntries; 875 do 876 { 877 if ( aLowerLang.equalsAscii( pEntry->maLangStr ) ) 878 { 879 if ( !aUpperCountry.getLength() || 880 aUpperCountry.equalsAscii( pEntry->maCountry ) ) 881 return pEntry->mnLang; 882 if ( !pFirstLang ) 883 pFirstLang = pEntry; 884 else if ( !*pEntry->maCountry ) 885 pFirstLang = pEntry; 886 } 887 ++pEntry; 888 } 889 while ( pEntry->mnLang != LANGUAGE_DONTKNOW ); 890 891 // some eng countries should be mapped to a specific english language 892 if ( aLowerLang.equalsAscii( "en" ) ) 893 { 894 const IsoLangEngEntry* pEngEntry = aImplIsoLangEngEntries; 895 do 896 { 897 if ( aUpperCountry.equalsAscii( pEngEntry->maCountry ) ) 898 return pEngEntry->mnLang; 899 ++pEngEntry; 900 } 901 while ( pEngEntry->mnLang != LANGUAGE_DONTKNOW ); 902 } 903 904 // test for specific languages which are not used standard ISO 3166 codes 905 const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries; 906 do 907 { 908 if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) ) 909 { 910 // The countries in this table are not all in upper case 911 if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) ) 912 return pNoneStdEntry->mnLang; 913 } 914 ++pNoneStdEntry; 915 } 916 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW ); 917 pNoneStdEntry = aImplIsoNoneStdLangEntries2; 918 do 919 { 920 if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) ) 921 { 922 // The countries in this table are not all in upper case 923 if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) ) 924 return pNoneStdEntry->mnLang; 925 } 926 ++pNoneStdEntry; 927 } 928 while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW ); 929 930 // If the language is correct, than we return the default language 931 if ( pFirstLang ) 932 return pFirstLang->mnLang; 933 934 // if only the country is set, look for any entry matching the country 935 // (to allow reading country and language in separate steps, in any order) 936 if ( rCountry.getLength() && !rLang.getLength() ) 937 { 938 const IsoLangEntry* pEntry2 = aImplIsoLangEntries; 939 do 940 { 941 if ( aUpperCountry.equalsAscii( pEntry2->maCountry ) ) 942 return pEntry2->mnLang; 943 ++pEntry2; 944 } 945 while ( pEntry2->mnLang != LANGUAGE_DONTKNOW ); 946 947 aLowerLang = aUpperCountry.toAsciiLowerCase(); 948 } 949 950 // Now look for all other definitions, which are not standard 951 const IsoLangOtherEntry* pOtherEntry = aImplOtherEntries; 952 do 953 { 954 if ( aLowerLang.equalsAscii( pOtherEntry->mpLangStr ) ) 955 return pOtherEntry->mnLang; 956 ++pOtherEntry; 957 } 958 while ( pOtherEntry->mnLang != LANGUAGE_DONTKNOW ); 959 960 return LANGUAGE_DONTKNOW; 961 } 962 963 // ----------------------------------------------------------------------- 964 965 // static 966 LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OString& rLang, 967 const rtl::OString& rCountry ) 968 { 969 rtl::OUString aLang = OStringToOUString( rLang, RTL_TEXTENCODING_ASCII_US); 970 rtl::OUString aCountry = OStringToOUString( rCountry, RTL_TEXTENCODING_ASCII_US); 971 return convertIsoNamesToLanguage( aLang, aCountry); 972 } 973 974 // ----------------------------------------------------------------------- 975 976 // static 977 LanguageType MsLangId::convertIsoStringToLanguage( 978 const rtl::OUString& rString, sal_Unicode cSep ) 979 { 980 rtl::OUString aLang; 981 rtl::OUString aCountry; 982 sal_Int32 nSepPos = rString.indexOf( cSep ); 983 if ( nSepPos >= 0 ) 984 { 985 aLang = rString.copy( 0, nSepPos ); 986 aCountry = rString.copy( nSepPos+1 ); 987 } 988 else 989 aLang = rString; 990 991 return convertIsoNamesToLanguage( aLang, aCountry ); 992 } 993 994 // ----------------------------------------------------------------------- 995 996 // static 997 LanguageType MsLangId::convertIsoByteStringToLanguage( 998 const rtl::OString& rString, sal_Char cSep ) 999 { 1000 rtl::OString aLang; 1001 rtl::OString aCountry; 1002 sal_Int32 nSepPos = rString.indexOf( cSep ); 1003 if ( nSepPos >= 0 ) 1004 { 1005 aLang = rString.copy( 0, nSepPos ); 1006 aCountry = rString.copy( nSepPos+1 ); 1007 } 1008 else 1009 aLang = rString; 1010 1011 return convertIsoNamesToLanguage( aLang, aCountry ); 1012 } 1013 1014 // ----------------------------------------------------------------------- 1015 1016 struct IsoLangGLIBCModifiersEntry 1017 { 1018 LanguageType mnLang; 1019 sal_Char maLangStr[4]; 1020 sal_Char maCountry[3]; 1021 sal_Char maAtString[9]; 1022 }; 1023 1024 static IsoLangGLIBCModifiersEntry const aImplIsoLangGLIBCModifiersEntries[] = 1025 { 1026 // MS-LANGID codes ISO639-1/2/3 ISO3166 glibc modifier 1027 { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "bs", "BA", "cyrillic" }, 1028 { LANGUAGE_USER_SERBIAN_LATIN_SERBIA, "sr", "RS", "latin" }, // Serbian Latin in Serbia 1029 { LANGUAGE_SERBIAN_LATIN, "sr", "CS", "latin" }, // Serbian Latin in Serbia and Montenegro 1030 { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO, "sr", "ME", "latin" }, // Serbian Latin in Montenegro 1031 { LANGUAGE_SERBIAN_LATIN_NEUTRAL, "sr", "", "latin" }, 1032 { LANGUAGE_AZERI_CYRILLIC, "az", "AZ", "cyrillic" }, 1033 { LANGUAGE_UZBEK_CYRILLIC, "uz", "UZ", "cyrillic" }, 1034 { LANGUAGE_DONTKNOW, "", "", "" } // marks end of table 1035 }; 1036 1037 // convert a unix locale string into LanguageType 1038 1039 // static 1040 LanguageType MsLangId::convertUnxByteStringToLanguage( 1041 const rtl::OString& rString ) 1042 { 1043 rtl::OString aLang; 1044 rtl::OString aCountry; 1045 rtl::OString aAtString; 1046 1047 sal_Int32 nLangSepPos = rString.indexOf( (sal_Char)'_' ); 1048 sal_Int32 nCountrySepPos = rString.indexOf( (sal_Char)'.' ); 1049 sal_Int32 nAtPos = rString.indexOf( (sal_Char)'@' ); 1050 1051 if (nCountrySepPos < 0) 1052 nCountrySepPos = nAtPos; 1053 if (nCountrySepPos < 0) 1054 nCountrySepPos = rString.getLength(); 1055 1056 if (nAtPos >= 0) 1057 aAtString = rString.copy( nAtPos+1 ); 1058 1059 if ( ((nLangSepPos >= 0) && (nLangSepPos > nCountrySepPos)) 1060 || ((nLangSepPos < 0)) ) 1061 { 1062 // eg. "el.sun_eu_greek", "tchinese", "es.ISO8859-15" 1063 aLang = rString.copy( 0, nCountrySepPos ); 1064 } 1065 else if ( nLangSepPos >= 0 ) 1066 { 1067 // well formed iso names like "en_US.UTF-8", "sh_BA.ISO8859-2@bosnia" 1068 aLang = rString.copy( 0, nLangSepPos ); 1069 aCountry = rString.copy( nLangSepPos+1, nCountrySepPos - nLangSepPos - 1); 1070 } 1071 1072 // if there is a glibc modifier, first look for exact match in modifier table 1073 if (aAtString.getLength()) 1074 { 1075 // language is lower case in table 1076 rtl::OString aLowerLang = aLang.toAsciiLowerCase(); 1077 // country is upper case in table 1078 rtl::OString aUpperCountry = aCountry.toAsciiUpperCase(); 1079 const IsoLangGLIBCModifiersEntry* pGLIBCModifiersEntry = aImplIsoLangGLIBCModifiersEntries; 1080 do 1081 { 1082 if (( aLowerLang.equals( pGLIBCModifiersEntry->maLangStr ) ) && 1083 ( aAtString.equals( pGLIBCModifiersEntry->maAtString ) )) 1084 { 1085 if ( !aUpperCountry.getLength() || 1086 aUpperCountry.equals( pGLIBCModifiersEntry->maCountry ) ) 1087 { 1088 return pGLIBCModifiersEntry->mnLang; 1089 } 1090 } 1091 ++pGLIBCModifiersEntry; 1092 } 1093 while ( pGLIBCModifiersEntry->mnLang != LANGUAGE_DONTKNOW ); 1094 } 1095 1096 return convertIsoNamesToLanguage( aLang, aCountry ); 1097 } 1098 1099 // ----------------------------------------------------------------------- 1100 // pass one IsoLangEntry to the outer world of the resource compiler 1101 1102 // static 1103 const MsLangId::IsoLangEntry* MsLangId::getIsoLangEntry( size_t nIndex ) 1104 { 1105 if (nIndex < sizeof( aImplIsoLangEntries) / sizeof( IsoLangEntry)) 1106 return &aImplIsoLangEntries[ nIndex]; 1107 return 0; 1108 } 1109