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_USER_VENETAN, "vec", "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 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 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 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 725 LanguageType MsLangId::lookupFallbackLanguage( LanguageType nLang ) 726 { 727 return lcl_lookupFallbackEntry( nLang).mnLang; 728 } 729 730 731 // static 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 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 806 LanguageType MsLangId::lookupFallbackLanguage( 807 const ::com::sun::star::lang::Locale & rLocale ) 808 { 809 return lcl_lookupFallbackEntry( rLocale).mnLang; 810 } 811 812 813 // static 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 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 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 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 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 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 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 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 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