| 1 | /* Determine the current selected locale.
|
|---|
| 2 | Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 7 | any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program; if not, write to the Free Software Foundation,
|
|---|
| 16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 17 |
|
|---|
| 18 | /* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
|
|---|
| 19 | /* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
|
|---|
| 20 |
|
|---|
| 21 | #ifdef HAVE_CONFIG_H
|
|---|
| 22 | # include <config.h>
|
|---|
| 23 | #endif
|
|---|
| 24 |
|
|---|
| 25 | #include <stdlib.h>
|
|---|
| 26 | #include <locale.h>
|
|---|
| 27 |
|
|---|
| 28 | #if defined _WIN32 || defined __WIN32__
|
|---|
| 29 | # undef WIN32 /* avoid warning on mingw32 */
|
|---|
| 30 | # define WIN32
|
|---|
| 31 | #endif
|
|---|
| 32 |
|
|---|
| 33 | #ifdef WIN32
|
|---|
| 34 | # define WIN32_LEAN_AND_MEAN
|
|---|
| 35 | # include <windows.h>
|
|---|
| 36 | /* Mingw headers don't have latest language and sublanguage codes. */
|
|---|
| 37 | # ifndef LANG_AFRIKAANS
|
|---|
| 38 | # define LANG_AFRIKAANS 0x36
|
|---|
| 39 | # endif
|
|---|
| 40 | # ifndef LANG_ALBANIAN
|
|---|
| 41 | # define LANG_ALBANIAN 0x1c
|
|---|
| 42 | # endif
|
|---|
| 43 | # ifndef LANG_ARABIC
|
|---|
| 44 | # define LANG_ARABIC 0x01
|
|---|
| 45 | # endif
|
|---|
| 46 | # ifndef LANG_ARMENIAN
|
|---|
| 47 | # define LANG_ARMENIAN 0x2b
|
|---|
| 48 | # endif
|
|---|
| 49 | # ifndef LANG_ASSAMESE
|
|---|
| 50 | # define LANG_ASSAMESE 0x4d
|
|---|
| 51 | # endif
|
|---|
| 52 | # ifndef LANG_AZERI
|
|---|
| 53 | # define LANG_AZERI 0x2c
|
|---|
| 54 | # endif
|
|---|
| 55 | # ifndef LANG_BASQUE
|
|---|
| 56 | # define LANG_BASQUE 0x2d
|
|---|
| 57 | # endif
|
|---|
| 58 | # ifndef LANG_BELARUSIAN
|
|---|
| 59 | # define LANG_BELARUSIAN 0x23
|
|---|
| 60 | # endif
|
|---|
| 61 | # ifndef LANG_BENGALI
|
|---|
| 62 | # define LANG_BENGALI 0x45
|
|---|
| 63 | # endif
|
|---|
| 64 | # ifndef LANG_CATALAN
|
|---|
| 65 | # define LANG_CATALAN 0x03
|
|---|
| 66 | # endif
|
|---|
| 67 | # ifndef LANG_ESTONIAN
|
|---|
| 68 | # define LANG_ESTONIAN 0x25
|
|---|
| 69 | # endif
|
|---|
| 70 | # ifndef LANG_FAEROESE
|
|---|
| 71 | # define LANG_FAEROESE 0x38
|
|---|
| 72 | # endif
|
|---|
| 73 | # ifndef LANG_FARSI
|
|---|
| 74 | # define LANG_FARSI 0x29
|
|---|
| 75 | # endif
|
|---|
| 76 | # ifndef LANG_GEORGIAN
|
|---|
| 77 | # define LANG_GEORGIAN 0x37
|
|---|
| 78 | # endif
|
|---|
| 79 | # ifndef LANG_GUJARATI
|
|---|
| 80 | # define LANG_GUJARATI 0x47
|
|---|
| 81 | # endif
|
|---|
| 82 | # ifndef LANG_HEBREW
|
|---|
| 83 | # define LANG_HEBREW 0x0d
|
|---|
| 84 | # endif
|
|---|
| 85 | # ifndef LANG_HINDI
|
|---|
| 86 | # define LANG_HINDI 0x39
|
|---|
| 87 | # endif
|
|---|
| 88 | # ifndef LANG_INDONESIAN
|
|---|
| 89 | # define LANG_INDONESIAN 0x21
|
|---|
| 90 | # endif
|
|---|
| 91 | # ifndef LANG_KANNADA
|
|---|
| 92 | # define LANG_KANNADA 0x4b
|
|---|
| 93 | # endif
|
|---|
| 94 | # ifndef LANG_KASHMIRI
|
|---|
| 95 | # define LANG_KASHMIRI 0x60
|
|---|
| 96 | # endif
|
|---|
| 97 | # ifndef LANG_KAZAK
|
|---|
| 98 | # define LANG_KAZAK 0x3f
|
|---|
| 99 | # endif
|
|---|
| 100 | # ifndef LANG_KONKANI
|
|---|
| 101 | # define LANG_KONKANI 0x57
|
|---|
| 102 | # endif
|
|---|
| 103 | # ifndef LANG_LATVIAN
|
|---|
| 104 | # define LANG_LATVIAN 0x26
|
|---|
| 105 | # endif
|
|---|
| 106 | # ifndef LANG_LITHUANIAN
|
|---|
| 107 | # define LANG_LITHUANIAN 0x27
|
|---|
| 108 | # endif
|
|---|
| 109 | # ifndef LANG_MACEDONIAN
|
|---|
| 110 | # define LANG_MACEDONIAN 0x2f
|
|---|
| 111 | # endif
|
|---|
| 112 | # ifndef LANG_MALAY
|
|---|
| 113 | # define LANG_MALAY 0x3e
|
|---|
| 114 | # endif
|
|---|
| 115 | # ifndef LANG_MALAYALAM
|
|---|
| 116 | # define LANG_MALAYALAM 0x4c
|
|---|
| 117 | # endif
|
|---|
| 118 | # ifndef LANG_MANIPURI
|
|---|
| 119 | # define LANG_MANIPURI 0x58
|
|---|
| 120 | # endif
|
|---|
| 121 | # ifndef LANG_MARATHI
|
|---|
| 122 | # define LANG_MARATHI 0x4e
|
|---|
| 123 | # endif
|
|---|
| 124 | # ifndef LANG_NEPALI
|
|---|
| 125 | # define LANG_NEPALI 0x61
|
|---|
| 126 | # endif
|
|---|
| 127 | # ifndef LANG_ORIYA
|
|---|
| 128 | # define LANG_ORIYA 0x48
|
|---|
| 129 | # endif
|
|---|
| 130 | # ifndef LANG_PUNJABI
|
|---|
| 131 | # define LANG_PUNJABI 0x46
|
|---|
| 132 | # endif
|
|---|
| 133 | # ifndef LANG_SANSKRIT
|
|---|
| 134 | # define LANG_SANSKRIT 0x4f
|
|---|
| 135 | # endif
|
|---|
| 136 | # ifndef LANG_SERBIAN
|
|---|
| 137 | # define LANG_SERBIAN 0x1a
|
|---|
| 138 | # endif
|
|---|
| 139 | # ifndef LANG_SINDHI
|
|---|
| 140 | # define LANG_SINDHI 0x59
|
|---|
| 141 | # endif
|
|---|
| 142 | # ifndef LANG_SLOVAK
|
|---|
| 143 | # define LANG_SLOVAK 0x1b
|
|---|
| 144 | # endif
|
|---|
| 145 | # ifndef LANG_SWAHILI
|
|---|
| 146 | # define LANG_SWAHILI 0x41
|
|---|
| 147 | # endif
|
|---|
| 148 | # ifndef LANG_TAMIL
|
|---|
| 149 | # define LANG_TAMIL 0x49
|
|---|
| 150 | # endif
|
|---|
| 151 | # ifndef LANG_TATAR
|
|---|
| 152 | # define LANG_TATAR 0x44
|
|---|
| 153 | # endif
|
|---|
| 154 | # ifndef LANG_TELUGU
|
|---|
| 155 | # define LANG_TELUGU 0x4a
|
|---|
| 156 | # endif
|
|---|
| 157 | # ifndef LANG_THAI
|
|---|
| 158 | # define LANG_THAI 0x1e
|
|---|
| 159 | # endif
|
|---|
| 160 | # ifndef LANG_UKRAINIAN
|
|---|
| 161 | # define LANG_UKRAINIAN 0x22
|
|---|
| 162 | # endif
|
|---|
| 163 | # ifndef LANG_URDU
|
|---|
| 164 | # define LANG_URDU 0x20
|
|---|
| 165 | # endif
|
|---|
| 166 | # ifndef LANG_UZBEK
|
|---|
| 167 | # define LANG_UZBEK 0x43
|
|---|
| 168 | # endif
|
|---|
| 169 | # ifndef LANG_VIETNAMESE
|
|---|
| 170 | # define LANG_VIETNAMESE 0x2a
|
|---|
| 171 | # endif
|
|---|
| 172 | # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
|
|---|
| 173 | # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
|
|---|
| 174 | # endif
|
|---|
| 175 | # ifndef SUBLANG_ARABIC_IRAQ
|
|---|
| 176 | # define SUBLANG_ARABIC_IRAQ 0x02
|
|---|
| 177 | # endif
|
|---|
| 178 | # ifndef SUBLANG_ARABIC_EGYPT
|
|---|
| 179 | # define SUBLANG_ARABIC_EGYPT 0x03
|
|---|
| 180 | # endif
|
|---|
| 181 | # ifndef SUBLANG_ARABIC_LIBYA
|
|---|
| 182 | # define SUBLANG_ARABIC_LIBYA 0x04
|
|---|
| 183 | # endif
|
|---|
| 184 | # ifndef SUBLANG_ARABIC_ALGERIA
|
|---|
| 185 | # define SUBLANG_ARABIC_ALGERIA 0x05
|
|---|
| 186 | # endif
|
|---|
| 187 | # ifndef SUBLANG_ARABIC_MOROCCO
|
|---|
| 188 | # define SUBLANG_ARABIC_MOROCCO 0x06
|
|---|
| 189 | # endif
|
|---|
| 190 | # ifndef SUBLANG_ARABIC_TUNISIA
|
|---|
| 191 | # define SUBLANG_ARABIC_TUNISIA 0x07
|
|---|
| 192 | # endif
|
|---|
| 193 | # ifndef SUBLANG_ARABIC_OMAN
|
|---|
| 194 | # define SUBLANG_ARABIC_OMAN 0x08
|
|---|
| 195 | # endif
|
|---|
| 196 | # ifndef SUBLANG_ARABIC_YEMEN
|
|---|
| 197 | # define SUBLANG_ARABIC_YEMEN 0x09
|
|---|
| 198 | # endif
|
|---|
| 199 | # ifndef SUBLANG_ARABIC_SYRIA
|
|---|
| 200 | # define SUBLANG_ARABIC_SYRIA 0x0a
|
|---|
| 201 | # endif
|
|---|
| 202 | # ifndef SUBLANG_ARABIC_JORDAN
|
|---|
| 203 | # define SUBLANG_ARABIC_JORDAN 0x0b
|
|---|
| 204 | # endif
|
|---|
| 205 | # ifndef SUBLANG_ARABIC_LEBANON
|
|---|
| 206 | # define SUBLANG_ARABIC_LEBANON 0x0c
|
|---|
| 207 | # endif
|
|---|
| 208 | # ifndef SUBLANG_ARABIC_KUWAIT
|
|---|
| 209 | # define SUBLANG_ARABIC_KUWAIT 0x0d
|
|---|
| 210 | # endif
|
|---|
| 211 | # ifndef SUBLANG_ARABIC_UAE
|
|---|
| 212 | # define SUBLANG_ARABIC_UAE 0x0e
|
|---|
| 213 | # endif
|
|---|
| 214 | # ifndef SUBLANG_ARABIC_BAHRAIN
|
|---|
| 215 | # define SUBLANG_ARABIC_BAHRAIN 0x0f
|
|---|
| 216 | # endif
|
|---|
| 217 | # ifndef SUBLANG_ARABIC_QATAR
|
|---|
| 218 | # define SUBLANG_ARABIC_QATAR 0x10
|
|---|
| 219 | # endif
|
|---|
| 220 | # ifndef SUBLANG_AZERI_LATIN
|
|---|
| 221 | # define SUBLANG_AZERI_LATIN 0x01
|
|---|
| 222 | # endif
|
|---|
| 223 | # ifndef SUBLANG_AZERI_CYRILLIC
|
|---|
| 224 | # define SUBLANG_AZERI_CYRILLIC 0x02
|
|---|
| 225 | # endif
|
|---|
| 226 | # ifndef SUBLANG_CHINESE_MACAU
|
|---|
| 227 | # define SUBLANG_CHINESE_MACAU 0x05
|
|---|
| 228 | # endif
|
|---|
| 229 | # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
|
|---|
| 230 | # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
|
|---|
| 231 | # endif
|
|---|
| 232 | # ifndef SUBLANG_ENGLISH_JAMAICA
|
|---|
| 233 | # define SUBLANG_ENGLISH_JAMAICA 0x08
|
|---|
| 234 | # endif
|
|---|
| 235 | # ifndef SUBLANG_ENGLISH_CARIBBEAN
|
|---|
| 236 | # define SUBLANG_ENGLISH_CARIBBEAN 0x09
|
|---|
| 237 | # endif
|
|---|
| 238 | # ifndef SUBLANG_ENGLISH_BELIZE
|
|---|
| 239 | # define SUBLANG_ENGLISH_BELIZE 0x0a
|
|---|
| 240 | # endif
|
|---|
| 241 | # ifndef SUBLANG_ENGLISH_TRINIDAD
|
|---|
| 242 | # define SUBLANG_ENGLISH_TRINIDAD 0x0b
|
|---|
| 243 | # endif
|
|---|
| 244 | # ifndef SUBLANG_ENGLISH_ZIMBABWE
|
|---|
| 245 | # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
|
|---|
| 246 | # endif
|
|---|
| 247 | # ifndef SUBLANG_ENGLISH_PHILIPPINES
|
|---|
| 248 | # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
|
|---|
| 249 | # endif
|
|---|
| 250 | # ifndef SUBLANG_FRENCH_LUXEMBOURG
|
|---|
| 251 | # define SUBLANG_FRENCH_LUXEMBOURG 0x05
|
|---|
| 252 | # endif
|
|---|
| 253 | # ifndef SUBLANG_FRENCH_MONACO
|
|---|
| 254 | # define SUBLANG_FRENCH_MONACO 0x06
|
|---|
| 255 | # endif
|
|---|
| 256 | # ifndef SUBLANG_GERMAN_LUXEMBOURG
|
|---|
| 257 | # define SUBLANG_GERMAN_LUXEMBOURG 0x04
|
|---|
| 258 | # endif
|
|---|
| 259 | # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
|
|---|
| 260 | # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
|
|---|
| 261 | # endif
|
|---|
| 262 | # ifndef SUBLANG_KASHMIRI_INDIA
|
|---|
| 263 | # define SUBLANG_KASHMIRI_INDIA 0x02
|
|---|
| 264 | # endif
|
|---|
| 265 | # ifndef SUBLANG_MALAY_MALAYSIA
|
|---|
| 266 | # define SUBLANG_MALAY_MALAYSIA 0x01
|
|---|
| 267 | # endif
|
|---|
| 268 | # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
|
|---|
| 269 | # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
|
|---|
| 270 | # endif
|
|---|
| 271 | # ifndef SUBLANG_NEPALI_INDIA
|
|---|
| 272 | # define SUBLANG_NEPALI_INDIA 0x02
|
|---|
| 273 | # endif
|
|---|
| 274 | # ifndef SUBLANG_SERBIAN_LATIN
|
|---|
| 275 | # define SUBLANG_SERBIAN_LATIN 0x02
|
|---|
| 276 | # endif
|
|---|
| 277 | # ifndef SUBLANG_SERBIAN_CYRILLIC
|
|---|
| 278 | # define SUBLANG_SERBIAN_CYRILLIC 0x03
|
|---|
| 279 | # endif
|
|---|
| 280 | # ifndef SUBLANG_SPANISH_GUATEMALA
|
|---|
| 281 | # define SUBLANG_SPANISH_GUATEMALA 0x04
|
|---|
| 282 | # endif
|
|---|
| 283 | # ifndef SUBLANG_SPANISH_COSTA_RICA
|
|---|
| 284 | # define SUBLANG_SPANISH_COSTA_RICA 0x05
|
|---|
| 285 | # endif
|
|---|
| 286 | # ifndef SUBLANG_SPANISH_PANAMA
|
|---|
| 287 | # define SUBLANG_SPANISH_PANAMA 0x06
|
|---|
| 288 | # endif
|
|---|
| 289 | # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
|
|---|
| 290 | # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
|
|---|
| 291 | # endif
|
|---|
| 292 | # ifndef SUBLANG_SPANISH_VENEZUELA
|
|---|
| 293 | # define SUBLANG_SPANISH_VENEZUELA 0x08
|
|---|
| 294 | # endif
|
|---|
| 295 | # ifndef SUBLANG_SPANISH_COLOMBIA
|
|---|
| 296 | # define SUBLANG_SPANISH_COLOMBIA 0x09
|
|---|
| 297 | # endif
|
|---|
| 298 | # ifndef SUBLANG_SPANISH_PERU
|
|---|
| 299 | # define SUBLANG_SPANISH_PERU 0x0a
|
|---|
| 300 | # endif
|
|---|
| 301 | # ifndef SUBLANG_SPANISH_ARGENTINA
|
|---|
| 302 | # define SUBLANG_SPANISH_ARGENTINA 0x0b
|
|---|
| 303 | # endif
|
|---|
| 304 | # ifndef SUBLANG_SPANISH_ECUADOR
|
|---|
| 305 | # define SUBLANG_SPANISH_ECUADOR 0x0c
|
|---|
| 306 | # endif
|
|---|
| 307 | # ifndef SUBLANG_SPANISH_CHILE
|
|---|
| 308 | # define SUBLANG_SPANISH_CHILE 0x0d
|
|---|
| 309 | # endif
|
|---|
| 310 | # ifndef SUBLANG_SPANISH_URUGUAY
|
|---|
| 311 | # define SUBLANG_SPANISH_URUGUAY 0x0e
|
|---|
| 312 | # endif
|
|---|
| 313 | # ifndef SUBLANG_SPANISH_PARAGUAY
|
|---|
| 314 | # define SUBLANG_SPANISH_PARAGUAY 0x0f
|
|---|
| 315 | # endif
|
|---|
| 316 | # ifndef SUBLANG_SPANISH_BOLIVIA
|
|---|
| 317 | # define SUBLANG_SPANISH_BOLIVIA 0x10
|
|---|
| 318 | # endif
|
|---|
| 319 | # ifndef SUBLANG_SPANISH_EL_SALVADOR
|
|---|
| 320 | # define SUBLANG_SPANISH_EL_SALVADOR 0x11
|
|---|
| 321 | # endif
|
|---|
| 322 | # ifndef SUBLANG_SPANISH_HONDURAS
|
|---|
| 323 | # define SUBLANG_SPANISH_HONDURAS 0x12
|
|---|
| 324 | # endif
|
|---|
| 325 | # ifndef SUBLANG_SPANISH_NICARAGUA
|
|---|
| 326 | # define SUBLANG_SPANISH_NICARAGUA 0x13
|
|---|
| 327 | # endif
|
|---|
| 328 | # ifndef SUBLANG_SPANISH_PUERTO_RICO
|
|---|
| 329 | # define SUBLANG_SPANISH_PUERTO_RICO 0x14
|
|---|
| 330 | # endif
|
|---|
| 331 | # ifndef SUBLANG_SWEDISH_FINLAND
|
|---|
| 332 | # define SUBLANG_SWEDISH_FINLAND 0x02
|
|---|
| 333 | # endif
|
|---|
| 334 | # ifndef SUBLANG_URDU_PAKISTAN
|
|---|
| 335 | # define SUBLANG_URDU_PAKISTAN 0x01
|
|---|
| 336 | # endif
|
|---|
| 337 | # ifndef SUBLANG_URDU_INDIA
|
|---|
| 338 | # define SUBLANG_URDU_INDIA 0x02
|
|---|
| 339 | # endif
|
|---|
| 340 | # ifndef SUBLANG_UZBEK_LATIN
|
|---|
| 341 | # define SUBLANG_UZBEK_LATIN 0x01
|
|---|
| 342 | # endif
|
|---|
| 343 | # ifndef SUBLANG_UZBEK_CYRILLIC
|
|---|
| 344 | # define SUBLANG_UZBEK_CYRILLIC 0x02
|
|---|
| 345 | # endif
|
|---|
| 346 | #endif
|
|---|
| 347 |
|
|---|
| 348 | /* XPG3 defines the result of 'setlocale (category, NULL)' as:
|
|---|
| 349 | "Directs 'setlocale()' to query 'category' and return the current
|
|---|
| 350 | setting of 'local'."
|
|---|
| 351 | However it does not specify the exact format. Neither do SUSV2 and
|
|---|
| 352 | ISO C 99. So we can use this feature only on selected systems (e.g.
|
|---|
| 353 | those using GNU C Library). */
|
|---|
| 354 | #if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
|
|---|
| 355 | # define HAVE_LOCALE_NULL
|
|---|
| 356 | #endif
|
|---|
| 357 |
|
|---|
| 358 | /* Determine the current locale's name, and canonicalize it into XPG syntax
|
|---|
| 359 | language[_territory[.codeset]][@modifier]
|
|---|
| 360 | The codeset part in the result is not reliable; the locale_charset()
|
|---|
| 361 | should be used for codeset information instead.
|
|---|
| 362 | The result must not be freed; it is statically allocated. */
|
|---|
| 363 |
|
|---|
| 364 | const char *
|
|---|
| 365 | _nl_locale_name (category, categoryname)
|
|---|
| 366 | int category;
|
|---|
| 367 | const char *categoryname;
|
|---|
| 368 | {
|
|---|
| 369 | const char *retval;
|
|---|
| 370 |
|
|---|
| 371 | #ifndef WIN32
|
|---|
| 372 |
|
|---|
| 373 | /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
|
|---|
| 374 | On some systems this can be done by the 'setlocale' function itself. */
|
|---|
| 375 | # if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
|
|---|
| 376 | retval = setlocale (category, NULL);
|
|---|
| 377 | # else
|
|---|
| 378 | /* Setting of LC_ALL overwrites all other. */
|
|---|
| 379 | retval = getenv ("LC_ALL");
|
|---|
| 380 | if (retval == NULL || retval[0] == '\0')
|
|---|
| 381 | {
|
|---|
| 382 | /* Next comes the name of the desired category. */
|
|---|
| 383 | retval = getenv (categoryname);
|
|---|
| 384 | if (retval == NULL || retval[0] == '\0')
|
|---|
| 385 | {
|
|---|
| 386 | /* Last possibility is the LANG environment variable. */
|
|---|
| 387 | retval = getenv ("LANG");
|
|---|
| 388 | if (retval == NULL || retval[0] == '\0')
|
|---|
| 389 | /* We use C as the default domain. POSIX says this is
|
|---|
| 390 | implementation defined. */
|
|---|
| 391 | retval = "C";
|
|---|
| 392 | }
|
|---|
| 393 | }
|
|---|
| 394 | # endif
|
|---|
| 395 |
|
|---|
| 396 | return retval;
|
|---|
| 397 |
|
|---|
| 398 | #else /* WIN32 */
|
|---|
| 399 |
|
|---|
| 400 | /* Return an XPG style locale name language[_territory][@modifier].
|
|---|
| 401 | Don't even bother determining the codeset; it's not useful in this
|
|---|
| 402 | context, because message catalogs are not specific to a single
|
|---|
| 403 | codeset. */
|
|---|
| 404 |
|
|---|
| 405 | LCID lcid;
|
|---|
| 406 | LANGID langid;
|
|---|
| 407 | int primary, sub;
|
|---|
| 408 |
|
|---|
| 409 | /* Let the user override the system settings through environment
|
|---|
| 410 | variables, as on POSIX systems. */
|
|---|
| 411 | retval = getenv ("LC_ALL");
|
|---|
| 412 | if (retval != NULL && retval[0] != '\0')
|
|---|
| 413 | return retval;
|
|---|
| 414 | retval = getenv (categoryname);
|
|---|
| 415 | if (retval != NULL && retval[0] != '\0')
|
|---|
| 416 | return retval;
|
|---|
| 417 | retval = getenv ("LANG");
|
|---|
| 418 | if (retval != NULL && retval[0] != '\0')
|
|---|
| 419 | return retval;
|
|---|
| 420 |
|
|---|
| 421 | /* Use native Win32 API locale ID. */
|
|---|
| 422 | lcid = GetThreadLocale ();
|
|---|
| 423 |
|
|---|
| 424 | /* Strip off the sorting rules, keep only the language part. */
|
|---|
| 425 | langid = LANGIDFROMLCID (lcid);
|
|---|
| 426 |
|
|---|
| 427 | /* Split into language and territory part. */
|
|---|
| 428 | primary = PRIMARYLANGID (langid);
|
|---|
| 429 | sub = SUBLANGID (langid);
|
|---|
| 430 | switch (primary)
|
|---|
| 431 | {
|
|---|
| 432 | case LANG_AFRIKAANS: return "af_ZA";
|
|---|
| 433 | case LANG_ALBANIAN: return "sq_AL";
|
|---|
| 434 | case LANG_ARABIC:
|
|---|
| 435 | switch (sub)
|
|---|
| 436 | {
|
|---|
| 437 | case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
|
|---|
| 438 | case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
|
|---|
| 439 | case SUBLANG_ARABIC_EGYPT: return "ar_EG";
|
|---|
| 440 | case SUBLANG_ARABIC_LIBYA: return "ar_LY";
|
|---|
| 441 | case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
|
|---|
| 442 | case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
|
|---|
| 443 | case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
|
|---|
| 444 | case SUBLANG_ARABIC_OMAN: return "ar_OM";
|
|---|
| 445 | case SUBLANG_ARABIC_YEMEN: return "ar_YE";
|
|---|
| 446 | case SUBLANG_ARABIC_SYRIA: return "ar_SY";
|
|---|
| 447 | case SUBLANG_ARABIC_JORDAN: return "ar_JO";
|
|---|
| 448 | case SUBLANG_ARABIC_LEBANON: return "ar_LB";
|
|---|
| 449 | case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
|
|---|
| 450 | case SUBLANG_ARABIC_UAE: return "ar_AE";
|
|---|
| 451 | case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
|
|---|
| 452 | case SUBLANG_ARABIC_QATAR: return "ar_QA";
|
|---|
| 453 | }
|
|---|
| 454 | return "ar";
|
|---|
| 455 | case LANG_ARMENIAN: return "hy_AM";
|
|---|
| 456 | case LANG_ASSAMESE: return "as_IN";
|
|---|
| 457 | case LANG_AZERI:
|
|---|
| 458 | switch (sub)
|
|---|
| 459 | {
|
|---|
| 460 | /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
|
|---|
| 461 | case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
|
|---|
| 462 | case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
|
|---|
| 463 | }
|
|---|
| 464 | return "az";
|
|---|
| 465 | case LANG_BASQUE:
|
|---|
| 466 | return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
|
|---|
| 467 | case LANG_BELARUSIAN: return "be_BY";
|
|---|
| 468 | case LANG_BENGALI: return "bn_IN";
|
|---|
| 469 | case LANG_BULGARIAN: return "bg_BG";
|
|---|
| 470 | case LANG_CATALAN: return "ca_ES";
|
|---|
| 471 | case LANG_CHINESE:
|
|---|
| 472 | switch (sub)
|
|---|
| 473 | {
|
|---|
| 474 | case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
|
|---|
| 475 | case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
|
|---|
| 476 | case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
|
|---|
| 477 | case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
|
|---|
| 478 | case SUBLANG_CHINESE_MACAU: return "zh_MO";
|
|---|
| 479 | }
|
|---|
| 480 | return "zh";
|
|---|
| 481 | case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN
|
|---|
| 482 | * What used to be called Serbo-Croatian
|
|---|
| 483 | * should really now be two separate
|
|---|
| 484 | * languages because of political reasons.
|
|---|
| 485 | * (Says tml, who knows nothing about Serbian
|
|---|
| 486 | * or Croatian.)
|
|---|
| 487 | * (I can feel those flames coming already.)
|
|---|
| 488 | */
|
|---|
| 489 | switch (sub)
|
|---|
| 490 | {
|
|---|
| 491 | /* FIXME: How to distinguish Croatian and Latin Serbian locales? */
|
|---|
| 492 | case SUBLANG_SERBIAN_LATIN: return "sr_YU";
|
|---|
| 493 | case SUBLANG_SERBIAN_CYRILLIC: return "sr_YU@cyrillic";
|
|---|
| 494 | default: return "hr_HR";
|
|---|
| 495 | }
|
|---|
| 496 | case LANG_CZECH: return "cs_CZ";
|
|---|
| 497 | case LANG_DANISH: return "da_DK";
|
|---|
| 498 | case LANG_DUTCH:
|
|---|
| 499 | switch (sub)
|
|---|
| 500 | {
|
|---|
| 501 | case SUBLANG_DUTCH: return "nl_NL";
|
|---|
| 502 | case SUBLANG_DUTCH_BELGIAN: return "nl_BE";
|
|---|
| 503 | }
|
|---|
| 504 | return "nl";
|
|---|
| 505 | case LANG_ENGLISH:
|
|---|
| 506 | switch (sub)
|
|---|
| 507 | {
|
|---|
| 508 | /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
|
|---|
| 509 | * English was the language spoken in England.
|
|---|
| 510 | * Oh well.
|
|---|
| 511 | */
|
|---|
| 512 | case SUBLANG_ENGLISH_US: return "en_US";
|
|---|
| 513 | case SUBLANG_ENGLISH_UK: return "en_GB";
|
|---|
| 514 | case SUBLANG_ENGLISH_AUS: return "en_AU";
|
|---|
| 515 | case SUBLANG_ENGLISH_CAN: return "en_CA";
|
|---|
| 516 | case SUBLANG_ENGLISH_NZ: return "en_NZ";
|
|---|
| 517 | case SUBLANG_ENGLISH_EIRE: return "en_IE";
|
|---|
| 518 | case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
|
|---|
| 519 | case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
|
|---|
| 520 | case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
|
|---|
| 521 | case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
|
|---|
| 522 | case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
|
|---|
| 523 | case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
|
|---|
| 524 | case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
|
|---|
| 525 | }
|
|---|
| 526 | return "en";
|
|---|
| 527 | case LANG_ESTONIAN: return "et_EE";
|
|---|
| 528 | case LANG_FAEROESE: return "fo_FO";
|
|---|
| 529 | case LANG_FARSI: return "fa_IR";
|
|---|
| 530 | case LANG_FINNISH: return "fi_FI";
|
|---|
| 531 | case LANG_FRENCH:
|
|---|
| 532 | switch (sub)
|
|---|
| 533 | {
|
|---|
| 534 | case SUBLANG_FRENCH: return "fr_FR";
|
|---|
| 535 | case SUBLANG_FRENCH_BELGIAN: return "fr_BE";
|
|---|
| 536 | case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
|
|---|
| 537 | case SUBLANG_FRENCH_SWISS: return "fr_CH";
|
|---|
| 538 | case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
|
|---|
| 539 | case SUBLANG_FRENCH_MONACO: return "fr_MC";
|
|---|
| 540 | }
|
|---|
| 541 | return "fr";
|
|---|
| 542 | case LANG_GEORGIAN: return "ka_GE";
|
|---|
| 543 | case LANG_GERMAN:
|
|---|
| 544 | switch (sub)
|
|---|
| 545 | {
|
|---|
| 546 | case SUBLANG_GERMAN: return "de_DE";
|
|---|
| 547 | case SUBLANG_GERMAN_SWISS: return "de_CH";
|
|---|
| 548 | case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
|
|---|
| 549 | case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
|
|---|
| 550 | case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
|
|---|
| 551 | }
|
|---|
| 552 | return "de";
|
|---|
| 553 | case LANG_GREEK: return "el_GR";
|
|---|
| 554 | case LANG_GUJARATI: return "gu_IN";
|
|---|
| 555 | case LANG_HEBREW: return "he_IL";
|
|---|
| 556 | case LANG_HINDI: return "hi_IN";
|
|---|
| 557 | case LANG_HUNGARIAN: return "hu_HU";
|
|---|
| 558 | case LANG_ICELANDIC: return "is_IS";
|
|---|
| 559 | case LANG_INDONESIAN: return "id_ID";
|
|---|
| 560 | case LANG_ITALIAN:
|
|---|
| 561 | switch (sub)
|
|---|
| 562 | {
|
|---|
| 563 | case SUBLANG_ITALIAN: return "it_IT";
|
|---|
| 564 | case SUBLANG_ITALIAN_SWISS: return "it_CH";
|
|---|
| 565 | }
|
|---|
| 566 | return "it";
|
|---|
| 567 | case LANG_JAPANESE: return "ja_JP";
|
|---|
| 568 | case LANG_KANNADA: return "kn_IN";
|
|---|
| 569 | case LANG_KASHMIRI:
|
|---|
| 570 | switch (sub)
|
|---|
| 571 | {
|
|---|
| 572 | case SUBLANG_DEFAULT: return "ks_PK";
|
|---|
| 573 | case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
|
|---|
| 574 | }
|
|---|
| 575 | return "ks";
|
|---|
| 576 | case LANG_KAZAK: return "kk_KZ";
|
|---|
| 577 | case LANG_KONKANI:
|
|---|
| 578 | /* FIXME: Adjust this when such locales appear on Unix. */
|
|---|
| 579 | return "kok_IN";
|
|---|
| 580 | case LANG_KOREAN: return "ko_KR";
|
|---|
| 581 | case LANG_LATVIAN: return "lv_LV";
|
|---|
| 582 | case LANG_LITHUANIAN: return "lt_LT";
|
|---|
| 583 | case LANG_MACEDONIAN: return "mk_MK";
|
|---|
| 584 | case LANG_MALAY:
|
|---|
| 585 | switch (sub)
|
|---|
| 586 | {
|
|---|
| 587 | case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
|
|---|
| 588 | case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
|
|---|
| 589 | }
|
|---|
| 590 | return "ms";
|
|---|
| 591 | case LANG_MALAYALAM: return "ml_IN";
|
|---|
| 592 | case LANG_MANIPURI:
|
|---|
| 593 | /* FIXME: Adjust this when such locales appear on Unix. */
|
|---|
| 594 | return "mni_IN";
|
|---|
| 595 | case LANG_MARATHI: return "mr_IN";
|
|---|
| 596 | case LANG_NEPALI:
|
|---|
| 597 | switch (sub)
|
|---|
| 598 | {
|
|---|
| 599 | case SUBLANG_DEFAULT: return "ne_NP";
|
|---|
| 600 | case SUBLANG_NEPALI_INDIA: return "ne_IN";
|
|---|
| 601 | }
|
|---|
| 602 | return "ne";
|
|---|
| 603 | case LANG_NORWEGIAN:
|
|---|
| 604 | switch (sub)
|
|---|
| 605 | {
|
|---|
| 606 | case SUBLANG_NORWEGIAN_BOKMAL: return "no_NO";
|
|---|
| 607 | case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
|
|---|
| 608 | }
|
|---|
| 609 | return "no";
|
|---|
| 610 | case LANG_ORIYA: return "or_IN";
|
|---|
| 611 | case LANG_POLISH: return "pl_PL";
|
|---|
| 612 | case LANG_PORTUGUESE:
|
|---|
| 613 | switch (sub)
|
|---|
| 614 | {
|
|---|
| 615 | case SUBLANG_PORTUGUESE: return "pt_PT";
|
|---|
| 616 | /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
|
|---|
| 617 | Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
|
|---|
| 618 | case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
|
|---|
| 619 | }
|
|---|
| 620 | return "pt";
|
|---|
| 621 | case LANG_PUNJABI: return "pa_IN";
|
|---|
| 622 | case LANG_ROMANIAN: return "ro_RO";
|
|---|
| 623 | case LANG_RUSSIAN:
|
|---|
| 624 | return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA". */
|
|---|
| 625 | case LANG_SANSKRIT: return "sa_IN";
|
|---|
| 626 | case LANG_SINDHI: return "sd";
|
|---|
| 627 | case LANG_SLOVAK: return "sk_SK";
|
|---|
| 628 | case LANG_SLOVENIAN: return "sl_SI";
|
|---|
| 629 | case LANG_SORBIAN:
|
|---|
| 630 | /* FIXME: Adjust this when such locales appear on Unix. */
|
|---|
| 631 | return "wen_DE";
|
|---|
| 632 | case LANG_SPANISH:
|
|---|
| 633 | switch (sub)
|
|---|
| 634 | {
|
|---|
| 635 | case SUBLANG_SPANISH: return "es_ES";
|
|---|
| 636 | case SUBLANG_SPANISH_MEXICAN: return "es_MX";
|
|---|
| 637 | case SUBLANG_SPANISH_MODERN:
|
|---|
| 638 | return "es_ES@modern"; /* not seen on Unix */
|
|---|
| 639 | case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
|
|---|
| 640 | case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
|
|---|
| 641 | case SUBLANG_SPANISH_PANAMA: return "es_PA";
|
|---|
| 642 | case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
|
|---|
| 643 | case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
|
|---|
| 644 | case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
|
|---|
| 645 | case SUBLANG_SPANISH_PERU: return "es_PE";
|
|---|
| 646 | case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
|
|---|
| 647 | case SUBLANG_SPANISH_ECUADOR: return "es_EC";
|
|---|
| 648 | case SUBLANG_SPANISH_CHILE: return "es_CL";
|
|---|
| 649 | case SUBLANG_SPANISH_URUGUAY: return "es_UY";
|
|---|
| 650 | case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
|
|---|
| 651 | case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
|
|---|
| 652 | case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
|
|---|
| 653 | case SUBLANG_SPANISH_HONDURAS: return "es_HN";
|
|---|
| 654 | case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
|
|---|
| 655 | case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
|
|---|
| 656 | }
|
|---|
| 657 | return "es";
|
|---|
| 658 | case LANG_SWAHILI: return "sw";
|
|---|
| 659 | case LANG_SWEDISH:
|
|---|
| 660 | switch (sub)
|
|---|
| 661 | {
|
|---|
| 662 | case SUBLANG_DEFAULT: return "sv_SE";
|
|---|
| 663 | case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
|
|---|
| 664 | }
|
|---|
| 665 | return "sv";
|
|---|
| 666 | case LANG_TAMIL:
|
|---|
| 667 | return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
|
|---|
| 668 | case LANG_TATAR: return "tt";
|
|---|
| 669 | case LANG_TELUGU: return "te_IN";
|
|---|
| 670 | case LANG_THAI: return "th_TH";
|
|---|
| 671 | case LANG_TURKISH: return "tr_TR";
|
|---|
| 672 | case LANG_UKRAINIAN: return "uk_UA";
|
|---|
| 673 | case LANG_URDU:
|
|---|
| 674 | switch (sub)
|
|---|
| 675 | {
|
|---|
| 676 | case SUBLANG_URDU_PAKISTAN: return "ur_PK";
|
|---|
| 677 | case SUBLANG_URDU_INDIA: return "ur_IN";
|
|---|
| 678 | }
|
|---|
| 679 | return "ur";
|
|---|
| 680 | case LANG_UZBEK:
|
|---|
| 681 | switch (sub)
|
|---|
| 682 | {
|
|---|
| 683 | /* FIXME: Adjust this when Uzbek locales appear on Unix. */
|
|---|
| 684 | case SUBLANG_UZBEK_LATIN: return "uz_UZ@latin";
|
|---|
| 685 | case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
|
|---|
| 686 | }
|
|---|
| 687 | return "uz";
|
|---|
| 688 | case LANG_VIETNAMESE: return "vi_VN";
|
|---|
| 689 | default: return "C";
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| 692 | #endif
|
|---|
| 693 | }
|
|---|