Debian Codegraph @

lib-python/3/locale.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 """Locale support module.
2
3 The module provides low-level access to the C lib's locale APIs and adds high
4 level number formatting APIs as well as a locale aliasing engine to complement
5 these.
6
7 The aliasing engine includes support for many commonly used locale names and
8 maps them to values suitable for passing to the C lib's setlocale() function. It
9 also includes default encodings for all supported locale names.
10
11 """
12
13 import sys
14 import encodings
15 import encodings.aliases
16 import re
17 import _collections_abc
18 from builtins import str as _builtin_str
19 import functools
20
21 # Try importing the _locale module.
22 #
23 # If this fails, fall back on a basic 'C' locale emulation.
24
25 # Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before
26 # trying the import. So __all__ is also fiddled at the end of the file.
27 __all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error",
28 "setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm",
29 "str", "atof", "atoi", "format", "format_string", "currency",
30 "normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
31 "LC_NUMERIC", "LC_ALL", "CHAR_MAX", "getencoding"]
32
33 def _strcoll(a,b):
34 """ strcoll(string,string) -> int.
35 Compares two strings according to the locale.
36 """
37 return (a > b) - (a < b)
38
39 def _strxfrm(s):
40 """ strxfrm(string) -> string.
41 Returns a string that behaves for cmp locale-aware.
42 """
43 return s
44
45 try:
46
47 from _locale import *
48
49 except ImportError:
50
51 # Locale emulation
52
53 CHAR_MAX = 127
54 LC_ALL = 6
55 LC_COLLATE = 3
56 LC_CTYPE = 0
57 LC_MESSAGES = 5
58 LC_MONETARY = 4
59 LC_NUMERIC = 1
60 LC_TIME = 2
61 Error = ValueError
62
63 def localeconv():
64 """ localeconv() -> dict.
65 Returns numeric and monetary locale-specific parameters.
66 """
67 # 'C' locale default values
68 return {'grouping': [127],
69 'currency_symbol': '',
70 'n_sign_posn': 127,
71 'p_cs_precedes': 127,
72 'n_cs_precedes': 127,
73 'mon_grouping': [],
74 'n_sep_by_space': 127,
75 'decimal_point': '.',
76 'negative_sign': '',
77 'positive_sign': '',
78 'p_sep_by_space': 127,
79 'int_curr_symbol': '',
80 'p_sign_posn': 127,
81 'thousands_sep': '',
82 'mon_thousands_sep': '',
83 'frac_digits': 127,
84 'mon_decimal_point': '',
85 'int_frac_digits': 127}
86
87 def setlocale(category, value=None):
88 """ setlocale(integer,string=None) -> string.
89 Activates/queries locale processing.
90 """
91 if value not in (None, '', 'C'):
92 raise Error('_locale emulation only supports "C" locale')
93 return 'C'
94
95 # These may or may not exist in _locale, so be sure to set them.
96 if 'strxfrm' not in globals():
97 strxfrm = _strxfrm
98 if 'strcoll' not in globals():
99 strcoll = _strcoll
100
101
102 _localeconv = localeconv
103
104 # With this dict, you can override some items of localeconv's return value.
105 # This is useful for testing purposes.
106 _override_localeconv = {}
107
108 @functools.wraps(_localeconv)
109 def localeconv():
110 d = _localeconv()
111 if _override_localeconv:
112 d.update(_override_localeconv)
113 return d
114
115
116 ### Number formatting APIs
117
118 # Author: Martin von Loewis
119 # improved by Georg Brandl
120
121 # Iterate over grouping intervals
122 def _grouping_intervals(grouping):
123 last_interval = None
124 for interval in grouping:
125 # if grouping is -1, we are done
126 if interval == CHAR_MAX:
127 return
128 # 0: re-use last group ad infinitum
129 if interval == 0:
130 if last_interval is None:
131 raise ValueError("invalid grouping")
132 while True:
133 yield last_interval
134 yield interval
135 last_interval = interval
136
137 #perform the grouping from right to left
138 def _group(s, monetary=False):
139 conv = localeconv()
140 thousands_sep = conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
141 grouping = conv[monetary and 'mon_grouping' or 'grouping']
142 if not grouping:
143 return (s, 0)
144 if s[-1] == ' ':
145 stripped = s.rstrip()
146 right_spaces = s[len(stripped):]
147 s = stripped
148 else:
149 right_spaces = ''
150 left_spaces = ''
151 groups = []
152 for interval in _grouping_intervals(grouping):
153 if not s or s[-1] not in "0123456789":
154 # only non-digit characters remain (sign, spaces)
155 left_spaces = s
156 s = ''
157 break
158 groups.append(s[-interval:])
159 s = s[:-interval]
160 if s:
161 groups.append(s)
162 groups.reverse()
163 return (
164 left_spaces + thousands_sep.join(groups) + right_spaces,
165 len(thousands_sep) * (len(groups) - 1)
166 )
167
168 # Strip a given amount of excess padding from the given string
169 def _strip_padding(s, amount):
170 lpos = 0
171 while amount and s[lpos] == ' ':
172 lpos += 1
173 amount -= 1
174 rpos = len(s) - 1
175 while amount and s[rpos] == ' ':
176 rpos -= 1
177 amount -= 1
178 return s[lpos:rpos+1]
179
180 _percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
181 r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
182
183 def _format(percent, value, grouping=False, monetary=False, *additional):
184 if additional:
185 formatted = percent % ((value,) + additional)
186 else:
187 formatted = percent % value
188 if percent[-1] in 'eEfFgGdiu':
189 formatted = _localize(formatted, grouping, monetary)
190 return formatted
191
192 # Transform formatted as locale number according to the locale settings
193 def _localize(formatted, grouping=False, monetary=False):
194 # floats and decimal ints need special action!
195 if '.' in formatted:
196 seps = 0
197 parts = formatted.split('.')
198 if grouping:
199 parts[0], seps = _group(parts[0], monetary=monetary)
200 decimal_point = localeconv()[monetary and 'mon_decimal_point'
201 or 'decimal_point']
202 formatted = decimal_point.join(parts)
203 if seps:
204 formatted = _strip_padding(formatted, seps)
205 else:
206 seps = 0
207 if grouping:
208 formatted, seps = _group(formatted, monetary=monetary)
209 if seps:
210 formatted = _strip_padding(formatted, seps)
211 return formatted
212
213 def format_string(f, val, grouping=False, monetary=False):
214 """Formats a string in the same way that the % formatting would use,
215 but takes the current locale into account.
216
217 Grouping is applied if the third parameter is true.
218 Conversion uses monetary thousands separator and grouping strings if
219 forth parameter monetary is true."""
220 percents = list(_percent_re.finditer(f))
221 new_f = _percent_re.sub('%s', f)
222
223 if isinstance(val, _collections_abc.Mapping):
224 new_val = []
225 for perc in percents:
226 if perc.group()[-1]=='%':
227 new_val.append('%')
228 else:
229 new_val.append(_format(perc.group(), val, grouping, monetary))
230 else:
231 if not isinstance(val, tuple):
232 val = (val,)
233 new_val = []
234 i = 0
235 for perc in percents:
236 if perc.group()[-1]=='%':
237 new_val.append('%')
238 else:
239 starcount = perc.group('modifiers').count('*')
240 new_val.append(_format(perc.group(),
241 val[i],
242 grouping,
243 monetary,
244 *val[i+1:i+1+starcount]))
245 i += (1 + starcount)
246 val = tuple(new_val)
247
248 return new_f % val
249
250 def format(percent, value, grouping=False, monetary=False, *additional):
251 """Deprecated, use format_string instead."""
252 import warnings
253 warnings.warn(
254 "This method will be removed in a future version of Python. "
255 "Use 'locale.format_string()' instead.",
256 DeprecationWarning, stacklevel=2
257 )
258
259 match = _percent_re.match(percent)
260 if not match or len(match.group())!= len(percent):
261 raise ValueError(("format() must be given exactly one %%char "
262 "format specifier, %s not valid") % repr(percent))
263 return _format(percent, value, grouping, monetary, *additional)
264
265 def currency(val, symbol=True, grouping=False, international=False):
266 """Formats val according to the currency settings
267 in the current locale."""
268 conv = localeconv()
269
270 # check for illegal values
271 digits = conv[international and 'int_frac_digits' or 'frac_digits']
272 if digits == 127:
273 raise ValueError("Currency formatting is not possible using "
274 "the 'C' locale.")
275
276 s = _localize(f'{abs(val):.{digits}f}', grouping, monetary=True)
277 # '<' and '>' are markers if the sign must be inserted between symbol and value
278 s = '<' + s + '>'
279
280 if symbol:
281 smb = conv[international and 'int_curr_symbol' or 'currency_symbol']
282 precedes = conv[val<0 and 'n_cs_precedes' or 'p_cs_precedes']
283 separated = conv[val<0 and 'n_sep_by_space' or 'p_sep_by_space']
284
285 if precedes:
286 s = smb + (separated and ' ' or '') + s
287 else:
288 if international and smb[-1] == ' ':
289 smb = smb[:-1]
290 s = s + (separated and ' ' or '') + smb
291
292 sign_pos = conv[val<0 and 'n_sign_posn' or 'p_sign_posn']
293 sign = conv[val<0 and 'negative_sign' or 'positive_sign']
294
295 if sign_pos == 0:
296 s = '(' + s + ')'
297 elif sign_pos == 1:
298 s = sign + s
299 elif sign_pos == 2:
300 s = s + sign
301 elif sign_pos == 3:
302 s = s.replace('<', sign)
303 elif sign_pos == 4:
304 s = s.replace('>', sign)
305 else:
306 # the default if nothing specified;
307 # this should be the most fitting sign position
308 s = sign + s
309
310 return s.replace('<', '').replace('>', '')
311
312 def str(val):
313 """Convert float to string, taking the locale into account."""
314 return _format("%.12g", val)
315
316 def delocalize(string):
317 "Parses a string as a normalized number according to the locale settings."
318
319 conv = localeconv()
320
321 #First, get rid of the grouping
322 ts = conv['thousands_sep']
323 if ts:
324 string = string.replace(ts, '')
325
326 #next, replace the decimal point with a dot
327 dd = conv['decimal_point']
328 if dd:
329 string = string.replace(dd, '.')
330 return string
331
332 def localize(string, grouping=False, monetary=False):
333 """Parses a string as locale number according to the locale settings."""
334 return _localize(string, grouping, monetary)
335
336 def atof(string, func=float):
337 "Parses a string as a float according to the locale settings."
338 return func(delocalize(string))
339
340 def atoi(string):
341 "Converts a string to an integer according to the locale settings."
342 return int(delocalize(string))
343
344 def _test():
345 setlocale(LC_ALL, "")
346 #do grouping
347 s1 = format_string("%d", 123456789,1)
348 print(s1, "is", atoi(s1))
349 #standard formatting
350 s1 = str(3.14)
351 print(s1, "is", atof(s1))
352
353 ### Locale name aliasing engine
354
355 # Author: Marc-Andre Lemburg, [email protected]
356 # Various tweaks by Fredrik Lundh <[email protected]>
357
358 # store away the low-level version of setlocale (it's
359 # overridden below)
360 _setlocale = setlocale
361
362 def _replace_encoding(code, encoding):
363 if '.' in code:
364 langname = code[:code.index('.')]
365 else:
366 langname = code
367 # Convert the encoding to a C lib compatible encoding string
368 norm_encoding = encodings.normalize_encoding(encoding)
369 #print('norm encoding: %r' % norm_encoding)
370 norm_encoding = encodings.aliases.aliases.get(norm_encoding.lower(),
371 norm_encoding)
372 #print('aliased encoding: %r' % norm_encoding)
373 encoding = norm_encoding
374 norm_encoding = norm_encoding.lower()
375 if norm_encoding in locale_encoding_alias:
376 encoding = locale_encoding_alias[norm_encoding]
377 else:
378 norm_encoding = norm_encoding.replace('_', '')
379 norm_encoding = norm_encoding.replace('-', '')
380 if norm_encoding in locale_encoding_alias:
381 encoding = locale_encoding_alias[norm_encoding]
382 #print('found encoding %r' % encoding)
383 return langname + '.' + encoding
384
385 def _append_modifier(code, modifier):
386 if modifier == 'euro':
387 if '.' not in code:
388 return code + '.ISO8859-15'
389 _, _, encoding = code.partition('.')
390 if encoding in ('ISO8859-15', 'UTF-8'):
391 return code
392 if encoding == 'ISO8859-1':
393 return _replace_encoding(code, 'ISO8859-15')
394 return code + '@' + modifier
395
396 def normalize(localename):
397
398 """ Returns a normalized locale code for the given locale
399 name.
400
401 The returned locale code is formatted for use with
402 setlocale().
403
404 If normalization fails, the original name is returned
405 unchanged.
406
407 If the given encoding is not known, the function defaults to
408 the default encoding for the locale code just like setlocale()
409 does.
410
411 """
412 # Normalize the locale name and extract the encoding and modifier
413 code = localename.lower()
414 if ':' in code:
415 # ':' is sometimes used as encoding delimiter.
416 code = code.replace(':', '.')
417 if '@' in code:
418 code, modifier = code.split('@', 1)
419 else:
420 modifier = ''
421 if '.' in code:
422 langname, encoding = code.split('.')[:2]
423 else:
424 langname = code
425 encoding = ''
426
427 # First lookup: fullname (possibly with encoding and modifier)
428 lang_enc = langname
429 if encoding:
430 norm_encoding = encoding.replace('-', '')
431 norm_encoding = norm_encoding.replace('_', '')
432 lang_enc += '.' + norm_encoding
433 lookup_name = lang_enc
434 if modifier:
435 lookup_name += '@' + modifier
436 code = locale_alias.get(lookup_name, None)
437 if code is not None:
438 return code
439 #print('first lookup failed')
440
441 if modifier:
442 # Second try: fullname without modifier (possibly with encoding)
443 code = locale_alias.get(lang_enc, None)
444 if code is not None:
445 #print('lookup without modifier succeeded')
446 if '@' not in code:
447 return _append_modifier(code, modifier)
448 if code.split('@', 1)[1].lower() == modifier:
449 return code
450 #print('second lookup failed')
451
452 if encoding:
453 # Third try: langname (without encoding, possibly with modifier)
454 lookup_name = langname
455 if modifier:
456 lookup_name += '@' + modifier
457 code = locale_alias.get(lookup_name, None)
458 if code is not None:
459 #print('lookup without encoding succeeded')
460 if '@' not in code:
461 return _replace_encoding(code, encoding)
462 code, modifier = code.split('@', 1)
463 return _replace_encoding(code, encoding) + '@' + modifier
464
465 if modifier:
466 # Fourth try: langname (without encoding and modifier)
467 code = locale_alias.get(langname, None)
468 if code is not None:
469 #print('lookup without modifier and encoding succeeded')
470 if '@' not in code:
471 code = _replace_encoding(code, encoding)
472 return _append_modifier(code, modifier)
473 code, defmod = code.split('@', 1)
474 if defmod.lower() == modifier:
475 return _replace_encoding(code, encoding) + '@' + defmod
476
477 return localename
478
479 def _parse_localename(localename):
480
481 """ Parses the locale code for localename and returns the
482 result as tuple (language code, encoding).
483
484 The localename is normalized and passed through the locale
485 alias engine. A ValueError is raised in case the locale name
486 cannot be parsed.
487
488 The language code corresponds to RFC 1766. code and encoding
489 can be None in case the values cannot be determined or are
490 unknown to this implementation.
491
492 """
493 code = normalize(localename)
494 if '@' in code:
495 # Deal with locale modifiers
496 code, modifier = code.split('@', 1)
497 if modifier == 'euro' and '.' not in code:
498 # Assume Latin-9 for @euro locales. This is bogus,
499 # since some systems may use other encodings for these
500 # locales. Also, we ignore other modifiers.
501 return code, 'iso-8859-15'
502
503 if '.' in code:
504 return tuple(code.split('.')[:2])
505 elif code == 'C':
506 return None, None
507 elif code == 'UTF-8':
508 # On macOS "LC_CTYPE=UTF-8" is a valid locale setting
509 # for getting UTF-8 handling for text.
510 return None, 'UTF-8'
511 raise ValueError('unknown locale: %s' % localename)
512
513 def _build_localename(localetuple):
514
515 """ Builds a locale code from the given tuple (language code,
516 encoding).
517
518 No aliasing or normalizing takes place.
519
520 """
521 try:
522 language, encoding = localetuple
523
524 if language is None:
525 language = 'C'
526 if encoding is None:
527 return language
528 else:
529 return language + '.' + encoding
530 except (TypeError, ValueError):
531 raise TypeError('Locale must be None, a string, or an iterable of '
532 'two strings -- language code, encoding.') from None
533
534 def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
535
536 """ Tries to determine the default locale settings and returns
537 them as tuple (language code, encoding).
538
539 According to POSIX, a program which has not called
540 setlocale(LC_ALL, "") runs using the portable 'C' locale.
541 Calling setlocale(LC_ALL, "") lets it use the default locale as
542 defined by the LANG variable. Since we don't want to interfere
543 with the current locale setting we thus emulate the behavior
544 in the way described above.
545
546 To maintain compatibility with other platforms, not only the
547 LANG variable is tested, but a list of variables given as
548 envvars parameter. The first found to be defined will be
549 used. envvars defaults to the search path used in GNU gettext;
550 it must always contain the variable name 'LANG'.
551
552 Except for the code 'C', the language code corresponds to RFC
553 1766. code and encoding can be None in case the values cannot
554 be determined.
555
556 """
557
558 import warnings
559 warnings._deprecated(
560 "locale.getdefaultlocale",
561 "{name!r} is deprecated and slated for removal in Python {remove}. "
562 "Use setlocale(), getencoding() and getlocale() instead.",
563 remove=(3, 15))
564
565 try:
566 # check if it's supported by the _locale module
567 import _locale
568 code, encoding = _locale._getdefaultlocale()
569 except (ImportError, AttributeError):
570 pass
571 else:
572 # make sure the code/encoding values are valid
573 if sys.platform == "win32" and code and code[:2] == "0x":
574 # map windows language identifier to language name
575 code = windows_locale.get(int(code, 0))
576 # ...add other platform-specific processing here, if
577 # necessary...
578 return code, encoding
579
580 # fall back on POSIX behaviour
581 import os
582 lookup = os.environ.get
583 for variable in envvars:
584 localename = lookup(variable,None)
585 if localename:
586 if variable == 'LANGUAGE':
587 localename = localename.split(':')[0]
588 break
589 else:
590 localename = 'C'
591 return _parse_localename(localename)
592
593
594 def getlocale(category=LC_CTYPE):
595
596 """ Returns the current setting for the given locale category as
597 tuple (language code, encoding).
598
599 category may be one of the LC_* value except LC_ALL. It
600 defaults to LC_CTYPE.
601
602 Except for the code 'C', the language code corresponds to RFC
603 1766. code and encoding can be None in case the values cannot
604 be determined.
605
606 """
607 localename = _setlocale(category)
608 if category == LC_ALL and ';' in localename:
609 raise TypeError('category LC_ALL is not supported')
610 return _parse_localename(localename)
611
612 def setlocale(category, locale=None):
613
614 """ Set the locale for the given category. The locale can be
615 a string, an iterable of two strings (language code and encoding),
616 or None.
617
618 Iterables are converted to strings using the locale aliasing
619 engine. Locale strings are passed directly to the C lib.
620
621 category may be given as one of the LC_* values.
622
623 """
624 if locale and not isinstance(locale, _builtin_str):
625 # convert to string
626 locale = normalize(_build_localename(locale))
627 return _setlocale(category, locale)
628
629 def resetlocale(category=LC_ALL):
630
631 """ Sets the locale for category to the default setting.
632
633 The default setting is determined by calling
634 getdefaultlocale(). category defaults to LC_ALL.
635
636 """
637 import warnings
638 warnings.warn(
639 'Use locale.setlocale(locale.LC_ALL, "") instead',
640 DeprecationWarning, stacklevel=2
641 )
642
643 with warnings.catch_warnings():
644 warnings.simplefilter('ignore', category=DeprecationWarning)
645 loc = getdefaultlocale()
646
647 _setlocale(category, _build_localename(loc))
648
649
650 try:
651 from _locale import getencoding
652 except ImportError:
653 def getencoding():
654 if hasattr(sys, 'getandroidapilevel'):
655 # On Android langinfo.h and CODESET are missing, and UTF-8 is
656 # always used in mbstowcs() and wcstombs().
657 return 'utf-8'
658 encoding = getdefaultlocale()[1]
659 if encoding is None:
660 # LANG not set, default to UTF-8
661 encoding = 'utf-8'
662 return encoding
663
664 try:
665 CODESET
666 except NameError:
667 def getpreferredencoding(do_setlocale=True):
668 """Return the charset that the user is likely using."""
669 if sys.flags.warn_default_encoding:
670 import warnings
671 warnings.warn(
672 "UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.",
673 EncodingWarning, 2)
674 if sys.flags.utf8_mode:
675 return 'utf-8'
676 return getencoding()
677 else:
678 # On Unix, if CODESET is available, use that.
679 def getpreferredencoding(do_setlocale=True):
680 """Return the charset that the user is likely using,
681 according to the system configuration."""
682
683 if sys.flags.warn_default_encoding:
684 import warnings
685 warnings.warn(
686 "UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.",
687 EncodingWarning, 2)
688 if sys.flags.utf8_mode:
689 return 'utf-8'
690
691 if not do_setlocale:
692 return getencoding()
693
694 old_loc = setlocale(LC_CTYPE)
695 try:
696 try:
697 setlocale(LC_CTYPE, "")
698 except Error:
699 pass
700 return getencoding()
701 finally:
702 setlocale(LC_CTYPE, old_loc)
703
704
705 ### Database
706 #
707 # The following data was extracted from the locale.alias file which
708 # comes with X11 and then hand edited removing the explicit encoding
709 # definitions and adding some more aliases. The file is usually
710 # available as /usr/lib/X11/locale/locale.alias.
711 #
712
713 #
714 # The local_encoding_alias table maps lowercase encoding alias names
715 # to C locale encoding names (case-sensitive). Note that normalize()
716 # first looks up the encoding in the encodings.aliases dictionary and
717 # then applies this mapping to find the correct C lib name for the
718 # encoding.
719 #
720 locale_encoding_alias = {
721
722 # Mappings for non-standard encoding names used in locale names
723 '437': 'C',
724 'c': 'C',
725 'en': 'ISO8859-1',
726 'jis': 'JIS7',
727 'jis7': 'JIS7',
728 'ajec': 'eucJP',
729 'koi8c': 'KOI8-C',
730 'microsoftcp1251': 'CP1251',
731 'microsoftcp1255': 'CP1255',
732 'microsoftcp1256': 'CP1256',
733 '88591': 'ISO8859-1',
734 '88592': 'ISO8859-2',
735 '88595': 'ISO8859-5',
736 '885915': 'ISO8859-15',
737
738 # Mappings from Python codec names to C lib encoding names
739 'ascii': 'ISO8859-1',
740 'latin_1': 'ISO8859-1',
741 'iso8859_1': 'ISO8859-1',
742 'iso8859_10': 'ISO8859-10',
743 'iso8859_11': 'ISO8859-11',
744 'iso8859_13': 'ISO8859-13',
745 'iso8859_14': 'ISO8859-14',
746 'iso8859_15': 'ISO8859-15',
747 'iso8859_16': 'ISO8859-16',
748 'iso8859_2': 'ISO8859-2',
749 'iso8859_3': 'ISO8859-3',
750 'iso8859_4': 'ISO8859-4',
751 'iso8859_5': 'ISO8859-5',
752 'iso8859_6': 'ISO8859-6',
753 'iso8859_7': 'ISO8859-7',
754 'iso8859_8': 'ISO8859-8',
755 'iso8859_9': 'ISO8859-9',
756 'iso2022_jp': 'JIS7',
757 'shift_jis': 'SJIS',
758 'tactis': 'TACTIS',
759 'euc_jp': 'eucJP',
760 'euc_kr': 'eucKR',
761 'utf_8': 'UTF-8',
762 'koi8_r': 'KOI8-R',
763 'koi8_t': 'KOI8-T',
764 'koi8_u': 'KOI8-U',
765 'kz1048': 'RK1048',
766 'cp1251': 'CP1251',
767 'cp1255': 'CP1255',
768 'cp1256': 'CP1256',
769
770 # XXX This list is still incomplete. If you know more
771 # mappings, please file a bug report. Thanks.
772 }
773
774 for k, v in sorted(locale_encoding_alias.items()):
775 k = k.replace('_', '')
776 locale_encoding_alias.setdefault(k, v)
777 del k, v
778
779 #
780 # The locale_alias table maps lowercase alias names to C locale names
781 # (case-sensitive). Encodings are always separated from the locale
782 # name using a dot ('.'); they should only be given in case the
783 # language name is needed to interpret the given encoding alias
784 # correctly (CJK codes often have this need).
785 #
786 # Note that the normalize() function which uses this tables
787 # removes '_' and '-' characters from the encoding part of the
788 # locale name before doing the lookup. This saves a lot of
789 # space in the table.
790 #
791 # MAL 2004-12-10:
792 # Updated alias mapping to most recent locale.alias file
793 # from X.org distribution using makelocalealias.py.
794 #
795 # These are the differences compared to the old mapping (Python 2.4
796 # and older):
797 #
798 # updated 'bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
799 # updated 'bg_bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
800 # updated 'bulgarian' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
801 # updated 'cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
802 # updated 'cz_cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
803 # updated 'czech' -> 'cs_CS.ISO8859-2' to 'cs_CZ.ISO8859-2'
804 # updated 'dutch' -> 'nl_BE.ISO8859-1' to 'nl_NL.ISO8859-1'
805 # updated 'et' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
806 # updated 'et_ee' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
807 # updated 'fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
808 # updated 'fi_fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
809 # updated 'iw' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
810 # updated 'iw_il' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
811 # updated 'japanese' -> 'ja_JP.SJIS' to 'ja_JP.eucJP'
812 # updated 'lt' -> 'lt_LT.ISO8859-4' to 'lt_LT.ISO8859-13'
813 # updated 'lv' -> 'lv_LV.ISO8859-4' to 'lv_LV.ISO8859-13'
814 # updated 'sl' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
815 # updated 'slovene' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
816 # updated 'th_th' -> 'th_TH.TACTIS' to 'th_TH.ISO8859-11'
817 # updated 'zh_cn' -> 'zh_CN.eucCN' to 'zh_CN.gb2312'
818 # updated 'zh_cn.big5' -> 'zh_TW.eucTW' to 'zh_TW.big5'
819 # updated 'zh_tw' -> 'zh_TW.eucTW' to 'zh_TW.big5'
820 #
821 # MAL 2008-05-30:
822 # Updated alias mapping to most recent locale.alias file
823 # from X.org distribution using makelocalealias.py.
824 #
825 # These are the differences compared to the old mapping (Python 2.5
826 # and older):
827 #
828 # updated 'cs_cs.iso88592' -> 'cs_CZ.ISO8859-2' to 'cs_CS.ISO8859-2'
829 # updated 'serbocroatian' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
830 # updated 'sh' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
831 # updated 'sh_hr.iso88592' -> 'sh_HR.ISO8859-2' to 'hr_HR.ISO8859-2'
832 # updated 'sh_sp' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
833 # updated 'sh_yu' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
834 # updated 'sp' -> 'sp_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
835 # updated 'sp_yu' -> 'sp_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
836 # updated 'sr' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
837 # updated 'sr@cyrillic' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
838 # updated 'sr_sp' -> 'sr_SP.ISO8859-2' to 'sr_CS.ISO8859-2'
839 # updated 'sr_yu' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
840 # updated 'sr_yu.cp1251@cyrillic' -> 'sr_YU.CP1251' to 'sr_CS.CP1251'
841 # updated 'sr_yu.iso88592' -> 'sr_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
842 # updated 'sr_yu.iso88595' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
843 # updated 'sr_yu.iso88595@cyrillic' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
844 # updated 'sr_yu.microsoftcp1251@cyrillic' -> 'sr_YU.CP1251' to 'sr_CS.CP1251'
845 # updated 'sr_yu.utf8@cyrillic' -> 'sr_YU.UTF-8' to 'sr_CS.UTF-8'
846 # updated 'sr_yu@cyrillic' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
847 #
848 # AP 2010-04-12:
849 # Updated alias mapping to most recent locale.alias file
850 # from X.org distribution using makelocalealias.py.
851 #
852 # These are the differences compared to the old mapping (Python 2.6.5
853 # and older):
854 #
855 # updated 'ru' -> 'ru_RU.ISO8859-5' to 'ru_RU.UTF-8'
856 # updated 'ru_ru' -> 'ru_RU.ISO8859-5' to 'ru_RU.UTF-8'
857 # updated 'serbocroatian' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
858 # updated 'sh' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
859 # updated 'sh_yu' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
860 # updated 'sr' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8'
861 # updated 'sr@cyrillic' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8'
862 # updated 'sr@latn' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
863 # updated 'sr_cs.utf8@latn' -> 'sr_CS.UTF-8' to 'sr_RS.UTF-8@latin'
864 # updated 'sr_cs@latn' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
865 # updated 'sr_yu' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8@latin'
866 # updated 'sr_yu.utf8@cyrillic' -> 'sr_CS.UTF-8' to 'sr_RS.UTF-8'
867 # updated 'sr_yu@cyrillic' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8'
868 #
869 # SS 2013-12-20:
870 # Updated alias mapping to most recent locale.alias file
871 # from X.org distribution using makelocalealias.py.
872 #
873 # These are the differences compared to the old mapping (Python 3.3.3
874 # and older):
875 #
876 # updated 'a3' -> 'a3_AZ.KOI8-C' to 'az_AZ.KOI8-C'
877 # updated 'a3_az' -> 'a3_AZ.KOI8-C' to 'az_AZ.KOI8-C'
878 # updated 'a3_az.koi8c' -> 'a3_AZ.KOI8-C' to 'az_AZ.KOI8-C'
879 # updated 'cs_cs.iso88592' -> 'cs_CS.ISO8859-2' to 'cs_CZ.ISO8859-2'
880 # updated 'hebrew' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
881 # updated 'hebrew.iso88598' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
882 # updated 'sd' -> '[email protected]' to 'sd_IN.UTF-8'
883 # updated 'sr@latn' -> 'sr_RS.UTF-8@latin' to 'sr_CS.UTF-8@latin'
884 # updated 'sr_cs' -> 'sr_RS.UTF-8' to 'sr_CS.UTF-8'
885 # updated 'sr_cs.utf8@latn' -> 'sr_RS.UTF-8@latin' to 'sr_CS.UTF-8@latin'
886 # updated 'sr_cs@latn' -> 'sr_RS.UTF-8@latin' to 'sr_CS.UTF-8@latin'
887 #
888 # SS 2014-10-01:
889 # Updated alias mapping with glibc 2.19 supported locales.
890 #
891 # SS 2018-05-05:
892 # Updated alias mapping with glibc 2.27 supported locales.
893 #
894 # These are the differences compared to the old mapping (Python 3.6.5
895 # and older):
896 #
897 # updated 'ca_es@valencia' -> 'ca_ES.ISO8859-15@valencia' to 'ca_ES.UTF-8@valencia'
898 # updated 'kk_kz' -> 'kk_KZ.RK1048' to 'kk_KZ.ptcp154'
899 # updated 'russian' -> 'ru_RU.ISO8859-5' to 'ru_RU.KOI8-R'
900
901 locale_alias = {
902 'a3': 'az_AZ.KOI8-C',
903 'a3_az': 'az_AZ.KOI8-C',
904 'a3_az.koic': 'az_AZ.KOI8-C',
905 'aa_dj': 'aa_DJ.ISO8859-1',
906 'aa_er': 'aa_ER.UTF-8',
907 'aa_et': 'aa_ET.UTF-8',
908 'af': 'af_ZA.ISO8859-1',
909 'af_za': 'af_ZA.ISO8859-1',
910 'agr_pe': 'agr_PE.UTF-8',
911 'ak_gh': 'ak_GH.UTF-8',
912 'am': 'am_ET.UTF-8',
913 'am_et': 'am_ET.UTF-8',
914 'american': 'en_US.ISO8859-1',
915 'an_es': 'an_ES.ISO8859-15',
916 'anp_in': 'anp_IN.UTF-8',
917 'ar': 'ar_AA.ISO8859-6',
918 'ar_aa': 'ar_AA.ISO8859-6',
919 'ar_ae': 'ar_AE.ISO8859-6',
920 'ar_bh': 'ar_BH.ISO8859-6',
921 'ar_dz': 'ar_DZ.ISO8859-6',
922 'ar_eg': 'ar_EG.ISO8859-6',
923 'ar_in': 'ar_IN.UTF-8',
924 'ar_iq': 'ar_IQ.ISO8859-6',
925 'ar_jo': 'ar_JO.ISO8859-6',
926 'ar_kw': 'ar_KW.ISO8859-6',
927 'ar_lb': 'ar_LB.ISO8859-6',
928 'ar_ly': 'ar_LY.ISO8859-6',
929 'ar_ma': 'ar_MA.ISO8859-6',
930 'ar_om': 'ar_OM.ISO8859-6',
931 'ar_qa': 'ar_QA.ISO8859-6',
932 'ar_sa': 'ar_SA.ISO8859-6',
933 'ar_sd': 'ar_SD.ISO8859-6',
934 'ar_ss': 'ar_SS.UTF-8',
935 'ar_sy': 'ar_SY.ISO8859-6',
936 'ar_tn': 'ar_TN.ISO8859-6',
937 'ar_ye': 'ar_YE.ISO8859-6',
938 'arabic': 'ar_AA.ISO8859-6',
939 'as': 'as_IN.UTF-8',
940 'as_in': 'as_IN.UTF-8',
941 'ast_es': 'ast_ES.ISO8859-15',
942 'ayc_pe': 'ayc_PE.UTF-8',
943 'az': 'az_AZ.ISO8859-9E',
944 'az_az': 'az_AZ.ISO8859-9E',
945 'az_az.iso88599e': 'az_AZ.ISO8859-9E',
946 'az_ir': 'az_IR.UTF-8',
947 'be': 'be_BY.CP1251',
948 'be@latin': 'be_BY.UTF-8@latin',
949 'be_bg.utf8': 'bg_BG.UTF-8',
950 'be_by': 'be_BY.CP1251',
951 'be_by@latin': 'be_BY.UTF-8@latin',
952 'bem_zm': 'bem_ZM.UTF-8',
953 'ber_dz': 'ber_DZ.UTF-8',
954 'ber_ma': 'ber_MA.UTF-8',
955 'bg': 'bg_BG.CP1251',
956 'bg_bg': 'bg_BG.CP1251',
957 'bhb_in.utf8': 'bhb_IN.UTF-8',
958 'bho_in': 'bho_IN.UTF-8',
959 'bho_np': 'bho_NP.UTF-8',
960 'bi_vu': 'bi_VU.UTF-8',
961 'bn_bd': 'bn_BD.UTF-8',
962 'bn_in': 'bn_IN.UTF-8',
963 'bo_cn': 'bo_CN.UTF-8',
964 'bo_in': 'bo_IN.UTF-8',
965 'bokmal': 'nb_NO.ISO8859-1',
966 'bokm\xe5l': 'nb_NO.ISO8859-1',
967 'br': 'br_FR.ISO8859-1',
968 'br_fr': 'br_FR.ISO8859-1',
969 'brx_in': 'brx_IN.UTF-8',
970 'bs': 'bs_BA.ISO8859-2',
971 'bs_ba': 'bs_BA.ISO8859-2',
972 'bulgarian': 'bg_BG.CP1251',
973 'byn_er': 'byn_ER.UTF-8',
974 'c': 'C',
975 'c-french': 'fr_CA.ISO8859-1',
976 'c.ascii': 'C',
977 'c.en': 'C',
978 'c.iso88591': 'en_US.ISO8859-1',
979 'c.utf8': 'en_US.UTF-8',
980 'c_c': 'C',
981 'c_c.c': 'C',
982 'ca': 'ca_ES.ISO8859-1',
983 'ca_ad': 'ca_AD.ISO8859-1',
984 'ca_es': 'ca_ES.ISO8859-1',
985 'ca_es@valencia': 'ca_ES.UTF-8@valencia',
986 'ca_fr': 'ca_FR.ISO8859-1',
987 'ca_it': 'ca_IT.ISO8859-1',
988 'catalan': 'ca_ES.ISO8859-1',
989 'ce_ru': 'ce_RU.UTF-8',
990 'cextend': 'en_US.ISO8859-1',
991 'chinese-s': 'zh_CN.eucCN',
992 'chinese-t': 'zh_TW.eucTW',
993 'chr_us': 'chr_US.UTF-8',
994 'ckb_iq': 'ckb_IQ.UTF-8',
995 'cmn_tw': 'cmn_TW.UTF-8',
996 'crh_ua': 'crh_UA.UTF-8',
997 'croatian': 'hr_HR.ISO8859-2',
998 'cs': 'cs_CZ.ISO8859-2',
999 'cs_cs': 'cs_CZ.ISO8859-2',
1000 'cs_cz': 'cs_CZ.ISO8859-2',
1001 'csb_pl': 'csb_PL.UTF-8',
1002 'cv_ru': 'cv_RU.UTF-8',
1003 'cy': 'cy_GB.ISO8859-1',
1004 'cy_gb': 'cy_GB.ISO8859-1',
1005 'cz': 'cs_CZ.ISO8859-2',
1006 'cz_cz': 'cs_CZ.ISO8859-2',
1007 'czech': 'cs_CZ.ISO8859-2',
1008 'da': 'da_DK.ISO8859-1',
1009 'da_dk': 'da_DK.ISO8859-1',
1010 'danish': 'da_DK.ISO8859-1',
1011 'dansk': 'da_DK.ISO8859-1',
1012 'de': 'de_DE.ISO8859-1',
1013 'de_at': 'de_AT.ISO8859-1',
1014 'de_be': 'de_BE.ISO8859-1',
1015 'de_ch': 'de_CH.ISO8859-1',
1016 'de_de': 'de_DE.ISO8859-1',
1017 'de_it': 'de_IT.ISO8859-1',
1018 'de_li.utf8': 'de_LI.UTF-8',
1019 'de_lu': 'de_LU.ISO8859-1',
1020 'deutsch': 'de_DE.ISO8859-1',
1021 'doi_in': 'doi_IN.UTF-8',
1022 'dutch': 'nl_NL.ISO8859-1',
1023 'dutch.iso88591': 'nl_BE.ISO8859-1',
1024 'dv_mv': 'dv_MV.UTF-8',
1025 'dz_bt': 'dz_BT.UTF-8',
1026 'ee': 'ee_EE.ISO8859-4',
1027 'ee_ee': 'ee_EE.ISO8859-4',
1028 'eesti': 'et_EE.ISO8859-1',
1029 'el': 'el_GR.ISO8859-7',
1030 'el_cy': 'el_CY.ISO8859-7',
1031 'el_gr': 'el_GR.ISO8859-7',
1032 'el_gr@euro': 'el_GR.ISO8859-15',
1033 'en': 'en_US.ISO8859-1',
1034 'en_ag': 'en_AG.UTF-8',
1035 'en_au': 'en_AU.ISO8859-1',
1036 'en_be': 'en_BE.ISO8859-1',
1037 'en_bw': 'en_BW.ISO8859-1',
1038 'en_ca': 'en_CA.ISO8859-1',
1039 'en_dk': 'en_DK.ISO8859-1',
1040 'en_dl.utf8': 'en_DL.UTF-8',
1041 'en_gb': 'en_GB.ISO8859-1',
1042 'en_hk': 'en_HK.ISO8859-1',
1043 'en_ie': 'en_IE.ISO8859-1',
1044 'en_il': 'en_IL.UTF-8',
1045 'en_in': 'en_IN.ISO8859-1',
1046 'en_ng': 'en_NG.UTF-8',
1047 'en_nz': 'en_NZ.ISO8859-1',
1048 'en_ph': 'en_PH.ISO8859-1',
1049 'en_sc.utf8': 'en_SC.UTF-8',
1050 'en_sg': 'en_SG.ISO8859-1',
1051 'en_uk': 'en_GB.ISO8859-1',
1052 'en_us': 'en_US.ISO8859-1',
1053 'en_us@euro@euro': 'en_US.ISO8859-15',
1054 'en_za': 'en_ZA.ISO8859-1',
1055 'en_zm': 'en_ZM.UTF-8',
1056 'en_zw': 'en_ZW.ISO8859-1',
1057 'en_zw.utf8': 'en_ZS.UTF-8',
1058 'eng_gb': 'en_GB.ISO8859-1',
1059 'english': 'en_EN.ISO8859-1',
1060 'english.iso88591': 'en_US.ISO8859-1',
1061 'english_uk': 'en_GB.ISO8859-1',
1062 'english_united-states': 'en_US.ISO8859-1',
1063 'english_united-states.437': 'C',
1064 'english_us': 'en_US.ISO8859-1',
1065 'eo': 'eo_XX.ISO8859-3',
1066 'eo.utf8': 'eo.UTF-8',
1067 'eo_eo': 'eo_EO.ISO8859-3',
1068 'eo_us.utf8': 'eo_US.UTF-8',
1069 'eo_xx': 'eo_XX.ISO8859-3',
1070 'es': 'es_ES.ISO8859-1',
1071 'es_ar': 'es_AR.ISO8859-1',
1072 'es_bo': 'es_BO.ISO8859-1',
1073 'es_cl': 'es_CL.ISO8859-1',
1074 'es_co': 'es_CO.ISO8859-1',
1075 'es_cr': 'es_CR.ISO8859-1',
1076 'es_cu': 'es_CU.UTF-8',
1077 'es_do': 'es_DO.ISO8859-1',
1078 'es_ec': 'es_EC.ISO8859-1',
1079 'es_es': 'es_ES.ISO8859-1',
1080 'es_gt': 'es_GT.ISO8859-1',
1081 'es_hn': 'es_HN.ISO8859-1',
1082 'es_mx': 'es_MX.ISO8859-1',
1083 'es_ni': 'es_NI.ISO8859-1',
1084 'es_pa': 'es_PA.ISO8859-1',
1085 'es_pe': 'es_PE.ISO8859-1',
1086 'es_pr': 'es_PR.ISO8859-1',
1087 'es_py': 'es_PY.ISO8859-1',
1088 'es_sv': 'es_SV.ISO8859-1',
1089 'es_us': 'es_US.ISO8859-1',
1090 'es_uy': 'es_UY.ISO8859-1',
1091 'es_ve': 'es_VE.ISO8859-1',
1092 'estonian': 'et_EE.ISO8859-1',
1093 'et': 'et_EE.ISO8859-15',
1094 'et_ee': 'et_EE.ISO8859-15',
1095 'eu': 'eu_ES.ISO8859-1',
1096 'eu_es': 'eu_ES.ISO8859-1',
1097 'eu_fr': 'eu_FR.ISO8859-1',
1098 'fa': 'fa_IR.UTF-8',
1099 'fa_ir': 'fa_IR.UTF-8',
1100 'fa_ir.isiri3342': 'fa_IR.ISIRI-3342',
1101 'ff_sn': 'ff_SN.UTF-8',
1102 'fi': 'fi_FI.ISO8859-15',
1103 'fi_fi': 'fi_FI.ISO8859-15',
1104 'fil_ph': 'fil_PH.UTF-8',
1105 'finnish': 'fi_FI.ISO8859-1',
1106 'fo': 'fo_FO.ISO8859-1',
1107 'fo_fo': 'fo_FO.ISO8859-1',
1108 'fr': 'fr_FR.ISO8859-1',
1109 'fr_be': 'fr_BE.ISO8859-1',
1110 'fr_ca': 'fr_CA.ISO8859-1',
1111 'fr_ch': 'fr_CH.ISO8859-1',
1112 'fr_fr': 'fr_FR.ISO8859-1',
1113 'fr_lu': 'fr_LU.ISO8859-1',
1114 'fran\xe7ais': 'fr_FR.ISO8859-1',
1115 'fre_fr': 'fr_FR.ISO8859-1',
1116 'french': 'fr_FR.ISO8859-1',
1117 'french.iso88591': 'fr_CH.ISO8859-1',
1118 'french_france': 'fr_FR.ISO8859-1',
1119 'fur_it': 'fur_IT.UTF-8',
1120 'fy_de': 'fy_DE.UTF-8',
1121 'fy_nl': 'fy_NL.UTF-8',
1122 'ga': 'ga_IE.ISO8859-1',
1123 'ga_ie': 'ga_IE.ISO8859-1',
1124 'galego': 'gl_ES.ISO8859-1',
1125 'galician': 'gl_ES.ISO8859-1',
1126 'gd': 'gd_GB.ISO8859-1',
1127 'gd_gb': 'gd_GB.ISO8859-1',
1128 'ger_de': 'de_DE.ISO8859-1',
1129 'german': 'de_DE.ISO8859-1',
1130 'german.iso88591': 'de_CH.ISO8859-1',
1131 'german_germany': 'de_DE.ISO8859-1',
1132 'gez_er': 'gez_ER.UTF-8',
1133 'gez_et': 'gez_ET.UTF-8',
1134 'gl': 'gl_ES.ISO8859-1',
1135 'gl_es': 'gl_ES.ISO8859-1',
1136 'greek': 'el_GR.ISO8859-7',
1137 'gu_in': 'gu_IN.UTF-8',
1138 'gv': 'gv_GB.ISO8859-1',
1139 'gv_gb': 'gv_GB.ISO8859-1',
1140 'ha_ng': 'ha_NG.UTF-8',
1141 'hak_tw': 'hak_TW.UTF-8',
1142 'he': 'he_IL.ISO8859-8',
1143 'he_il': 'he_IL.ISO8859-8',
1144 'hebrew': 'he_IL.ISO8859-8',
1145 'hi': 'hi_IN.ISCII-DEV',
1146 'hi_in': 'hi_IN.ISCII-DEV',
1147 'hi_in.isciidev': 'hi_IN.ISCII-DEV',
1148 'hif_fj': 'hif_FJ.UTF-8',
1149 'hne': 'hne_IN.UTF-8',
1150 'hne_in': 'hne_IN.UTF-8',
1151 'hr': 'hr_HR.ISO8859-2',
1152 'hr_hr': 'hr_HR.ISO8859-2',
1153 'hrvatski': 'hr_HR.ISO8859-2',
1154 'hsb_de': 'hsb_DE.ISO8859-2',
1155 'ht_ht': 'ht_HT.UTF-8',
1156 'hu': 'hu_HU.ISO8859-2',
1157 'hu_hu': 'hu_HU.ISO8859-2',
1158 'hungarian': 'hu_HU.ISO8859-2',
1159 'hy_am': 'hy_AM.UTF-8',
1160 'hy_am.armscii8': 'hy_AM.ARMSCII_8',
1161 'ia': 'ia.UTF-8',
1162 'ia_fr': 'ia_FR.UTF-8',
1163 'icelandic': 'is_IS.ISO8859-1',
1164 'id': 'id_ID.ISO8859-1',
1165 'id_id': 'id_ID.ISO8859-1',
1166 'ig_ng': 'ig_NG.UTF-8',
1167 'ik_ca': 'ik_CA.UTF-8',
1168 'in': 'id_ID.ISO8859-1',
1169 'in_id': 'id_ID.ISO8859-1',
1170 'is': 'is_IS.ISO8859-1',
1171 'is_is': 'is_IS.ISO8859-1',
1172 'iso-8859-1': 'en_US.ISO8859-1',
1173 'iso-8859-15': 'en_US.ISO8859-15',
1174 'iso8859-1': 'en_US.ISO8859-1',
1175 'iso8859-15': 'en_US.ISO8859-15',
1176 'iso_8859_1': 'en_US.ISO8859-1',
1177 'iso_8859_15': 'en_US.ISO8859-15',
1178 'it': 'it_IT.ISO8859-1',
1179 'it_ch': 'it_CH.ISO8859-1',
1180 'it_it': 'it_IT.ISO8859-1',
1181 'italian': 'it_IT.ISO8859-1',
1182 'iu': 'iu_CA.NUNACOM-8',
1183 'iu_ca': 'iu_CA.NUNACOM-8',
1184 'iu_ca.nunacom8': 'iu_CA.NUNACOM-8',
1185 'iw': 'he_IL.ISO8859-8',
1186 'iw_il': 'he_IL.ISO8859-8',
1187 'iw_il.utf8': 'iw_IL.UTF-8',
1188 'ja': 'ja_JP.eucJP',
1189 'ja_jp': 'ja_JP.eucJP',
1190 'ja_jp.euc': 'ja_JP.eucJP',
1191 'ja_jp.mscode': 'ja_JP.SJIS',
1192 'ja_jp.pck': 'ja_JP.SJIS',
1193 'japan': 'ja_JP.eucJP',
1194 'japanese': 'ja_JP.eucJP',
1195 'japanese-euc': 'ja_JP.eucJP',
1196 'japanese.euc': 'ja_JP.eucJP',
1197 'jp_jp': 'ja_JP.eucJP',
1198 'ka': 'ka_GE.GEORGIAN-ACADEMY',
1199 'ka_ge': 'ka_GE.GEORGIAN-ACADEMY',
1200 'ka_ge.georgianacademy': 'ka_GE.GEORGIAN-ACADEMY',
1201 'ka_ge.georgianps': 'ka_GE.GEORGIAN-PS',
1202 'ka_ge.georgianrs': 'ka_GE.GEORGIAN-ACADEMY',
1203 'kab_dz': 'kab_DZ.UTF-8',
1204 'kk_kz': 'kk_KZ.ptcp154',
1205 'kl': 'kl_GL.ISO8859-1',
1206 'kl_gl': 'kl_GL.ISO8859-1',
1207 'km_kh': 'km_KH.UTF-8',
1208 'kn': 'kn_IN.UTF-8',
1209 'kn_in': 'kn_IN.UTF-8',
1210 'ko': 'ko_KR.eucKR',
1211 'ko_kr': 'ko_KR.eucKR',
1212 'ko_kr.euc': 'ko_KR.eucKR',
1213 'kok_in': 'kok_IN.UTF-8',
1214 'korean': 'ko_KR.eucKR',
1215 'korean.euc': 'ko_KR.eucKR',
1216 'ks': 'ks_IN.UTF-8',
1217 'ks_in': 'ks_IN.UTF-8',
1218 '[email protected]': 'ks_IN.UTF-8@devanagari',
1219 'ku_tr': 'ku_TR.ISO8859-9',
1220 'kw': 'kw_GB.ISO8859-1',
1221 'kw_gb': 'kw_GB.ISO8859-1',
1222 'ky': 'ky_KG.UTF-8',
1223 'ky_kg': 'ky_KG.UTF-8',
1224 'lb_lu': 'lb_LU.UTF-8',
1225 'lg_ug': 'lg_UG.ISO8859-10',
1226 'li_be': 'li_BE.UTF-8',
1227 'li_nl': 'li_NL.UTF-8',
1228 'lij_it': 'lij_IT.UTF-8',
1229 'lithuanian': 'lt_LT.ISO8859-13',
1230 'ln_cd': 'ln_CD.UTF-8',
1231 'lo': 'lo_LA.MULELAO-1',
1232 'lo_la': 'lo_LA.MULELAO-1',
1233 'lo_la.cp1133': 'lo_LA.IBM-CP1133',
1234 'lo_la.ibmcp1133': 'lo_LA.IBM-CP1133',
1235 'lo_la.mulelao1': 'lo_LA.MULELAO-1',
1236 'lt': 'lt_LT.ISO8859-13',
1237 'lt_lt': 'lt_LT.ISO8859-13',
1238 'lv': 'lv_LV.ISO8859-13',
1239 'lv_lv': 'lv_LV.ISO8859-13',
1240 'lzh_tw': 'lzh_TW.UTF-8',
1241 'mag_in': 'mag_IN.UTF-8',
1242 'mai': 'mai_IN.UTF-8',
1243 'mai_in': 'mai_IN.UTF-8',
1244 'mai_np': 'mai_NP.UTF-8',
1245 'mfe_mu': 'mfe_MU.UTF-8',
1246 'mg_mg': 'mg_MG.ISO8859-15',
1247 'mhr_ru': 'mhr_RU.UTF-8',
1248 'mi': 'mi_NZ.ISO8859-1',
1249 'mi_nz': 'mi_NZ.ISO8859-1',
1250 'miq_ni': 'miq_NI.UTF-8',
1251 'mjw_in': 'mjw_IN.UTF-8',
1252 'mk': 'mk_MK.ISO8859-5',
1253 'mk_mk': 'mk_MK.ISO8859-5',
1254 'ml': 'ml_IN.UTF-8',
1255 'ml_in': 'ml_IN.UTF-8',
1256 'mn_mn': 'mn_MN.UTF-8',
1257 'mni_in': 'mni_IN.UTF-8',
1258 'mr': 'mr_IN.UTF-8',
1259 'mr_in': 'mr_IN.UTF-8',
1260 'ms': 'ms_MY.ISO8859-1',
1261 'ms_my': 'ms_MY.ISO8859-1',
1262 'mt': 'mt_MT.ISO8859-3',
1263 'mt_mt': 'mt_MT.ISO8859-3',
1264 'my_mm': 'my_MM.UTF-8',
1265 'nan_tw': 'nan_TW.UTF-8',
1266 'nb': 'nb_NO.ISO8859-1',
1267 'nb_no': 'nb_NO.ISO8859-1',
1268 'nds_de': 'nds_DE.UTF-8',
1269 'nds_nl': 'nds_NL.UTF-8',
1270 'ne_np': 'ne_NP.UTF-8',
1271 'nhn_mx': 'nhn_MX.UTF-8',
1272 'niu_nu': 'niu_NU.UTF-8',
1273 'niu_nz': 'niu_NZ.UTF-8',
1274 'nl': 'nl_NL.ISO8859-1',
1275 'nl_aw': 'nl_AW.UTF-8',
1276 'nl_be': 'nl_BE.ISO8859-1',
1277 'nl_nl': 'nl_NL.ISO8859-1',
1278 'nn': 'nn_NO.ISO8859-1',
1279 'nn_no': 'nn_NO.ISO8859-1',
1280 'no': 'no_NO.ISO8859-1',
1281 'no@nynorsk': 'ny_NO.ISO8859-1',
1282 'no_no': 'no_NO.ISO8859-1',
1283 'no_no.iso88591@bokmal': 'no_NO.ISO8859-1',
1284 'no_no.iso88591@nynorsk': 'no_NO.ISO8859-1',
1285 'norwegian': 'no_NO.ISO8859-1',
1286 'nr': 'nr_ZA.ISO8859-1',
1287 'nr_za': 'nr_ZA.ISO8859-1',
1288 'nso': 'nso_ZA.ISO8859-15',
1289 'nso_za': 'nso_ZA.ISO8859-15',
1290 'ny': 'ny_NO.ISO8859-1',
1291 'ny_no': 'ny_NO.ISO8859-1',
1292 'nynorsk': 'nn_NO.ISO8859-1',
1293 'oc': 'oc_FR.ISO8859-1',
1294 'oc_fr': 'oc_FR.ISO8859-1',
1295 'om_et': 'om_ET.UTF-8',
1296 'om_ke': 'om_KE.ISO8859-1',
1297 'or': 'or_IN.UTF-8',
1298 'or_in': 'or_IN.UTF-8',
1299 'os_ru': 'os_RU.UTF-8',
1300 'pa': 'pa_IN.UTF-8',
1301 'pa_in': 'pa_IN.UTF-8',
1302 'pa_pk': 'pa_PK.UTF-8',
1303 'pap_an': 'pap_AN.UTF-8',
1304 'pap_aw': 'pap_AW.UTF-8',
1305 'pap_cw': 'pap_CW.UTF-8',
1306 'pd': 'pd_US.ISO8859-1',
1307 'pd_de': 'pd_DE.ISO8859-1',
1308 'pd_us': 'pd_US.ISO8859-1',
1309 'ph': 'ph_PH.ISO8859-1',
1310 'ph_ph': 'ph_PH.ISO8859-1',
1311 'pl': 'pl_PL.ISO8859-2',
1312 'pl_pl': 'pl_PL.ISO8859-2',
1313 'polish': 'pl_PL.ISO8859-2',
1314 'portuguese': 'pt_PT.ISO8859-1',
1315 'portuguese_brazil': 'pt_BR.ISO8859-1',
1316 'posix': 'C',
1317 'posix-utf2': 'C',
1318 'pp': 'pp_AN.ISO8859-1',
1319 'pp_an': 'pp_AN.ISO8859-1',
1320 'ps_af': 'ps_AF.UTF-8',
1321 'pt': 'pt_PT.ISO8859-1',
1322 'pt_br': 'pt_BR.ISO8859-1',
1323 'pt_pt': 'pt_PT.ISO8859-1',
1324 'quz_pe': 'quz_PE.UTF-8',
1325 'raj_in': 'raj_IN.UTF-8',
1326 'ro': 'ro_RO.ISO8859-2',
1327 'ro_ro': 'ro_RO.ISO8859-2',
1328 'romanian': 'ro_RO.ISO8859-2',
1329 'ru': 'ru_RU.UTF-8',
1330 'ru_ru': 'ru_RU.UTF-8',
1331 'ru_ua': 'ru_UA.KOI8-U',
1332 'rumanian': 'ro_RO.ISO8859-2',
1333 'russian': 'ru_RU.KOI8-R',
1334 'rw': 'rw_RW.ISO8859-1',
1335 'rw_rw': 'rw_RW.ISO8859-1',
1336 'sa_in': 'sa_IN.UTF-8',
1337 'sat_in': 'sat_IN.UTF-8',
1338 'sc_it': 'sc_IT.UTF-8',
1339 'sd': 'sd_IN.UTF-8',
1340 'sd_in': 'sd_IN.UTF-8',
1341 '[email protected]': 'sd_IN.UTF-8@devanagari',
1342 'sd_pk': 'sd_PK.UTF-8',
1343 'se_no': 'se_NO.UTF-8',
1344 'serbocroatian': 'sr_RS.UTF-8@latin',
1345 'sgs_lt': 'sgs_LT.UTF-8',
1346 'sh': 'sr_RS.UTF-8@latin',
1347 'sh_ba.iso88592@bosnia': 'sr_CS.ISO8859-2',
1348 'sh_hr': 'sh_HR.ISO8859-2',
1349 'sh_hr.iso88592': 'hr_HR.ISO8859-2',
1350 'sh_sp': 'sr_CS.ISO8859-2',
1351 'sh_yu': 'sr_RS.UTF-8@latin',
1352 'shn_mm': 'shn_MM.UTF-8',
1353 'shs_ca': 'shs_CA.UTF-8',
1354 'si': 'si_LK.UTF-8',
1355 'si_lk': 'si_LK.UTF-8',
1356 'sid_et': 'sid_ET.UTF-8',
1357 'sinhala': 'si_LK.UTF-8',
1358 'sk': 'sk_SK.ISO8859-2',
1359 'sk_sk': 'sk_SK.ISO8859-2',
1360 'sl': 'sl_SI.ISO8859-2',
1361 'sl_cs': 'sl_CS.ISO8859-2',
1362 'sl_si': 'sl_SI.ISO8859-2',
1363 'slovak': 'sk_SK.ISO8859-2',
1364 'slovene': 'sl_SI.ISO8859-2',
1365 'slovenian': 'sl_SI.ISO8859-2',
1366 'sm_ws': 'sm_WS.UTF-8',
1367 'so_dj': 'so_DJ.ISO8859-1',
1368 'so_et': 'so_ET.UTF-8',
1369 'so_ke': 'so_KE.ISO8859-1',
1370 'so_so': 'so_SO.ISO8859-1',
1371 'sp': 'sr_CS.ISO8859-5',
1372 'sp_yu': 'sr_CS.ISO8859-5',
1373 'spanish': 'es_ES.ISO8859-1',
1374 'spanish_spain': 'es_ES.ISO8859-1',
1375 'sq': 'sq_AL.ISO8859-2',
1376 'sq_al': 'sq_AL.ISO8859-2',
1377 'sq_mk': 'sq_MK.UTF-8',
1378 'sr': 'sr_RS.UTF-8',
1379 'sr@cyrillic': 'sr_RS.UTF-8',
1380 'sr@latn': 'sr_CS.UTF-8@latin',
1381 'sr_cs': 'sr_CS.UTF-8',
1382 'sr_cs.iso88592@latn': 'sr_CS.ISO8859-2',
1383 'sr_cs@latn': 'sr_CS.UTF-8@latin',
1384 'sr_me': 'sr_ME.UTF-8',
1385 'sr_rs': 'sr_RS.UTF-8',
1386 'sr_rs@latn': 'sr_RS.UTF-8@latin',
1387 'sr_sp': 'sr_CS.ISO8859-2',
1388 'sr_yu': 'sr_RS.UTF-8@latin',
1389 'sr_yu.cp1251@cyrillic': 'sr_CS.CP1251',
1390 'sr_yu.iso88592': 'sr_CS.ISO8859-2',
1391 'sr_yu.iso88595': 'sr_CS.ISO8859-5',
1392 'sr_yu.iso88595@cyrillic': 'sr_CS.ISO8859-5',
1393 'sr_yu.microsoftcp1251@cyrillic': 'sr_CS.CP1251',
1394 'sr_yu.utf8': 'sr_RS.UTF-8',
1395 'sr_yu.utf8@cyrillic': 'sr_RS.UTF-8',
1396 'sr_yu@cyrillic': 'sr_RS.UTF-8',
1397 'ss': 'ss_ZA.ISO8859-1',
1398 'ss_za': 'ss_ZA.ISO8859-1',
1399 'st': 'st_ZA.ISO8859-1',
1400 'st_za': 'st_ZA.ISO8859-1',
1401 'sv': 'sv_SE.ISO8859-1',
1402 'sv_fi': 'sv_FI.ISO8859-1',
1403 'sv_se': 'sv_SE.ISO8859-1',
1404 'sw_ke': 'sw_KE.UTF-8',
1405 'sw_tz': 'sw_TZ.UTF-8',
1406 'swedish': 'sv_SE.ISO8859-1',
1407 'szl_pl': 'szl_PL.UTF-8',
1408 'ta': 'ta_IN.TSCII-0',
1409 'ta_in': 'ta_IN.TSCII-0',
1410 'ta_in.tscii': 'ta_IN.TSCII-0',
1411 'ta_in.tscii0': 'ta_IN.TSCII-0',
1412 'ta_lk': 'ta_LK.UTF-8',
1413 'tcy_in.utf8': 'tcy_IN.UTF-8',
1414 'te': 'te_IN.UTF-8',
1415 'te_in': 'te_IN.UTF-8',
1416 'tg': 'tg_TJ.KOI8-C',
1417 'tg_tj': 'tg_TJ.KOI8-C',
1418 'th': 'th_TH.ISO8859-11',
1419 'th_th': 'th_TH.ISO8859-11',
1420 'th_th.tactis': 'th_TH.TIS620',
1421 'th_th.tis620': 'th_TH.TIS620',
1422 'thai': 'th_TH.ISO8859-11',
1423 'the_np': 'the_NP.UTF-8',
1424 'ti_er': 'ti_ER.UTF-8',
1425 'ti_et': 'ti_ET.UTF-8',
1426 'tig_er': 'tig_ER.UTF-8',
1427 'tk_tm': 'tk_TM.UTF-8',
1428 'tl': 'tl_PH.ISO8859-1',
1429 'tl_ph': 'tl_PH.ISO8859-1',
1430 'tn': 'tn_ZA.ISO8859-15',
1431 'tn_za': 'tn_ZA.ISO8859-15',
1432 'to_to': 'to_TO.UTF-8',
1433 'tpi_pg': 'tpi_PG.UTF-8',
1434 'tr': 'tr_TR.ISO8859-9',
1435 'tr_cy': 'tr_CY.ISO8859-9',
1436 'tr_tr': 'tr_TR.ISO8859-9',
1437 'ts': 'ts_ZA.ISO8859-1',
1438 'ts_za': 'ts_ZA.ISO8859-1',
1439 'tt': 'tt_RU.TATAR-CYR',
1440 'tt_ru': 'tt_RU.TATAR-CYR',
1441 'tt_ru.tatarcyr': 'tt_RU.TATAR-CYR',
1442 'tt_ru@iqtelif': 'tt_RU.UTF-8@iqtelif',
1443 'turkish': 'tr_TR.ISO8859-9',
1444 'ug_cn': 'ug_CN.UTF-8',
1445 'uk': 'uk_UA.KOI8-U',
1446 'uk_ua': 'uk_UA.KOI8-U',
1447 'univ': 'en_US.utf',
1448 'universal': 'en_US.utf',
1449 'universal.utf8@ucs4': 'en_US.UTF-8',
1450 'unm_us': 'unm_US.UTF-8',
1451 'ur': 'ur_PK.CP1256',
1452 'ur_in': 'ur_IN.UTF-8',
1453 'ur_pk': 'ur_PK.CP1256',
1454 'uz': 'uz_UZ.UTF-8',
1455 'uz_uz': 'uz_UZ.UTF-8',
1456 'uz_uz@cyrillic': 'uz_UZ.UTF-8',
1457 've': 've_ZA.UTF-8',
1458 've_za': 've_ZA.UTF-8',
1459 'vi': 'vi_VN.TCVN',
1460 'vi_vn': 'vi_VN.TCVN',
1461 'vi_vn.tcvn': 'vi_VN.TCVN',
1462 'vi_vn.tcvn5712': 'vi_VN.TCVN',
1463 'vi_vn.viscii': 'vi_VN.VISCII',
1464 'vi_vn.viscii111': 'vi_VN.VISCII',
1465 'wa': 'wa_BE.ISO8859-1',
1466 'wa_be': 'wa_BE.ISO8859-1',
1467 'wae_ch': 'wae_CH.UTF-8',
1468 'wal_et': 'wal_ET.UTF-8',
1469 'wo_sn': 'wo_SN.UTF-8',
1470 'xh': 'xh_ZA.ISO8859-1',
1471 'xh_za': 'xh_ZA.ISO8859-1',
1472 'yi': 'yi_US.CP1255',
1473 'yi_us': 'yi_US.CP1255',
1474 'yo_ng': 'yo_NG.UTF-8',
1475 'yue_hk': 'yue_HK.UTF-8',
1476 'yuw_pg': 'yuw_PG.UTF-8',
1477 'zh': 'zh_CN.eucCN',
1478 'zh_cn': 'zh_CN.gb2312',
1479 'zh_cn.big5': 'zh_TW.big5',
1480 'zh_cn.euc': 'zh_CN.eucCN',
1481 'zh_hk': 'zh_HK.big5hkscs',
1482 'zh_hk.big5hk': 'zh_HK.big5hkscs',
1483 'zh_sg': 'zh_SG.GB2312',
1484 'zh_sg.gbk': 'zh_SG.GBK',
1485 'zh_tw': 'zh_TW.big5',
1486 'zh_tw.euc': 'zh_TW.eucTW',
1487 'zh_tw.euctw': 'zh_TW.eucTW',
1488 'zu': 'zu_ZA.ISO8859-1',
1489 'zu_za': 'zu_ZA.ISO8859-1',
1490 }
1491
1492 #
1493 # This maps Windows language identifiers to locale strings.
1494 #
1495 # This list has been updated from
1496 # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_238z.asp
1497 # to include every locale up to Windows Vista.
1498 #
1499 # NOTE: this mapping is incomplete. If your language is missing, please
1500 # submit a bug report to the Python bug tracker at http://bugs.python.org/
1501 # Make sure you include the missing language identifier and the suggested
1502 # locale code.
1503 #
1504
1505 windows_locale = {
1506 0x0436: "af_ZA", # Afrikaans
1507 0x041c: "sq_AL", # Albanian
1508 0x0484: "gsw_FR",# Alsatian - France
1509 0x045e: "am_ET", # Amharic - Ethiopia
1510 0x0401: "ar_SA", # Arabic - Saudi Arabia
1511 0x0801: "ar_IQ", # Arabic - Iraq
1512 0x0c01: "ar_EG", # Arabic - Egypt
1513 0x1001: "ar_LY", # Arabic - Libya
1514 0x1401: "ar_DZ", # Arabic - Algeria
1515 0x1801: "ar_MA", # Arabic - Morocco
1516 0x1c01: "ar_TN", # Arabic - Tunisia
1517 0x2001: "ar_OM", # Arabic - Oman
1518 0x2401: "ar_YE", # Arabic - Yemen
1519 0x2801: "ar_SY", # Arabic - Syria
1520 0x2c01: "ar_JO", # Arabic - Jordan
1521 0x3001: "ar_LB", # Arabic - Lebanon
1522 0x3401: "ar_KW", # Arabic - Kuwait
1523 0x3801: "ar_AE", # Arabic - United Arab Emirates
1524 0x3c01: "ar_BH", # Arabic - Bahrain
1525 0x4001: "ar_QA", # Arabic - Qatar
1526 0x042b: "hy_AM", # Armenian
1527 0x044d: "as_IN", # Assamese - India
1528 0x042c: "az_AZ", # Azeri - Latin
1529 0x082c: "az_AZ", # Azeri - Cyrillic
1530 0x046d: "ba_RU", # Bashkir
1531 0x042d: "eu_ES", # Basque - Russia
1532 0x0423: "be_BY", # Belarusian
1533 0x0445: "bn_IN", # Begali
1534 0x201a: "bs_BA", # Bosnian - Cyrillic
1535 0x141a: "bs_BA", # Bosnian - Latin
1536 0x047e: "br_FR", # Breton - France
1537 0x0402: "bg_BG", # Bulgarian
1538 # 0x0455: "my_MM", # Burmese - Not supported
1539 0x0403: "ca_ES", # Catalan
1540 0x0004: "zh_CHS",# Chinese - Simplified
1541 0x0404: "zh_TW", # Chinese - Taiwan
1542 0x0804: "zh_CN", # Chinese - PRC
1543 0x0c04: "zh_HK", # Chinese - Hong Kong S.A.R.
1544 0x1004: "zh_SG", # Chinese - Singapore
1545 0x1404: "zh_MO", # Chinese - Macao S.A.R.
1546 0x7c04: "zh_CHT",# Chinese - Traditional
1547 0x0483: "co_FR", # Corsican - France
1548 0x041a: "hr_HR", # Croatian
1549 0x101a: "hr_BA", # Croatian - Bosnia
1550 0x0405: "cs_CZ", # Czech
1551 0x0406: "da_DK", # Danish
1552 0x048c: "gbz_AF",# Dari - Afghanistan
1553 0x0465: "div_MV",# Divehi - Maldives
1554 0x0413: "nl_NL", # Dutch - The Netherlands
1555 0x0813: "nl_BE", # Dutch - Belgium
1556 0x0409: "en_US", # English - United States
1557 0x0809: "en_GB", # English - United Kingdom
1558 0x0c09: "en_AU", # English - Australia
1559 0x1009: "en_CA", # English - Canada
1560 0x1409: "en_NZ", # English - New Zealand
1561 0x1809: "en_IE", # English - Ireland
1562 0x1c09: "en_ZA", # English - South Africa
1563 0x2009: "en_JA", # English - Jamaica
1564 0x2409: "en_CB", # English - Caribbean
1565 0x2809: "en_BZ", # English - Belize
1566 0x2c09: "en_TT", # English - Trinidad
1567 0x3009: "en_ZW", # English - Zimbabwe
1568 0x3409: "en_PH", # English - Philippines
1569 0x4009: "en_IN", # English - India
1570 0x4409: "en_MY", # English - Malaysia
1571 0x4809: "en_IN", # English - Singapore
1572 0x0425: "et_EE", # Estonian
1573 0x0438: "fo_FO", # Faroese
1574 0x0464: "fil_PH",# Filipino
1575 0x040b: "fi_FI", # Finnish
1576 0x040c: "fr_FR", # French - France
1577 0x080c: "fr_BE", # French - Belgium
1578 0x0c0c: "fr_CA", # French - Canada
1579 0x100c: "fr_CH", # French - Switzerland
1580 0x140c: "fr_LU", # French - Luxembourg
1581 0x180c: "fr_MC", # French - Monaco
1582 0x0462: "fy_NL", # Frisian - Netherlands
1583 0x0456: "gl_ES", # Galician
1584 0x0437: "ka_GE", # Georgian
1585 0x0407: "de_DE", # German - Germany
1586 0x0807: "de_CH", # German - Switzerland
1587 0x0c07: "de_AT", # German - Austria
1588 0x1007: "de_LU", # German - Luxembourg
1589 0x1407: "de_LI", # German - Liechtenstein
1590 0x0408: "el_GR", # Greek
1591 0x046f: "kl_GL", # Greenlandic - Greenland
1592 0x0447: "gu_IN", # Gujarati
1593 0x0468: "ha_NG", # Hausa - Latin
1594 0x040d: "he_IL", # Hebrew
1595 0x0439: "hi_IN", # Hindi
1596 0x040e: "hu_HU", # Hungarian
1597 0x040f: "is_IS", # Icelandic
1598 0x0421: "id_ID", # Indonesian
1599 0x045d: "iu_CA", # Inuktitut - Syllabics
1600 0x085d: "iu_CA", # Inuktitut - Latin
1601 0x083c: "ga_IE", # Irish - Ireland
1602 0x0410: "it_IT", # Italian - Italy
1603 0x0810: "it_CH", # Italian - Switzerland
1604 0x0411: "ja_JP", # Japanese
1605 0x044b: "kn_IN", # Kannada - India
1606 0x043f: "kk_KZ", # Kazakh
1607 0x0453: "kh_KH", # Khmer - Cambodia
1608 0x0486: "qut_GT",# K'iche - Guatemala
1609 0x0487: "rw_RW", # Kinyarwanda - Rwanda
1610 0x0457: "kok_IN",# Konkani
1611 0x0412: "ko_KR", # Korean
1612 0x0440: "ky_KG", # Kyrgyz
1613 0x0454: "lo_LA", # Lao - Lao PDR
1614 0x0426: "lv_LV", # Latvian
1615 0x0427: "lt_LT", # Lithuanian
1616 0x082e: "dsb_DE",# Lower Sorbian - Germany
1617 0x046e: "lb_LU", # Luxembourgish
1618 0x042f: "mk_MK", # FYROM Macedonian
1619 0x043e: "ms_MY", # Malay - Malaysia
1620 0x083e: "ms_BN", # Malay - Brunei Darussalam
1621 0x044c: "ml_IN", # Malayalam - India
1622 0x043a: "mt_MT", # Maltese
1623 0x0481: "mi_NZ", # Maori
1624 0x047a: "arn_CL",# Mapudungun
1625 0x044e: "mr_IN", # Marathi
1626 0x047c: "moh_CA",# Mohawk - Canada
1627 0x0450: "mn_MN", # Mongolian - Cyrillic
1628 0x0850: "mn_CN", # Mongolian - PRC
1629 0x0461: "ne_NP", # Nepali
1630 0x0414: "nb_NO", # Norwegian - Bokmal
1631 0x0814: "nn_NO", # Norwegian - Nynorsk
1632 0x0482: "oc_FR", # Occitan - France
1633 0x0448: "or_IN", # Oriya - India
1634 0x0463: "ps_AF", # Pashto - Afghanistan
1635 0x0429: "fa_IR", # Persian
1636 0x0415: "pl_PL", # Polish
1637 0x0416: "pt_BR", # Portuguese - Brazil
1638 0x0816: "pt_PT", # Portuguese - Portugal
1639 0x0446: "pa_IN", # Punjabi
1640 0x046b: "quz_BO",# Quechua (Bolivia)
1641 0x086b: "quz_EC",# Quechua (Ecuador)
1642 0x0c6b: "quz_PE",# Quechua (Peru)
1643 0x0418: "ro_RO", # Romanian - Romania
1644 0x0417: "rm_CH", # Romansh
1645 0x0419: "ru_RU", # Russian
1646 0x243b: "smn_FI",# Sami Finland
1647 0x103b: "smj_NO",# Sami Norway
1648 0x143b: "smj_SE",# Sami Sweden
1649 0x043b: "se_NO", # Sami Northern Norway
1650 0x083b: "se_SE", # Sami Northern Sweden
1651 0x0c3b: "se_FI", # Sami Northern Finland
1652 0x203b: "sms_FI",# Sami Skolt
1653 0x183b: "sma_NO",# Sami Southern Norway
1654 0x1c3b: "sma_SE",# Sami Southern Sweden
1655 0x044f: "sa_IN", # Sanskrit
1656 0x0c1a: "sr_SP", # Serbian - Cyrillic
1657 0x1c1a: "sr_BA", # Serbian - Bosnia Cyrillic
1658 0x081a: "sr_SP", # Serbian - Latin
1659 0x181a: "sr_BA", # Serbian - Bosnia Latin
1660 0x045b: "si_LK", # Sinhala - Sri Lanka
1661 0x046c: "ns_ZA", # Northern Sotho
1662 0x0432: "tn_ZA", # Setswana - Southern Africa
1663 0x041b: "sk_SK", # Slovak
1664 0x0424: "sl_SI", # Slovenian
1665 0x040a: "es_ES", # Spanish - Spain
1666 0x080a: "es_MX", # Spanish - Mexico
1667 0x0c0a: "es_ES", # Spanish - Spain (Modern)
1668 0x100a: "es_GT", # Spanish - Guatemala
1669 0x140a: "es_CR", # Spanish - Costa Rica
1670 0x180a: "es_PA", # Spanish - Panama
1671 0x1c0a: "es_DO", # Spanish - Dominican Republic
1672 0x200a: "es_VE", # Spanish - Venezuela
1673 0x240a: "es_CO", # Spanish - Colombia
1674 0x280a: "es_PE", # Spanish - Peru
1675 0x2c0a: "es_AR", # Spanish - Argentina
1676 0x300a: "es_EC", # Spanish - Ecuador
1677 0x340a: "es_CL", # Spanish - Chile
1678 0x380a: "es_UR", # Spanish - Uruguay
1679 0x3c0a: "es_PY", # Spanish - Paraguay
1680 0x400a: "es_BO", # Spanish - Bolivia
1681 0x440a: "es_SV", # Spanish - El Salvador
1682 0x480a: "es_HN", # Spanish - Honduras
1683 0x4c0a: "es_NI", # Spanish - Nicaragua
1684 0x500a: "es_PR", # Spanish - Puerto Rico
1685 0x540a: "es_US", # Spanish - United States
1686 # 0x0430: "", # Sutu - Not supported
1687 0x0441: "sw_KE", # Swahili
1688 0x041d: "sv_SE", # Swedish - Sweden
1689 0x081d: "sv_FI", # Swedish - Finland
1690 0x045a: "syr_SY",# Syriac
1691 0x0428: "tg_TJ", # Tajik - Cyrillic
1692 0x085f: "tmz_DZ",# Tamazight - Latin
1693 0x0449: "ta_IN", # Tamil
1694 0x0444: "tt_RU", # Tatar
1695 0x044a: "te_IN", # Telugu
1696 0x041e: "th_TH", # Thai
1697 0x0851: "bo_BT", # Tibetan - Bhutan
1698 0x0451: "bo_CN", # Tibetan - PRC
1699 0x041f: "tr_TR", # Turkish
1700 0x0442: "tk_TM", # Turkmen - Cyrillic
1701 0x0480: "ug_CN", # Uighur - Arabic
1702 0x0422: "uk_UA", # Ukrainian
1703 0x042e: "wen_DE",# Upper Sorbian - Germany
1704 0x0420: "ur_PK", # Urdu
1705 0x0820: "ur_IN", # Urdu - India
1706 0x0443: "uz_UZ", # Uzbek - Latin
1707 0x0843: "uz_UZ", # Uzbek - Cyrillic
1708 0x042a: "vi_VN", # Vietnamese
1709 0x0452: "cy_GB", # Welsh
1710 0x0488: "wo_SN", # Wolof - Senegal
1711 0x0434: "xh_ZA", # Xhosa - South Africa
1712 0x0485: "sah_RU",# Yakut - Cyrillic
1713 0x0478: "ii_CN", # Yi - PRC
1714 0x046a: "yo_NG", # Yoruba - Nigeria
1715 0x0435: "zu_ZA", # Zulu
1716 }
1717
1718 def _print_locale():
1719
1720 """ Test function.
1721 """
1722 categories = {}
1723 def _init_categories(categories=categories):
1724 for k,v in globals().items():
1725 if k[:3] == 'LC_':
1726 categories[k] = v
1727 _init_categories()
1728 del categories['LC_ALL']
1729
1730 print('Locale defaults as determined by getdefaultlocale():')
1731 print('-'*72)
1732 lang, enc = getdefaultlocale()
1733 print('Language: ', lang or '(undefined)')
1734 print('Encoding: ', enc or '(undefined)')
1735 print()
1736
1737 print('Locale settings on startup:')
1738 print('-'*72)
1739 for name,category in categories.items():
1740 print(name, '...')
1741 lang, enc = getlocale(category)
1742 print(' Language: ', lang or '(undefined)')
1743 print(' Encoding: ', enc or '(undefined)')
1744 print()
1745
1746 print()
1747 print('Locale settings after calling resetlocale():')
1748 print('-'*72)
1749 resetlocale()
1750 for name,category in categories.items():
1751 print(name, '...')
1752 lang, enc = getlocale(category)
1753 print(' Language: ', lang or '(undefined)')
1754 print(' Encoding: ', enc or '(undefined)')
1755 print()
1756
1757 try:
1758 setlocale(LC_ALL, "")
1759 except:
1760 print('NOTE:')
1761 print('setlocale(LC_ALL, "") does not support the default locale')
1762 print('given in the OS environment variables.')
1763 else:
1764 print()
1765 print('Locale settings after calling setlocale(LC_ALL, ""):')
1766 print('-'*72)
1767 for name,category in categories.items():
1768 print(name, '...')
1769 lang, enc = getlocale(category)
1770 print(' Language: ', lang or '(undefined)')
1771 print(' Encoding: ', enc or '(undefined)')
1772 print()
1773
1774 ###
1775
1776 try:
1777 LC_MESSAGES
1778 except NameError:
1779 pass
1780 else:
1781 __all__.append("LC_MESSAGES")
1782
1783 if __name__=='__main__':
1784 print('Locale aliasing:')
1785 print()
1786 _print_locale()
1787 print()
1788 print('Number formatting:')
1789 print()
1790 _test()