blob: 448b018a618d53e1cfb7b70c726cc5d6c1ae6f83 [file] [log] [blame]
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001""" Locale support.
Guido van Rossum4b8c6ea2000-02-04 15:39:30 +00002
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00003 The module provides low-level access to the C lib's locale APIs
4 and adds high level number formatting APIs as well as a locale
5 aliasing engine to complement these.
6
7 The aliasing engine includes support for many commonly used locale
8 names and maps them to values suitable for passing to the C lib's
9 setlocale() function. It also includes default encodings for all
10 supported locale names.
11
12"""
13
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +000014import sys, encodings, encodings.aliases
Georg Brandl1a3284e2007-12-02 09:40:06 +000015from builtins import str as _builtin_str
Marc-André Lemburg5431bc32000-06-07 09:11:40 +000016
Fredrik Lundh6c86b992000-07-09 17:12:58 +000017# Try importing the _locale module.
18#
19# If this fails, fall back on a basic 'C' locale emulation.
Guido van Rossumeef1d4e1997-11-19 19:01:43 +000020
Tim Peters1baf8292001-01-24 10:13:46 +000021# Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before
22# trying the import. So __all__ is also fiddled at the end of the file.
Guido van Rossum360e4b82007-05-14 22:51:27 +000023__all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error",
24 "setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm",
25 "str", "atof", "atoi", "format", "format_string", "currency",
26 "normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
27 "LC_NUMERIC", "LC_ALL", "CHAR_MAX"]
Skip Montanaro17ab1232001-01-24 06:27:27 +000028
Marc-André Lemburg23481142000-06-08 17:49:41 +000029try:
Fredrik Lundh6c86b992000-07-09 17:12:58 +000030
Marc-André Lemburg23481142000-06-08 17:49:41 +000031 from _locale import *
32
33except ImportError:
34
Fredrik Lundh6c86b992000-07-09 17:12:58 +000035 # Locale emulation
36
Marc-André Lemburg23481142000-06-08 17:49:41 +000037 CHAR_MAX = 127
38 LC_ALL = 6
39 LC_COLLATE = 3
40 LC_CTYPE = 0
41 LC_MESSAGES = 5
42 LC_MONETARY = 4
43 LC_NUMERIC = 1
44 LC_TIME = 2
45 Error = ValueError
46
47 def localeconv():
Fredrik Lundh6c86b992000-07-09 17:12:58 +000048 """ localeconv() -> dict.
Marc-André Lemburg23481142000-06-08 17:49:41 +000049 Returns numeric and monetary locale-specific parameters.
50 """
51 # 'C' locale default values
52 return {'grouping': [127],
53 'currency_symbol': '',
54 'n_sign_posn': 127,
Fredrik Lundh6c86b992000-07-09 17:12:58 +000055 'p_cs_precedes': 127,
56 'n_cs_precedes': 127,
57 'mon_grouping': [],
Marc-André Lemburg23481142000-06-08 17:49:41 +000058 'n_sep_by_space': 127,
59 'decimal_point': '.',
60 'negative_sign': '',
61 'positive_sign': '',
Fredrik Lundh6c86b992000-07-09 17:12:58 +000062 'p_sep_by_space': 127,
Marc-André Lemburg23481142000-06-08 17:49:41 +000063 'int_curr_symbol': '',
Fredrik Lundh6c86b992000-07-09 17:12:58 +000064 'p_sign_posn': 127,
Marc-André Lemburg23481142000-06-08 17:49:41 +000065 'thousands_sep': '',
Fredrik Lundh6c86b992000-07-09 17:12:58 +000066 'mon_thousands_sep': '',
67 'frac_digits': 127,
Marc-André Lemburg23481142000-06-08 17:49:41 +000068 'mon_decimal_point': '',
69 'int_frac_digits': 127}
Fredrik Lundh6c86b992000-07-09 17:12:58 +000070
Marc-André Lemburg23481142000-06-08 17:49:41 +000071 def setlocale(category, value=None):
Fredrik Lundh6c86b992000-07-09 17:12:58 +000072 """ setlocale(integer,string=None) -> string.
Marc-André Lemburg23481142000-06-08 17:49:41 +000073 Activates/queries locale processing.
74 """
Martin v. Löwis103d6e72003-03-30 15:42:13 +000075 if value not in (None, '', 'C'):
Collin Winterce36ad82007-08-30 01:19:48 +000076 raise Error('_locale emulation only supports "C" locale')
Marc-André Lemburg23481142000-06-08 17:49:41 +000077 return 'C'
78
79 def strcoll(a,b):
Fredrik Lundh6c86b992000-07-09 17:12:58 +000080 """ strcoll(string,string) -> int.
Marc-André Lemburg23481142000-06-08 17:49:41 +000081 Compares two strings according to the locale.
82 """
83 return cmp(a,b)
84
85 def strxfrm(s):
Fredrik Lundh6c86b992000-07-09 17:12:58 +000086 """ strxfrm(string) -> string.
Marc-André Lemburg23481142000-06-08 17:49:41 +000087 Returns a string that behaves for cmp locale-aware.
88 """
89 return s
Marc-André Lemburg5431bc32000-06-07 09:11:40 +000090
91### Number formatting APIs
92
93# Author: Martin von Loewis
Thomas Wouters477c8d52006-05-27 19:21:47 +000094# improved by Georg Brandl
Guido van Rossumeef1d4e1997-11-19 19:01:43 +000095
96#perform the grouping from right to left
Thomas Wouters477c8d52006-05-27 19:21:47 +000097def _group(s, monetary=False):
98 conv = localeconv()
99 thousands_sep = conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
100 grouping = conv[monetary and 'mon_grouping' or 'grouping']
101 if not grouping:
102 return (s, 0)
103 result = ""
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000104 seps = 0
105 spaces = ""
106 if s[-1] == ' ':
107 sp = s.find(' ')
108 spaces = s[sp:]
109 s = s[:sp]
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000110 while s and grouping:
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000111 # if grouping is -1, we are done
Thomas Wouters477c8d52006-05-27 19:21:47 +0000112 if grouping[0] == CHAR_MAX:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000113 break
114 # 0: re-use last group ad infinitum
Thomas Wouters477c8d52006-05-27 19:21:47 +0000115 elif grouping[0] != 0:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000116 #process last group
Thomas Wouters477c8d52006-05-27 19:21:47 +0000117 group = grouping[0]
118 grouping = grouping[1:]
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000119 if result:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000120 result = s[-group:] + thousands_sep + result
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000121 seps += 1
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000122 else:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000123 result = s[-group:]
124 s = s[:-group]
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000125 if s and s[-1] not in "0123456789":
126 # the leading string is only spaces and signs
Thomas Wouters477c8d52006-05-27 19:21:47 +0000127 return s + result + spaces, seps
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000128 if not result:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000129 return s + spaces, seps
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000130 if s:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000131 result = s + thousands_sep + result
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000132 seps += 1
Thomas Wouters477c8d52006-05-27 19:21:47 +0000133 return result + spaces, seps
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000134
Thomas Wouters477c8d52006-05-27 19:21:47 +0000135def format(percent, value, grouping=False, monetary=False, *additional):
136 """Returns the locale-aware substitution of a %? specifier
137 (percent).
138
139 additional is for format strings which contain one or more
140 '*' modifiers."""
141 # this is only for one-percent-specifier strings and this should be checked
142 if percent[0] != '%':
143 raise ValueError("format() must be given exactly one %char "
144 "format specifier")
145 if additional:
146 formatted = percent % ((value,) + additional)
147 else:
148 formatted = percent % value
149 # floats and decimal ints need special action!
150 if percent[-1] in 'eEfFgG':
151 seps = 0
152 parts = formatted.split('.')
153 if grouping:
154 parts[0], seps = _group(parts[0], monetary=monetary)
155 decimal_point = localeconv()[monetary and 'mon_decimal_point'
156 or 'decimal_point']
157 formatted = decimal_point.join(parts)
158 while seps:
159 sp = formatted.find(' ')
160 if sp == -1: break
161 formatted = formatted[:sp] + formatted[sp+1:]
162 seps -= 1
163 elif percent[-1] in 'diu':
164 if grouping:
165 formatted = _group(formatted, monetary=monetary)[0]
166 return formatted
167
168import re, operator
169_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
170 r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
171
172def format_string(f, val, grouping=False):
173 """Formats a string in the same way that the % formatting would use,
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000174 but takes the current locale into account.
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000175 Grouping is applied if the third parameter is true."""
Thomas Wouters477c8d52006-05-27 19:21:47 +0000176 percents = list(_percent_re.finditer(f))
177 new_f = _percent_re.sub('%s', f)
178
179 if isinstance(val, tuple):
180 new_val = list(val)
181 i = 0
182 for perc in percents:
183 starcount = perc.group('modifiers').count('*')
184 new_val[i] = format(perc.group(), new_val[i], grouping, False, *new_val[i+1:i+1+starcount])
185 del new_val[i+1:i+1+starcount]
186 i += (1 + starcount)
187 val = tuple(new_val)
188 elif operator.isMappingType(val):
189 for perc in percents:
190 key = perc.group("key")
191 val[key] = format(perc.group(), val[key], grouping)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000192 else:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000193 # val is a single value
194 val = format(percents[0].group(), val, grouping)
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000195
Thomas Wouters477c8d52006-05-27 19:21:47 +0000196 return new_f % val
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000197
Thomas Wouters477c8d52006-05-27 19:21:47 +0000198def currency(val, symbol=True, grouping=False, international=False):
199 """Formats val according to the currency settings
200 in the current locale."""
201 conv = localeconv()
202
203 # check for illegal values
204 digits = conv[international and 'int_frac_digits' or 'frac_digits']
205 if digits == 127:
206 raise ValueError("Currency formatting is not possible using "
207 "the 'C' locale.")
208
209 s = format('%%.%if' % digits, abs(val), grouping, monetary=True)
210 # '<' and '>' are markers if the sign must be inserted between symbol and value
211 s = '<' + s + '>'
212
213 if symbol:
214 smb = conv[international and 'int_curr_symbol' or 'currency_symbol']
215 precedes = conv[val<0 and 'n_cs_precedes' or 'p_cs_precedes']
216 separated = conv[val<0 and 'n_sep_by_space' or 'p_sep_by_space']
217
218 if precedes:
219 s = smb + (separated and ' ' or '') + s
220 else:
221 s = s + (separated and ' ' or '') + smb
222
223 sign_pos = conv[val<0 and 'n_sign_posn' or 'p_sign_posn']
224 sign = conv[val<0 and 'negative_sign' or 'positive_sign']
225
226 if sign_pos == 0:
227 s = '(' + s + ')'
228 elif sign_pos == 1:
229 s = sign + s
230 elif sign_pos == 2:
231 s = s + sign
232 elif sign_pos == 3:
233 s = s.replace('<', sign)
234 elif sign_pos == 4:
235 s = s.replace('>', sign)
236 else:
237 # the default if nothing specified;
238 # this should be the most fitting sign position
239 s = sign + s
240
241 return s.replace('<', '').replace('>', '')
Martin v. Löwisdb786872001-01-21 18:52:33 +0000242
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000243def str(val):
244 """Convert float to integer, taking the locale into account."""
Thomas Wouters477c8d52006-05-27 19:21:47 +0000245 return format("%.12g", val)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000246
Thomas Wouters477c8d52006-05-27 19:21:47 +0000247def atof(string, func=float):
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000248 "Parses a string as a float according to the locale settings."
249 #First, get rid of the grouping
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000250 ts = localeconv()['thousands_sep']
251 if ts:
Skip Montanaro249369c2004-04-10 16:39:32 +0000252 string = string.replace(ts, '')
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000253 #next, replace the decimal point with a dot
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000254 dd = localeconv()['decimal_point']
255 if dd:
Skip Montanaro249369c2004-04-10 16:39:32 +0000256 string = string.replace(dd, '.')
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000257 #finally, parse the string
Skip Montanaro249369c2004-04-10 16:39:32 +0000258 return func(string)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000259
260def atoi(str):
261 "Converts a string to an integer according to the locale settings."
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000262 return atof(str, int)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000263
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000264def _test():
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000265 setlocale(LC_ALL, "")
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000266 #do grouping
Thomas Wouters477c8d52006-05-27 19:21:47 +0000267 s1 = format("%d", 123456789,1)
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000268 print(s1, "is", atoi(s1))
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000269 #standard formatting
Thomas Wouters477c8d52006-05-27 19:21:47 +0000270 s1 = str(3.14)
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000271 print(s1, "is", atof(s1))
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000272
273### Locale name aliasing engine
274
275# Author: Marc-Andre Lemburg, mal@lemburg.com
Fredrik Lundh37a09822002-10-19 20:19:10 +0000276# Various tweaks by Fredrik Lundh <fredrik@pythonware.com>
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000277
278# store away the low-level version of setlocale (it's
279# overridden below)
280_setlocale = setlocale
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000281
282def normalize(localename):
283
284 """ Returns a normalized locale code for the given locale
285 name.
286
287 The returned locale code is formatted for use with
288 setlocale().
289
290 If normalization fails, the original name is returned
291 unchanged.
292
293 If the given encoding is not known, the function defaults to
294 the default encoding for the locale code just like setlocale()
295 does.
296
297 """
298 # Normalize the locale name and extract the encoding
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000299 fullname = localename.lower()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000300 if ':' in fullname:
301 # ':' is sometimes used as encoding delimiter.
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000302 fullname = fullname.replace(':', '.')
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000303 if '.' in fullname:
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000304 langname, encoding = fullname.split('.')[:2]
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000305 fullname = langname + '.' + encoding
306 else:
307 langname = fullname
308 encoding = ''
309
310 # First lookup: fullname (possibly with encoding)
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000311 norm_encoding = encoding.replace('-', '')
312 norm_encoding = norm_encoding.replace('_', '')
313 lookup_name = langname + '.' + encoding
314 code = locale_alias.get(lookup_name, None)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000315 if code is not None:
316 return code
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000317 #print 'first lookup failed'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000318
319 # Second try: langname (without encoding)
320 code = locale_alias.get(langname, None)
321 if code is not None:
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000322 #print 'langname lookup succeeded'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000323 if '.' in code:
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000324 langname, defenc = code.split('.')
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000325 else:
326 langname = code
327 defenc = ''
328 if encoding:
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000329 # Convert the encoding to a C lib compatible encoding string
330 norm_encoding = encodings.normalize_encoding(encoding)
331 #print 'norm encoding: %r' % norm_encoding
332 norm_encoding = encodings.aliases.aliases.get(norm_encoding,
333 norm_encoding)
334 #print 'aliased encoding: %r' % norm_encoding
335 encoding = locale_encoding_alias.get(norm_encoding,
336 norm_encoding)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000337 else:
338 encoding = defenc
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000339 #print 'found encoding %r' % encoding
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000340 if encoding:
341 return langname + '.' + encoding
342 else:
343 return langname
344
345 else:
346 return localename
347
348def _parse_localename(localename):
349
350 """ Parses the locale code for localename and returns the
351 result as tuple (language code, encoding).
352
353 The localename is normalized and passed through the locale
354 alias engine. A ValueError is raised in case the locale name
355 cannot be parsed.
356
357 The language code corresponds to RFC 1766. code and encoding
358 can be None in case the values cannot be determined or are
Jeremy Hyltona05e2932000-06-28 14:48:01 +0000359 unknown to this implementation.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000360
361 """
362 code = normalize(localename)
Georg Brandlb709c2c2006-01-20 09:07:35 +0000363 if '@' in code:
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000364 # Deal with locale modifiers
365 code, modifier = code.split('@')
366 if modifier == 'euro' and '.' not in code:
367 # Assume Latin-9 for @euro locales. This is bogus,
368 # since some systems may use other encodings for these
369 # locales. Also, we ignore other modifiers.
370 return code, 'iso-8859-15'
Tim Peters230a60c2002-11-09 05:08:07 +0000371
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000372 if '.' in code:
Raymond Hettinger346e67f2005-01-01 06:10:26 +0000373 return tuple(code.split('.')[:2])
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000374 elif code == 'C':
375 return None, None
Collin Winterce36ad82007-08-30 01:19:48 +0000376 raise ValueError('unknown locale: %s' % localename)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000377
378def _build_localename(localetuple):
379
380 """ Builds a locale code from the given tuple (language code,
381 encoding).
382
383 No aliasing or normalizing takes place.
384
385 """
386 language, encoding = localetuple
387 if language is None:
388 language = 'C'
389 if encoding is None:
390 return language
391 else:
392 return language + '.' + encoding
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000393
Matthias Klosef3f231f2005-09-20 07:02:49 +0000394def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000395
396 """ Tries to determine the default locale settings and returns
397 them as tuple (language code, encoding).
398
399 According to POSIX, a program which has not called
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000400 setlocale(LC_ALL, "") runs using the portable 'C' locale.
401 Calling setlocale(LC_ALL, "") lets it use the default locale as
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000402 defined by the LANG variable. Since we don't want to interfere
Thomas Wouters7e474022000-07-16 12:04:32 +0000403 with the current locale setting we thus emulate the behavior
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000404 in the way described above.
405
406 To maintain compatibility with other platforms, not only the
407 LANG variable is tested, but a list of variables given as
408 envvars parameter. The first found to be defined will be
409 used. envvars defaults to the search path used in GNU gettext;
410 it must always contain the variable name 'LANG'.
411
412 Except for the code 'C', the language code corresponds to RFC
413 1766. code and encoding can be None in case the values cannot
414 be determined.
415
416 """
Fredrik Lundh04661322000-07-09 23:16:10 +0000417
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000418 try:
419 # check if it's supported by the _locale module
420 import _locale
421 code, encoding = _locale._getdefaultlocale()
Fredrik Lundh04661322000-07-09 23:16:10 +0000422 except (ImportError, AttributeError):
423 pass
424 else:
Fredrik Lundh663809e2000-07-10 19:32:19 +0000425 # make sure the code/encoding values are valid
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000426 if sys.platform == "win32" and code and code[:2] == "0x":
427 # map windows language identifier to language name
428 code = windows_locale.get(int(code, 0))
Fredrik Lundh663809e2000-07-10 19:32:19 +0000429 # ...add other platform-specific processing here, if
430 # necessary...
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000431 return code, encoding
Fredrik Lundh04661322000-07-09 23:16:10 +0000432
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000433 # fall back on POSIX behaviour
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000434 import os
435 lookup = os.environ.get
436 for variable in envvars:
437 localename = lookup(variable,None)
Martin v. Löwisc8ae31d2004-07-26 12:45:18 +0000438 if localename:
Matthias Klosef3f231f2005-09-20 07:02:49 +0000439 if variable == 'LANGUAGE':
440 localename = localename.split(':')[0]
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000441 break
442 else:
443 localename = 'C'
444 return _parse_localename(localename)
445
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000446
447def getlocale(category=LC_CTYPE):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000448
449 """ Returns the current setting for the given locale category as
450 tuple (language code, encoding).
451
452 category may be one of the LC_* value except LC_ALL. It
453 defaults to LC_CTYPE.
454
455 Except for the code 'C', the language code corresponds to RFC
456 1766. code and encoding can be None in case the values cannot
457 be determined.
458
459 """
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000460 localename = _setlocale(category)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000461 if category == LC_ALL and ';' in localename:
Collin Winterce36ad82007-08-30 01:19:48 +0000462 raise TypeError('category LC_ALL is not supported')
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000463 return _parse_localename(localename)
464
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000465def setlocale(category, locale=None):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000466
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000467 """ Set the locale for the given category. The locale can be
468 a string, a locale tuple (language code, encoding), or None.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000469
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000470 Locale tuples are converted to strings the locale aliasing
471 engine. Locale strings are passed directly to the C lib.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000472
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000473 category may be given as one of the LC_* values.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000474
475 """
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000476 if locale and not isinstance(locale, _builtin_str):
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000477 # convert to string
478 locale = normalize(_build_localename(locale))
479 return _setlocale(category, locale)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000480
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000481def resetlocale(category=LC_ALL):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000482
483 """ Sets the locale for category to the default setting.
484
485 The default setting is determined by calling
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000486 getdefaultlocale(). category defaults to LC_ALL.
487
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000488 """
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000489 _setlocale(category, _build_localename(getdefaultlocale()))
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000490
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000491if sys.platform in ('win32', 'darwin', 'mac'):
492 # On Win32, this will return the ANSI code page
493 # On the Mac, it should return the system encoding;
494 # it might return "ascii" instead
495 def getpreferredencoding(do_setlocale = True):
496 """Return the charset that the user is likely using."""
497 import _locale
Tim Petersa326f472002-11-05 03:49:09 +0000498 return _locale._getdefaultlocale()[1]
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000499else:
500 # On Unix, if CODESET is available, use that.
501 try:
502 CODESET
503 except NameError:
504 # Fall back to parsing environment variables :-(
505 def getpreferredencoding(do_setlocale = True):
506 """Return the charset that the user is likely using,
507 by looking at environment variables."""
Martin v. Löwis071ef772008-03-08 11:24:24 +0000508 res = getdefaultlocale()[1]
509 if res is None:
510 # LANG not set, default conservatively to ASCII
511 res = 'ascii'
512 return res
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000513 else:
514 def getpreferredencoding(do_setlocale = True):
515 """Return the charset that the user is likely using,
516 according to the system configuration."""
517 if do_setlocale:
518 oldloc = setlocale(LC_CTYPE)
519 setlocale(LC_CTYPE, "")
520 result = nl_langinfo(CODESET)
521 setlocale(LC_CTYPE, oldloc)
522 return result
523 else:
524 return nl_langinfo(CODESET)
Tim Peters230a60c2002-11-09 05:08:07 +0000525
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000526
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000527### Database
528#
529# The following data was extracted from the locale.alias file which
530# comes with X11 and then hand edited removing the explicit encoding
531# definitions and adding some more aliases. The file is usually
532# available as /usr/lib/X11/locale/locale.alias.
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000533#
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000534
535#
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000536# The local_encoding_alias table maps lowercase encoding alias names
537# to C locale encoding names (case-sensitive). Note that normalize()
538# first looks up the encoding in the encodings.aliases dictionary and
539# then applies this mapping to find the correct C lib name for the
540# encoding.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000541#
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000542locale_encoding_alias = {
543
544 # Mappings for non-standard encoding names used in locale names
545 '437': 'C',
546 'c': 'C',
547 'en': 'ISO8859-1',
548 'jis': 'JIS7',
549 'jis7': 'JIS7',
550 'ajec': 'eucJP',
551
552 # Mappings from Python codec names to C lib encoding names
553 'ascii': 'ISO8859-1',
554 'latin_1': 'ISO8859-1',
555 'iso8859_1': 'ISO8859-1',
556 'iso8859_10': 'ISO8859-10',
557 'iso8859_11': 'ISO8859-11',
558 'iso8859_13': 'ISO8859-13',
559 'iso8859_14': 'ISO8859-14',
560 'iso8859_15': 'ISO8859-15',
561 'iso8859_2': 'ISO8859-2',
562 'iso8859_3': 'ISO8859-3',
563 'iso8859_4': 'ISO8859-4',
564 'iso8859_5': 'ISO8859-5',
565 'iso8859_6': 'ISO8859-6',
566 'iso8859_7': 'ISO8859-7',
567 'iso8859_8': 'ISO8859-8',
568 'iso8859_9': 'ISO8859-9',
569 'iso2022_jp': 'JIS7',
570 'shift_jis': 'SJIS',
571 'tactis': 'TACTIS',
572 'euc_jp': 'eucJP',
573 'euc_kr': 'eucKR',
Marc-André Lemburgb4cebd42004-12-13 19:56:01 +0000574 'utf_8': 'UTF8',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000575 'koi8_r': 'KOI8-R',
576 'koi8_u': 'KOI8-U',
577 # XXX This list is still incomplete. If you know more
578 # mappings, please file a bug report. Thanks.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000579}
580
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000581#
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000582# The locale_alias table maps lowercase alias names to C locale names
583# (case-sensitive). Encodings are always separated from the locale
584# name using a dot ('.'); they should only be given in case the
585# language name is needed to interpret the given encoding alias
586# correctly (CJK codes often have this need).
587#
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000588# Note that the normalize() function which uses this tables
589# removes '_' and '-' characters from the encoding part of the
590# locale name before doing the lookup. This saves a lot of
591# space in the table.
592#
593# MAL 2004-12-10:
594# Updated alias mapping to most recent locale.alias file
595# from X.org distribution using makelocalealias.py.
596#
597# These are the differences compared to the old mapping (Python 2.4
598# and older):
599#
600# updated 'bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
601# updated 'bg_bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
602# updated 'bulgarian' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
603# updated 'cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
604# updated 'cz_cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
605# updated 'czech' -> 'cs_CS.ISO8859-2' to 'cs_CZ.ISO8859-2'
606# updated 'dutch' -> 'nl_BE.ISO8859-1' to 'nl_NL.ISO8859-1'
607# updated 'et' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
608# updated 'et_ee' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
609# updated 'fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
610# updated 'fi_fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
611# updated 'iw' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
612# updated 'iw_il' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
613# updated 'japanese' -> 'ja_JP.SJIS' to 'ja_JP.eucJP'
614# updated 'lt' -> 'lt_LT.ISO8859-4' to 'lt_LT.ISO8859-13'
615# updated 'lv' -> 'lv_LV.ISO8859-4' to 'lv_LV.ISO8859-13'
616# updated 'sl' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
617# updated 'slovene' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
618# updated 'th_th' -> 'th_TH.TACTIS' to 'th_TH.ISO8859-11'
619# updated 'zh_cn' -> 'zh_CN.eucCN' to 'zh_CN.gb2312'
620# updated 'zh_cn.big5' -> 'zh_TW.eucTW' to 'zh_TW.big5'
621# updated 'zh_tw' -> 'zh_TW.eucTW' to 'zh_TW.big5'
622#
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000623locale_alias = {
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000624 'a3': 'a3_AZ.KOI8-C',
625 'a3_az': 'a3_AZ.KOI8-C',
626 'a3_az.koi8c': 'a3_AZ.KOI8-C',
627 'af': 'af_ZA.ISO8859-1',
628 'af_za': 'af_ZA.ISO8859-1',
629 'af_za.iso88591': 'af_ZA.ISO8859-1',
630 'am': 'am_ET.UTF-8',
631 'american': 'en_US.ISO8859-1',
632 'american.iso88591': 'en_US.ISO8859-1',
633 'ar': 'ar_AA.ISO8859-6',
634 'ar_aa': 'ar_AA.ISO8859-6',
635 'ar_aa.iso88596': 'ar_AA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000636 'ar_ae': 'ar_AE.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000637 'ar_bh': 'ar_BH.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000638 'ar_dz': 'ar_DZ.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000639 'ar_eg': 'ar_EG.ISO8859-6',
640 'ar_eg.iso88596': 'ar_EG.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000641 'ar_iq': 'ar_IQ.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000642 'ar_jo': 'ar_JO.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000643 'ar_kw': 'ar_KW.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000644 'ar_lb': 'ar_LB.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000645 'ar_ly': 'ar_LY.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000646 'ar_ma': 'ar_MA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000647 'ar_om': 'ar_OM.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000648 'ar_qa': 'ar_QA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000649 'ar_sa': 'ar_SA.ISO8859-6',
650 'ar_sa.iso88596': 'ar_SA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000651 'ar_sd': 'ar_SD.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000652 'ar_sy': 'ar_SY.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000653 'ar_tn': 'ar_TN.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000654 'ar_ye': 'ar_YE.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000655 'arabic': 'ar_AA.ISO8859-6',
656 'arabic.iso88596': 'ar_AA.ISO8859-6',
657 'az': 'az_AZ.ISO8859-9E',
658 'az_az': 'az_AZ.ISO8859-9E',
659 'az_az.iso88599e': 'az_AZ.ISO8859-9E',
660 'be': 'be_BY.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000661 'be_by': 'be_BY.CP1251',
662 'be_by.cp1251': 'be_BY.CP1251',
663 'be_by.microsoftcp1251': 'be_BY.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000664 'bg': 'bg_BG.CP1251',
665 'bg_bg': 'bg_BG.CP1251',
666 'bg_bg.cp1251': 'bg_BG.CP1251',
667 'bg_bg.iso88595': 'bg_BG.ISO8859-5',
668 'bg_bg.koi8r': 'bg_BG.KOI8-R',
669 'bg_bg.microsoftcp1251': 'bg_BG.CP1251',
670 'bokmal': 'nb_NO.ISO8859-1',
671 'bokm\xe5l': 'nb_NO.ISO8859-1',
672 'br': 'br_FR.ISO8859-1',
673 'br_fr': 'br_FR.ISO8859-1',
674 'br_fr.iso88591': 'br_FR.ISO8859-1',
675 'br_fr.iso885914': 'br_FR.ISO8859-14',
676 'br_fr.iso885915': 'br_FR.ISO8859-15',
677 'br_fr@euro': 'br_FR.ISO8859-15',
678 'bulgarian': 'bg_BG.CP1251',
679 'c': 'C',
680 'c-french': 'fr_CA.ISO8859-1',
681 'c-french.iso88591': 'fr_CA.ISO8859-1',
682 'c.en': 'C',
683 'c.iso88591': 'en_US.ISO8859-1',
684 'c_c': 'C',
685 'c_c.c': 'C',
686 'ca': 'ca_ES.ISO8859-1',
687 'ca_es': 'ca_ES.ISO8859-1',
688 'ca_es.iso88591': 'ca_ES.ISO8859-1',
689 'ca_es.iso885915': 'ca_ES.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000690 'ca_es@euro': 'ca_ES.ISO8859-15',
691 'catalan': 'ca_ES.ISO8859-1',
692 'cextend': 'en_US.ISO8859-1',
693 'cextend.en': 'en_US.ISO8859-1',
694 'chinese-s': 'zh_CN.eucCN',
695 'chinese-t': 'zh_TW.eucTW',
696 'croatian': 'hr_HR.ISO8859-2',
697 'cs': 'cs_CZ.ISO8859-2',
698 'cs_cs': 'cs_CZ.ISO8859-2',
699 'cs_cs.iso88592': 'cs_CZ.ISO8859-2',
700 'cs_cz': 'cs_CZ.ISO8859-2',
701 'cs_cz.iso88592': 'cs_CZ.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000702 'cy': 'cy_GB.ISO8859-1',
703 'cy_gb': 'cy_GB.ISO8859-1',
704 'cy_gb.iso88591': 'cy_GB.ISO8859-1',
705 'cy_gb.iso885914': 'cy_GB.ISO8859-14',
706 'cy_gb.iso885915': 'cy_GB.ISO8859-15',
707 'cy_gb@euro': 'cy_GB.ISO8859-15',
708 'cz': 'cs_CZ.ISO8859-2',
709 'cz_cz': 'cs_CZ.ISO8859-2',
710 'czech': 'cs_CZ.ISO8859-2',
711 'da': 'da_DK.ISO8859-1',
712 'da_dk': 'da_DK.ISO8859-1',
713 'da_dk.88591': 'da_DK.ISO8859-1',
714 'da_dk.885915': 'da_DK.ISO8859-15',
715 'da_dk.iso88591': 'da_DK.ISO8859-1',
716 'da_dk.iso885915': 'da_DK.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000717 'da_dk@euro': 'da_DK.ISO8859-15',
718 'danish': 'da_DK.ISO8859-1',
719 'danish.iso88591': 'da_DK.ISO8859-1',
720 'dansk': 'da_DK.ISO8859-1',
721 'de': 'de_DE.ISO8859-1',
722 'de_at': 'de_AT.ISO8859-1',
723 'de_at.iso88591': 'de_AT.ISO8859-1',
724 'de_at.iso885915': 'de_AT.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000725 'de_at@euro': 'de_AT.ISO8859-15',
726 'de_be': 'de_BE.ISO8859-1',
727 'de_be.iso88591': 'de_BE.ISO8859-1',
728 'de_be.iso885915': 'de_BE.ISO8859-15',
729 'de_be@euro': 'de_BE.ISO8859-15',
730 'de_ch': 'de_CH.ISO8859-1',
731 'de_ch.iso88591': 'de_CH.ISO8859-1',
732 'de_ch.iso885915': 'de_CH.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000733 'de_ch@euro': 'de_CH.ISO8859-15',
734 'de_de': 'de_DE.ISO8859-1',
735 'de_de.88591': 'de_DE.ISO8859-1',
736 'de_de.885915': 'de_DE.ISO8859-15',
737 'de_de.885915@euro': 'de_DE.ISO8859-15',
738 'de_de.iso88591': 'de_DE.ISO8859-1',
739 'de_de.iso885915': 'de_DE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000740 'de_de@euro': 'de_DE.ISO8859-15',
741 'de_lu': 'de_LU.ISO8859-1',
742 'de_lu.iso88591': 'de_LU.ISO8859-1',
743 'de_lu.iso885915': 'de_LU.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000744 'de_lu@euro': 'de_LU.ISO8859-15',
745 'deutsch': 'de_DE.ISO8859-1',
746 'dutch': 'nl_NL.ISO8859-1',
747 'dutch.iso88591': 'nl_BE.ISO8859-1',
748 'ee': 'ee_EE.ISO8859-4',
749 'ee_ee': 'ee_EE.ISO8859-4',
750 'ee_ee.iso88594': 'ee_EE.ISO8859-4',
751 'eesti': 'et_EE.ISO8859-1',
752 'el': 'el_GR.ISO8859-7',
753 'el_gr': 'el_GR.ISO8859-7',
754 'el_gr.iso88597': 'el_GR.ISO8859-7',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000755 'el_gr@euro': 'el_GR.ISO8859-15',
756 'en': 'en_US.ISO8859-1',
757 'en.iso88591': 'en_US.ISO8859-1',
758 'en_au': 'en_AU.ISO8859-1',
759 'en_au.iso88591': 'en_AU.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000760 'en_be': 'en_BE.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000761 'en_be@euro': 'en_BE.ISO8859-15',
762 'en_bw': 'en_BW.ISO8859-1',
763 'en_ca': 'en_CA.ISO8859-1',
764 'en_ca.iso88591': 'en_CA.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000765 'en_gb': 'en_GB.ISO8859-1',
766 'en_gb.88591': 'en_GB.ISO8859-1',
767 'en_gb.iso88591': 'en_GB.ISO8859-1',
768 'en_gb.iso885915': 'en_GB.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000769 'en_gb@euro': 'en_GB.ISO8859-15',
770 'en_hk': 'en_HK.ISO8859-1',
771 'en_ie': 'en_IE.ISO8859-1',
772 'en_ie.iso88591': 'en_IE.ISO8859-1',
773 'en_ie.iso885915': 'en_IE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000774 'en_ie@euro': 'en_IE.ISO8859-15',
775 'en_in': 'en_IN.ISO8859-1',
776 'en_nz': 'en_NZ.ISO8859-1',
777 'en_nz.iso88591': 'en_NZ.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000778 'en_ph': 'en_PH.ISO8859-1',
779 'en_sg': 'en_SG.ISO8859-1',
780 'en_uk': 'en_GB.ISO8859-1',
781 'en_us': 'en_US.ISO8859-1',
782 'en_us.88591': 'en_US.ISO8859-1',
783 'en_us.885915': 'en_US.ISO8859-15',
784 'en_us.iso88591': 'en_US.ISO8859-1',
785 'en_us.iso885915': 'en_US.ISO8859-15',
786 'en_us.iso885915@euro': 'en_US.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000787 'en_us@euro': 'en_US.ISO8859-15',
788 'en_us@euro@euro': 'en_US.ISO8859-15',
789 'en_za': 'en_ZA.ISO8859-1',
790 'en_za.88591': 'en_ZA.ISO8859-1',
791 'en_za.iso88591': 'en_ZA.ISO8859-1',
792 'en_za.iso885915': 'en_ZA.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000793 'en_za@euro': 'en_ZA.ISO8859-15',
794 'en_zw': 'en_ZW.ISO8859-1',
795 'eng_gb': 'en_GB.ISO8859-1',
796 'eng_gb.8859': 'en_GB.ISO8859-1',
797 'english': 'en_EN.ISO8859-1',
798 'english.iso88591': 'en_EN.ISO8859-1',
799 'english_uk': 'en_GB.ISO8859-1',
800 'english_uk.8859': 'en_GB.ISO8859-1',
801 'english_united-states': 'en_US.ISO8859-1',
802 'english_united-states.437': 'C',
803 'english_us': 'en_US.ISO8859-1',
804 'english_us.8859': 'en_US.ISO8859-1',
805 'english_us.ascii': 'en_US.ISO8859-1',
806 'eo': 'eo_XX.ISO8859-3',
807 'eo_eo': 'eo_EO.ISO8859-3',
808 'eo_eo.iso88593': 'eo_EO.ISO8859-3',
809 'eo_xx': 'eo_XX.ISO8859-3',
810 'eo_xx.iso88593': 'eo_XX.ISO8859-3',
811 'es': 'es_ES.ISO8859-1',
812 'es_ar': 'es_AR.ISO8859-1',
813 'es_ar.iso88591': 'es_AR.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000814 'es_bo': 'es_BO.ISO8859-1',
815 'es_bo.iso88591': 'es_BO.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000816 'es_cl': 'es_CL.ISO8859-1',
817 'es_cl.iso88591': 'es_CL.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000818 'es_co': 'es_CO.ISO8859-1',
819 'es_co.iso88591': 'es_CO.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000820 'es_cr': 'es_CR.ISO8859-1',
821 'es_cr.iso88591': 'es_CR.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000822 'es_do': 'es_DO.ISO8859-1',
823 'es_do.iso88591': 'es_DO.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000824 'es_ec': 'es_EC.ISO8859-1',
825 'es_ec.iso88591': 'es_EC.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000826 'es_es': 'es_ES.ISO8859-1',
827 'es_es.88591': 'es_ES.ISO8859-1',
828 'es_es.iso88591': 'es_ES.ISO8859-1',
829 'es_es.iso885915': 'es_ES.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000830 'es_es@euro': 'es_ES.ISO8859-15',
831 'es_gt': 'es_GT.ISO8859-1',
832 'es_gt.iso88591': 'es_GT.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000833 'es_hn': 'es_HN.ISO8859-1',
834 'es_hn.iso88591': 'es_HN.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000835 'es_mx': 'es_MX.ISO8859-1',
836 'es_mx.iso88591': 'es_MX.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000837 'es_ni': 'es_NI.ISO8859-1',
838 'es_ni.iso88591': 'es_NI.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000839 'es_pa': 'es_PA.ISO8859-1',
840 'es_pa.iso88591': 'es_PA.ISO8859-1',
841 'es_pa.iso885915': 'es_PA.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000842 'es_pa@euro': 'es_PA.ISO8859-15',
843 'es_pe': 'es_PE.ISO8859-1',
844 'es_pe.iso88591': 'es_PE.ISO8859-1',
845 'es_pe.iso885915': 'es_PE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000846 'es_pe@euro': 'es_PE.ISO8859-15',
847 'es_pr': 'es_PR.ISO8859-1',
848 'es_pr.iso88591': 'es_PR.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000849 'es_py': 'es_PY.ISO8859-1',
850 'es_py.iso88591': 'es_PY.ISO8859-1',
851 'es_py.iso885915': 'es_PY.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000852 'es_py@euro': 'es_PY.ISO8859-15',
853 'es_sv': 'es_SV.ISO8859-1',
854 'es_sv.iso88591': 'es_SV.ISO8859-1',
855 'es_sv.iso885915': 'es_SV.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000856 'es_sv@euro': 'es_SV.ISO8859-15',
857 'es_us': 'es_US.ISO8859-1',
858 'es_uy': 'es_UY.ISO8859-1',
859 'es_uy.iso88591': 'es_UY.ISO8859-1',
860 'es_uy.iso885915': 'es_UY.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000861 'es_uy@euro': 'es_UY.ISO8859-15',
862 'es_ve': 'es_VE.ISO8859-1',
863 'es_ve.iso88591': 'es_VE.ISO8859-1',
864 'es_ve.iso885915': 'es_VE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000865 'es_ve@euro': 'es_VE.ISO8859-15',
866 'estonian': 'et_EE.ISO8859-1',
867 'et': 'et_EE.ISO8859-15',
868 'et_ee': 'et_EE.ISO8859-15',
869 'et_ee.iso88591': 'et_EE.ISO8859-1',
870 'et_ee.iso885913': 'et_EE.ISO8859-13',
871 'et_ee.iso885915': 'et_EE.ISO8859-15',
872 'et_ee.iso88594': 'et_EE.ISO8859-4',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000873 'et_ee@euro': 'et_EE.ISO8859-15',
874 'eu': 'eu_ES.ISO8859-1',
875 'eu_es': 'eu_ES.ISO8859-1',
876 'eu_es.iso88591': 'eu_ES.ISO8859-1',
877 'eu_es.iso885915': 'eu_ES.ISO8859-15',
878 'eu_es@euro': 'eu_ES.ISO8859-15',
879 'fa': 'fa_IR.UTF-8',
880 'fa_ir': 'fa_IR.UTF-8',
881 'fa_ir.isiri3342': 'fa_IR.ISIRI-3342',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000882 'fi': 'fi_FI.ISO8859-15',
883 'fi_fi': 'fi_FI.ISO8859-15',
884 'fi_fi.88591': 'fi_FI.ISO8859-1',
885 'fi_fi.iso88591': 'fi_FI.ISO8859-1',
886 'fi_fi.iso885915': 'fi_FI.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000887 'fi_fi.utf8@euro': 'fi_FI.UTF-8',
888 'fi_fi@euro': 'fi_FI.ISO8859-15',
889 'finnish': 'fi_FI.ISO8859-1',
890 'finnish.iso88591': 'fi_FI.ISO8859-1',
891 'fo': 'fo_FO.ISO8859-1',
892 'fo_fo': 'fo_FO.ISO8859-1',
893 'fo_fo.iso88591': 'fo_FO.ISO8859-1',
894 'fo_fo.iso885915': 'fo_FO.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000895 'fo_fo@euro': 'fo_FO.ISO8859-15',
896 'fr': 'fr_FR.ISO8859-1',
897 'fr_be': 'fr_BE.ISO8859-1',
898 'fr_be.88591': 'fr_BE.ISO8859-1',
899 'fr_be.iso88591': 'fr_BE.ISO8859-1',
900 'fr_be.iso885915': 'fr_BE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000901 'fr_be@euro': 'fr_BE.ISO8859-15',
902 'fr_ca': 'fr_CA.ISO8859-1',
903 'fr_ca.88591': 'fr_CA.ISO8859-1',
904 'fr_ca.iso88591': 'fr_CA.ISO8859-1',
905 'fr_ca.iso885915': 'fr_CA.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000906 'fr_ca@euro': 'fr_CA.ISO8859-15',
907 'fr_ch': 'fr_CH.ISO8859-1',
908 'fr_ch.88591': 'fr_CH.ISO8859-1',
909 'fr_ch.iso88591': 'fr_CH.ISO8859-1',
910 'fr_ch.iso885915': 'fr_CH.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000911 'fr_ch@euro': 'fr_CH.ISO8859-15',
912 'fr_fr': 'fr_FR.ISO8859-1',
913 'fr_fr.88591': 'fr_FR.ISO8859-1',
914 'fr_fr.iso88591': 'fr_FR.ISO8859-1',
915 'fr_fr.iso885915': 'fr_FR.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000916 'fr_fr@euro': 'fr_FR.ISO8859-15',
917 'fr_lu': 'fr_LU.ISO8859-1',
918 'fr_lu.88591': 'fr_LU.ISO8859-1',
919 'fr_lu.iso88591': 'fr_LU.ISO8859-1',
920 'fr_lu.iso885915': 'fr_LU.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000921 'fr_lu@euro': 'fr_LU.ISO8859-15',
922 'fran\xe7ais': 'fr_FR.ISO8859-1',
923 'fre_fr': 'fr_FR.ISO8859-1',
924 'fre_fr.8859': 'fr_FR.ISO8859-1',
925 'french': 'fr_FR.ISO8859-1',
926 'french.iso88591': 'fr_CH.ISO8859-1',
927 'french_france': 'fr_FR.ISO8859-1',
928 'french_france.8859': 'fr_FR.ISO8859-1',
929 'ga': 'ga_IE.ISO8859-1',
930 'ga_ie': 'ga_IE.ISO8859-1',
931 'ga_ie.iso88591': 'ga_IE.ISO8859-1',
932 'ga_ie.iso885914': 'ga_IE.ISO8859-14',
933 'ga_ie.iso885915': 'ga_IE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000934 'ga_ie@euro': 'ga_IE.ISO8859-15',
935 'galego': 'gl_ES.ISO8859-1',
936 'galician': 'gl_ES.ISO8859-1',
937 'gd': 'gd_GB.ISO8859-1',
938 'gd_gb': 'gd_GB.ISO8859-1',
939 'gd_gb.iso88591': 'gd_GB.ISO8859-1',
940 'gd_gb.iso885914': 'gd_GB.ISO8859-14',
941 'gd_gb.iso885915': 'gd_GB.ISO8859-15',
942 'gd_gb@euro': 'gd_GB.ISO8859-15',
943 'ger_de': 'de_DE.ISO8859-1',
944 'ger_de.8859': 'de_DE.ISO8859-1',
945 'german': 'de_DE.ISO8859-1',
946 'german.iso88591': 'de_CH.ISO8859-1',
947 'german_germany': 'de_DE.ISO8859-1',
948 'german_germany.8859': 'de_DE.ISO8859-1',
949 'gl': 'gl_ES.ISO8859-1',
950 'gl_es': 'gl_ES.ISO8859-1',
951 'gl_es.iso88591': 'gl_ES.ISO8859-1',
952 'gl_es.iso885915': 'gl_ES.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000953 'gl_es@euro': 'gl_ES.ISO8859-15',
954 'greek': 'el_GR.ISO8859-7',
955 'greek.iso88597': 'el_GR.ISO8859-7',
956 'gv': 'gv_GB.ISO8859-1',
957 'gv_gb': 'gv_GB.ISO8859-1',
958 'gv_gb.iso88591': 'gv_GB.ISO8859-1',
959 'gv_gb.iso885914': 'gv_GB.ISO8859-14',
960 'gv_gb.iso885915': 'gv_GB.ISO8859-15',
961 'gv_gb@euro': 'gv_GB.ISO8859-15',
962 'he': 'he_IL.ISO8859-8',
963 'he_il': 'he_IL.ISO8859-8',
964 'he_il.cp1255': 'he_IL.CP1255',
965 'he_il.iso88598': 'he_IL.ISO8859-8',
966 'he_il.microsoftcp1255': 'he_IL.CP1255',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000967 'hebrew': 'iw_IL.ISO8859-8',
968 'hebrew.iso88598': 'iw_IL.ISO8859-8',
969 'hi': 'hi_IN.ISCII-DEV',
970 'hi_in': 'hi_IN.ISCII-DEV',
971 'hi_in.isciidev': 'hi_IN.ISCII-DEV',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000972 'hr': 'hr_HR.ISO8859-2',
973 'hr_hr': 'hr_HR.ISO8859-2',
974 'hr_hr.iso88592': 'hr_HR.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000975 'hrvatski': 'hr_HR.ISO8859-2',
976 'hu': 'hu_HU.ISO8859-2',
977 'hu_hu': 'hu_HU.ISO8859-2',
978 'hu_hu.iso88592': 'hu_HU.ISO8859-2',
979 'hungarian': 'hu_HU.ISO8859-2',
980 'icelandic': 'is_IS.ISO8859-1',
981 'icelandic.iso88591': 'is_IS.ISO8859-1',
982 'id': 'id_ID.ISO8859-1',
983 'id_id': 'id_ID.ISO8859-1',
984 'in': 'id_ID.ISO8859-1',
985 'in_id': 'id_ID.ISO8859-1',
986 'is': 'is_IS.ISO8859-1',
987 'is_is': 'is_IS.ISO8859-1',
988 'is_is.iso88591': 'is_IS.ISO8859-1',
989 'is_is.iso885915': 'is_IS.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000990 'is_is@euro': 'is_IS.ISO8859-15',
991 'iso-8859-1': 'en_US.ISO8859-1',
992 'iso-8859-15': 'en_US.ISO8859-15',
993 'iso8859-1': 'en_US.ISO8859-1',
994 'iso8859-15': 'en_US.ISO8859-15',
995 'iso_8859_1': 'en_US.ISO8859-1',
996 'iso_8859_15': 'en_US.ISO8859-15',
997 'it': 'it_IT.ISO8859-1',
998 'it_ch': 'it_CH.ISO8859-1',
999 'it_ch.iso88591': 'it_CH.ISO8859-1',
1000 'it_ch.iso885915': 'it_CH.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001001 'it_ch@euro': 'it_CH.ISO8859-15',
1002 'it_it': 'it_IT.ISO8859-1',
1003 'it_it.88591': 'it_IT.ISO8859-1',
1004 'it_it.iso88591': 'it_IT.ISO8859-1',
1005 'it_it.iso885915': 'it_IT.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001006 'it_it@euro': 'it_IT.ISO8859-15',
1007 'italian': 'it_IT.ISO8859-1',
1008 'italian.iso88591': 'it_IT.ISO8859-1',
1009 'iu': 'iu_CA.NUNACOM-8',
1010 'iu_ca': 'iu_CA.NUNACOM-8',
1011 'iu_ca.nunacom8': 'iu_CA.NUNACOM-8',
1012 'iw': 'he_IL.ISO8859-8',
1013 'iw_il': 'he_IL.ISO8859-8',
1014 'iw_il.iso88598': 'he_IL.ISO8859-8',
1015 'ja': 'ja_JP.eucJP',
1016 'ja.jis': 'ja_JP.JIS7',
1017 'ja.sjis': 'ja_JP.SJIS',
1018 'ja_jp': 'ja_JP.eucJP',
1019 'ja_jp.ajec': 'ja_JP.eucJP',
1020 'ja_jp.euc': 'ja_JP.eucJP',
1021 'ja_jp.eucjp': 'ja_JP.eucJP',
1022 'ja_jp.iso-2022-jp': 'ja_JP.JIS7',
1023 'ja_jp.iso2022jp': 'ja_JP.JIS7',
1024 'ja_jp.jis': 'ja_JP.JIS7',
1025 'ja_jp.jis7': 'ja_JP.JIS7',
1026 'ja_jp.mscode': 'ja_JP.SJIS',
1027 'ja_jp.sjis': 'ja_JP.SJIS',
1028 'ja_jp.ujis': 'ja_JP.eucJP',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001029 'japan': 'ja_JP.eucJP',
1030 'japanese': 'ja_JP.eucJP',
1031 'japanese-euc': 'ja_JP.eucJP',
1032 'japanese.euc': 'ja_JP.eucJP',
1033 'japanese.sjis': 'ja_JP.SJIS',
1034 'jp_jp': 'ja_JP.eucJP',
1035 'ka': 'ka_GE.GEORGIAN-ACADEMY',
1036 'ka_ge': 'ka_GE.GEORGIAN-ACADEMY',
1037 'ka_ge.georgianacademy': 'ka_GE.GEORGIAN-ACADEMY',
1038 'ka_ge.georgianps': 'ka_GE.GEORGIAN-PS',
1039 'ka_ge.georgianrs': 'ka_GE.GEORGIAN-ACADEMY',
1040 'kl': 'kl_GL.ISO8859-1',
1041 'kl_gl': 'kl_GL.ISO8859-1',
1042 'kl_gl.iso88591': 'kl_GL.ISO8859-1',
1043 'kl_gl.iso885915': 'kl_GL.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001044 'kl_gl@euro': 'kl_GL.ISO8859-15',
1045 'ko': 'ko_KR.eucKR',
1046 'ko_kr': 'ko_KR.eucKR',
1047 'ko_kr.euc': 'ko_KR.eucKR',
1048 'ko_kr.euckr': 'ko_KR.eucKR',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001049 'korean': 'ko_KR.eucKR',
1050 'korean.euc': 'ko_KR.eucKR',
1051 'kw': 'kw_GB.ISO8859-1',
1052 'kw_gb': 'kw_GB.ISO8859-1',
1053 'kw_gb.iso88591': 'kw_GB.ISO8859-1',
1054 'kw_gb.iso885914': 'kw_GB.ISO8859-14',
1055 'kw_gb.iso885915': 'kw_GB.ISO8859-15',
1056 'kw_gb@euro': 'kw_GB.ISO8859-15',
1057 'lithuanian': 'lt_LT.ISO8859-13',
1058 'lo': 'lo_LA.MULELAO-1',
1059 'lo_la': 'lo_LA.MULELAO-1',
1060 'lo_la.cp1133': 'lo_LA.IBM-CP1133',
1061 'lo_la.ibmcp1133': 'lo_LA.IBM-CP1133',
1062 'lo_la.mulelao1': 'lo_LA.MULELAO-1',
1063 'lt': 'lt_LT.ISO8859-13',
1064 'lt_lt': 'lt_LT.ISO8859-13',
1065 'lt_lt.iso885913': 'lt_LT.ISO8859-13',
1066 'lt_lt.iso88594': 'lt_LT.ISO8859-4',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001067 'lv': 'lv_LV.ISO8859-13',
1068 'lv_lv': 'lv_LV.ISO8859-13',
1069 'lv_lv.iso885913': 'lv_LV.ISO8859-13',
1070 'lv_lv.iso88594': 'lv_LV.ISO8859-4',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001071 'mi': 'mi_NZ.ISO8859-1',
1072 'mi_nz': 'mi_NZ.ISO8859-1',
1073 'mi_nz.iso88591': 'mi_NZ.ISO8859-1',
1074 'mk': 'mk_MK.ISO8859-5',
1075 'mk_mk': 'mk_MK.ISO8859-5',
1076 'mk_mk.cp1251': 'mk_MK.CP1251',
1077 'mk_mk.iso88595': 'mk_MK.ISO8859-5',
1078 'mk_mk.microsoftcp1251': 'mk_MK.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001079 'ms': 'ms_MY.ISO8859-1',
1080 'ms_my': 'ms_MY.ISO8859-1',
1081 'ms_my.iso88591': 'ms_MY.ISO8859-1',
1082 'mt': 'mt_MT.ISO8859-3',
1083 'mt_mt': 'mt_MT.ISO8859-3',
1084 'mt_mt.iso88593': 'mt_MT.ISO8859-3',
1085 'nb': 'nb_NO.ISO8859-1',
1086 'nb_no': 'nb_NO.ISO8859-1',
1087 'nb_no.88591': 'nb_NO.ISO8859-1',
1088 'nb_no.iso88591': 'nb_NO.ISO8859-1',
1089 'nb_no.iso885915': 'nb_NO.ISO8859-15',
1090 'nb_no@euro': 'nb_NO.ISO8859-15',
1091 'nl': 'nl_NL.ISO8859-1',
1092 'nl_be': 'nl_BE.ISO8859-1',
1093 'nl_be.88591': 'nl_BE.ISO8859-1',
1094 'nl_be.iso88591': 'nl_BE.ISO8859-1',
1095 'nl_be.iso885915': 'nl_BE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001096 'nl_be@euro': 'nl_BE.ISO8859-15',
1097 'nl_nl': 'nl_NL.ISO8859-1',
1098 'nl_nl.88591': 'nl_NL.ISO8859-1',
1099 'nl_nl.iso88591': 'nl_NL.ISO8859-1',
1100 'nl_nl.iso885915': 'nl_NL.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001101 'nl_nl@euro': 'nl_NL.ISO8859-15',
1102 'nn': 'nn_NO.ISO8859-1',
1103 'nn_no': 'nn_NO.ISO8859-1',
1104 'nn_no.88591': 'nn_NO.ISO8859-1',
1105 'nn_no.iso88591': 'nn_NO.ISO8859-1',
1106 'nn_no.iso885915': 'nn_NO.ISO8859-15',
1107 'nn_no@euro': 'nn_NO.ISO8859-15',
1108 'no': 'no_NO.ISO8859-1',
1109 'no@nynorsk': 'ny_NO.ISO8859-1',
1110 'no_no': 'no_NO.ISO8859-1',
1111 'no_no.88591': 'no_NO.ISO8859-1',
1112 'no_no.iso88591': 'no_NO.ISO8859-1',
1113 'no_no.iso885915': 'no_NO.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001114 'no_no@euro': 'no_NO.ISO8859-15',
1115 'norwegian': 'no_NO.ISO8859-1',
1116 'norwegian.iso88591': 'no_NO.ISO8859-1',
1117 'ny': 'ny_NO.ISO8859-1',
1118 'ny_no': 'ny_NO.ISO8859-1',
1119 'ny_no.88591': 'ny_NO.ISO8859-1',
1120 'ny_no.iso88591': 'ny_NO.ISO8859-1',
1121 'ny_no.iso885915': 'ny_NO.ISO8859-15',
1122 'ny_no@euro': 'ny_NO.ISO8859-15',
1123 'nynorsk': 'nn_NO.ISO8859-1',
1124 'oc': 'oc_FR.ISO8859-1',
1125 'oc_fr': 'oc_FR.ISO8859-1',
1126 'oc_fr.iso88591': 'oc_FR.ISO8859-1',
1127 'oc_fr.iso885915': 'oc_FR.ISO8859-15',
1128 'oc_fr@euro': 'oc_FR.ISO8859-15',
1129 'pd': 'pd_US.ISO8859-1',
1130 'pd_de': 'pd_DE.ISO8859-1',
1131 'pd_de.iso88591': 'pd_DE.ISO8859-1',
1132 'pd_de.iso885915': 'pd_DE.ISO8859-15',
1133 'pd_de@euro': 'pd_DE.ISO8859-15',
1134 'pd_us': 'pd_US.ISO8859-1',
1135 'pd_us.iso88591': 'pd_US.ISO8859-1',
1136 'pd_us.iso885915': 'pd_US.ISO8859-15',
1137 'pd_us@euro': 'pd_US.ISO8859-15',
1138 'ph': 'ph_PH.ISO8859-1',
1139 'ph_ph': 'ph_PH.ISO8859-1',
1140 'ph_ph.iso88591': 'ph_PH.ISO8859-1',
1141 'pl': 'pl_PL.ISO8859-2',
1142 'pl_pl': 'pl_PL.ISO8859-2',
1143 'pl_pl.iso88592': 'pl_PL.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001144 'polish': 'pl_PL.ISO8859-2',
1145 'portuguese': 'pt_PT.ISO8859-1',
1146 'portuguese.iso88591': 'pt_PT.ISO8859-1',
1147 'portuguese_brazil': 'pt_BR.ISO8859-1',
1148 'portuguese_brazil.8859': 'pt_BR.ISO8859-1',
1149 'posix': 'C',
1150 'posix-utf2': 'C',
1151 'pp': 'pp_AN.ISO8859-1',
1152 'pp_an': 'pp_AN.ISO8859-1',
1153 'pp_an.iso88591': 'pp_AN.ISO8859-1',
1154 'pt': 'pt_PT.ISO8859-1',
1155 'pt_br': 'pt_BR.ISO8859-1',
1156 'pt_br.88591': 'pt_BR.ISO8859-1',
1157 'pt_br.iso88591': 'pt_BR.ISO8859-1',
1158 'pt_br.iso885915': 'pt_BR.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001159 'pt_br@euro': 'pt_BR.ISO8859-15',
1160 'pt_pt': 'pt_PT.ISO8859-1',
1161 'pt_pt.88591': 'pt_PT.ISO8859-1',
1162 'pt_pt.iso88591': 'pt_PT.ISO8859-1',
1163 'pt_pt.iso885915': 'pt_PT.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001164 'pt_pt.utf8@euro': 'pt_PT.UTF-8',
1165 'pt_pt@euro': 'pt_PT.ISO8859-15',
1166 'ro': 'ro_RO.ISO8859-2',
1167 'ro_ro': 'ro_RO.ISO8859-2',
1168 'ro_ro.iso88592': 'ro_RO.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001169 'romanian': 'ro_RO.ISO8859-2',
1170 'ru': 'ru_RU.ISO8859-5',
1171 'ru_ru': 'ru_RU.ISO8859-5',
1172 'ru_ru.cp1251': 'ru_RU.CP1251',
1173 'ru_ru.iso88595': 'ru_RU.ISO8859-5',
1174 'ru_ru.koi8r': 'ru_RU.KOI8-R',
1175 'ru_ru.microsoftcp1251': 'ru_RU.CP1251',
1176 'ru_ua': 'ru_UA.KOI8-U',
1177 'ru_ua.cp1251': 'ru_UA.CP1251',
1178 'ru_ua.koi8u': 'ru_UA.KOI8-U',
1179 'ru_ua.microsoftcp1251': 'ru_UA.CP1251',
1180 'rumanian': 'ro_RO.ISO8859-2',
1181 'russian': 'ru_RU.ISO8859-5',
1182 'se_no': 'se_NO.UTF-8',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001183 'serbocroatian': 'sh_YU.ISO8859-2',
1184 'sh': 'sh_YU.ISO8859-2',
1185 'sh_hr': 'sh_HR.ISO8859-2',
1186 'sh_hr.iso88592': 'sh_HR.ISO8859-2',
1187 'sh_sp': 'sh_YU.ISO8859-2',
1188 'sh_yu': 'sh_YU.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001189 'sk': 'sk_SK.ISO8859-2',
1190 'sk_sk': 'sk_SK.ISO8859-2',
1191 'sk_sk.iso88592': 'sk_SK.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001192 'sl': 'sl_SI.ISO8859-2',
1193 'sl_cs': 'sl_CS.ISO8859-2',
1194 'sl_si': 'sl_SI.ISO8859-2',
1195 'sl_si.iso88592': 'sl_SI.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001196 'slovak': 'sk_SK.ISO8859-2',
1197 'slovene': 'sl_SI.ISO8859-2',
1198 'slovenian': 'sl_SI.ISO8859-2',
1199 'sp': 'sp_YU.ISO8859-5',
1200 'sp_yu': 'sp_YU.ISO8859-5',
1201 'spanish': 'es_ES.ISO8859-1',
1202 'spanish.iso88591': 'es_ES.ISO8859-1',
1203 'spanish_spain': 'es_ES.ISO8859-1',
1204 'spanish_spain.8859': 'es_ES.ISO8859-1',
1205 'sq': 'sq_AL.ISO8859-2',
1206 'sq_al': 'sq_AL.ISO8859-2',
1207 'sq_al.iso88592': 'sq_AL.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001208 'sr': 'sr_YU.ISO8859-5',
1209 'sr@cyrillic': 'sr_YU.ISO8859-5',
1210 'sr_sp': 'sr_SP.ISO8859-2',
1211 'sr_yu': 'sr_YU.ISO8859-5',
1212 'sr_yu.cp1251@cyrillic': 'sr_YU.CP1251',
1213 'sr_yu.iso88592': 'sr_YU.ISO8859-2',
1214 'sr_yu.iso88595': 'sr_YU.ISO8859-5',
1215 'sr_yu.iso88595@cyrillic': 'sr_YU.ISO8859-5',
1216 'sr_yu.microsoftcp1251@cyrillic': 'sr_YU.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001217 'sr_yu.utf8@cyrillic': 'sr_YU.UTF-8',
1218 'sr_yu@cyrillic': 'sr_YU.ISO8859-5',
1219 'sv': 'sv_SE.ISO8859-1',
1220 'sv_fi': 'sv_FI.ISO8859-1',
1221 'sv_fi.iso88591': 'sv_FI.ISO8859-1',
1222 'sv_fi.iso885915': 'sv_FI.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001223 'sv_fi@euro': 'sv_FI.ISO8859-15',
1224 'sv_se': 'sv_SE.ISO8859-1',
1225 'sv_se.88591': 'sv_SE.ISO8859-1',
1226 'sv_se.iso88591': 'sv_SE.ISO8859-1',
1227 'sv_se.iso885915': 'sv_SE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001228 'sv_se@euro': 'sv_SE.ISO8859-15',
1229 'swedish': 'sv_SE.ISO8859-1',
1230 'swedish.iso88591': 'sv_SE.ISO8859-1',
1231 'ta': 'ta_IN.TSCII-0',
1232 'ta_in': 'ta_IN.TSCII-0',
1233 'ta_in.tscii': 'ta_IN.TSCII-0',
1234 'ta_in.tscii0': 'ta_IN.TSCII-0',
1235 'tg': 'tg_TJ.KOI8-C',
1236 'tg_tj': 'tg_TJ.KOI8-C',
1237 'tg_tj.koi8c': 'tg_TJ.KOI8-C',
1238 'th': 'th_TH.ISO8859-11',
1239 'th_th': 'th_TH.ISO8859-11',
1240 'th_th.iso885911': 'th_TH.ISO8859-11',
1241 'th_th.tactis': 'th_TH.TIS620',
1242 'th_th.tis620': 'th_TH.TIS620',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001243 'thai': 'th_TH.ISO8859-11',
1244 'tl': 'tl_PH.ISO8859-1',
1245 'tl_ph': 'tl_PH.ISO8859-1',
1246 'tl_ph.iso88591': 'tl_PH.ISO8859-1',
1247 'tr': 'tr_TR.ISO8859-9',
1248 'tr_tr': 'tr_TR.ISO8859-9',
1249 'tr_tr.iso88599': 'tr_TR.ISO8859-9',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001250 'tt': 'tt_RU.TATAR-CYR',
1251 'tt_ru': 'tt_RU.TATAR-CYR',
1252 'tt_ru.koi8c': 'tt_RU.KOI8-C',
1253 'tt_ru.tatarcyr': 'tt_RU.TATAR-CYR',
1254 'turkish': 'tr_TR.ISO8859-9',
1255 'turkish.iso88599': 'tr_TR.ISO8859-9',
1256 'uk': 'uk_UA.KOI8-U',
1257 'uk_ua': 'uk_UA.KOI8-U',
1258 'uk_ua.cp1251': 'uk_UA.CP1251',
1259 'uk_ua.iso88595': 'uk_UA.ISO8859-5',
1260 'uk_ua.koi8u': 'uk_UA.KOI8-U',
1261 'uk_ua.microsoftcp1251': 'uk_UA.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001262 'univ': 'en_US.utf',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001263 'universal': 'en_US.utf',
1264 'universal.utf8@ucs4': 'en_US.UTF-8',
1265 'ur': 'ur_PK.CP1256',
1266 'ur_pk': 'ur_PK.CP1256',
1267 'ur_pk.cp1256': 'ur_PK.CP1256',
1268 'ur_pk.microsoftcp1256': 'ur_PK.CP1256',
1269 'uz': 'uz_UZ.UTF-8',
1270 'uz_uz': 'uz_UZ.UTF-8',
1271 'vi': 'vi_VN.TCVN',
1272 'vi_vn': 'vi_VN.TCVN',
1273 'vi_vn.tcvn': 'vi_VN.TCVN',
1274 'vi_vn.tcvn5712': 'vi_VN.TCVN',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001275 'vi_vn.viscii': 'vi_VN.VISCII',
1276 'vi_vn.viscii111': 'vi_VN.VISCII',
1277 'wa': 'wa_BE.ISO8859-1',
1278 'wa_be': 'wa_BE.ISO8859-1',
1279 'wa_be.iso88591': 'wa_BE.ISO8859-1',
1280 'wa_be.iso885915': 'wa_BE.ISO8859-15',
1281 'wa_be@euro': 'wa_BE.ISO8859-15',
1282 'yi': 'yi_US.CP1255',
1283 'yi_us': 'yi_US.CP1255',
1284 'yi_us.cp1255': 'yi_US.CP1255',
1285 'yi_us.microsoftcp1255': 'yi_US.CP1255',
1286 'zh': 'zh_CN.eucCN',
1287 'zh_cn': 'zh_CN.gb2312',
1288 'zh_cn.big5': 'zh_TW.big5',
1289 'zh_cn.euc': 'zh_CN.eucCN',
1290 'zh_cn.gb18030': 'zh_CN.gb18030',
1291 'zh_cn.gb2312': 'zh_CN.gb2312',
1292 'zh_cn.gbk': 'zh_CN.gbk',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001293 'zh_hk': 'zh_HK.big5hkscs',
1294 'zh_hk.big5': 'zh_HK.big5',
1295 'zh_hk.big5hkscs': 'zh_HK.big5hkscs',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001296 'zh_tw': 'zh_TW.big5',
1297 'zh_tw.big5': 'zh_TW.big5',
1298 'zh_tw.euc': 'zh_TW.eucTW',
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001299}
1300
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001301#
Georg Brandlb709c2c2006-01-20 09:07:35 +00001302# This maps Windows language identifiers to locale strings.
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001303#
Tim Peters777f1082006-01-20 20:03:24 +00001304# This list has been updated from
Georg Brandlb709c2c2006-01-20 09:07:35 +00001305# http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_238z.asp
1306# to include every locale up to Windows XP.
Fredrik Lundh37a09822002-10-19 20:19:10 +00001307#
Georg Brandl5035c1c2006-01-20 13:38:26 +00001308# NOTE: this mapping is incomplete. If your language is missing, please
1309# submit a bug report to Python bug manager, which you can find via:
1310# http://www.python.org/dev/
1311# Make sure you include the missing language identifier and the suggested
1312# locale code.
1313#
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001314
1315windows_locale = {
Georg Brandlb709c2c2006-01-20 09:07:35 +00001316 0x0436: "af_ZA", # Afrikaans
1317 0x041c: "sq_AL", # Albanian
1318 0x0401: "ar_SA", # Arabic - Saudi Arabia
1319 0x0801: "ar_IQ", # Arabic - Iraq
1320 0x0c01: "ar_EG", # Arabic - Egypt
1321 0x1001: "ar_LY", # Arabic - Libya
1322 0x1401: "ar_DZ", # Arabic - Algeria
1323 0x1801: "ar_MA", # Arabic - Morocco
1324 0x1c01: "ar_TN", # Arabic - Tunisia
1325 0x2001: "ar_OM", # Arabic - Oman
1326 0x2401: "ar_YE", # Arabic - Yemen
1327 0x2801: "ar_SY", # Arabic - Syria
1328 0x2c01: "ar_JO", # Arabic - Jordan
1329 0x3001: "ar_LB", # Arabic - Lebanon
1330 0x3401: "ar_KW", # Arabic - Kuwait
1331 0x3801: "ar_AE", # Arabic - United Arab Emirates
1332 0x3c01: "ar_BH", # Arabic - Bahrain
1333 0x4001: "ar_QA", # Arabic - Qatar
1334 0x042b: "hy_AM", # Armenian
1335 0x042c: "az_AZ", # Azeri Latin
1336 0x082c: "az_AZ", # Azeri - Cyrillic
1337 0x042d: "eu_ES", # Basque
1338 0x0423: "be_BY", # Belarusian
1339 0x0445: "bn_IN", # Begali
1340 0x201a: "bs_BA", # Bosnian
1341 0x141a: "bs_BA", # Bosnian - Cyrillic
1342 0x047e: "br_FR", # Breton - France
1343 0x0402: "bg_BG", # Bulgarian
1344 0x0403: "ca_ES", # Catalan
1345 0x0004: "zh_CHS",# Chinese - Simplified
1346 0x0404: "zh_TW", # Chinese - Taiwan
1347 0x0804: "zh_CN", # Chinese - PRC
1348 0x0c04: "zh_HK", # Chinese - Hong Kong S.A.R.
1349 0x1004: "zh_SG", # Chinese - Singapore
1350 0x1404: "zh_MO", # Chinese - Macao S.A.R.
1351 0x7c04: "zh_CHT",# Chinese - Traditional
1352 0x041a: "hr_HR", # Croatian
1353 0x101a: "hr_BA", # Croatian - Bosnia
1354 0x0405: "cs_CZ", # Czech
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001355 0x0406: "da_DK", # Danish
Georg Brandlb709c2c2006-01-20 09:07:35 +00001356 0x048c: "gbz_AF",# Dari - Afghanistan
1357 0x0465: "div_MV",# Divehi - Maldives
1358 0x0413: "nl_NL", # Dutch - The Netherlands
1359 0x0813: "nl_BE", # Dutch - Belgium
1360 0x0409: "en_US", # English - United States
1361 0x0809: "en_GB", # English - United Kingdom
1362 0x0c09: "en_AU", # English - Australia
1363 0x1009: "en_CA", # English - Canada
1364 0x1409: "en_NZ", # English - New Zealand
1365 0x1809: "en_IE", # English - Ireland
1366 0x1c09: "en_ZA", # English - South Africa
1367 0x2009: "en_JA", # English - Jamaica
1368 0x2409: "en_CB", # English - Carribbean
1369 0x2809: "en_BZ", # English - Belize
1370 0x2c09: "en_TT", # English - Trinidad
1371 0x3009: "en_ZW", # English - Zimbabwe
1372 0x3409: "en_PH", # English - Phillippines
1373 0x0425: "et_EE", # Estonian
1374 0x0438: "fo_FO", # Faroese
1375 0x0464: "fil_PH",# Filipino
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001376 0x040b: "fi_FI", # Finnish
Georg Brandlb709c2c2006-01-20 09:07:35 +00001377 0x040c: "fr_FR", # French - France
1378 0x080c: "fr_BE", # French - Belgium
1379 0x0c0c: "fr_CA", # French - Canada
1380 0x100c: "fr_CH", # French - Switzerland
1381 0x140c: "fr_LU", # French - Luxembourg
1382 0x180c: "fr_MC", # French - Monaco
1383 0x0462: "fy_NL", # Frisian - Netherlands
1384 0x0456: "gl_ES", # Galician
1385 0x0437: "ka_GE", # Georgian
1386 0x0407: "de_DE", # German - Germany
1387 0x0807: "de_CH", # German - Switzerland
1388 0x0c07: "de_AT", # German - Austria
1389 0x1007: "de_LU", # German - Luxembourg
1390 0x1407: "de_LI", # German - Liechtenstein
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001391 0x0408: "el_GR", # Greek
Georg Brandlb709c2c2006-01-20 09:07:35 +00001392 0x0447: "gu_IN", # Gujarati
1393 0x040d: "he_IL", # Hebrew
1394 0x0439: "hi_IN", # Hindi
1395 0x040e: "hu_HU", # Hungarian
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001396 0x040f: "is_IS", # Icelandic
Georg Brandlb709c2c2006-01-20 09:07:35 +00001397 0x0421: "id_ID", # Indonesian
1398 0x045d: "iu_CA", # Inuktitut
1399 0x085d: "iu_CA", # Inuktitut - Latin
1400 0x083c: "ga_IE", # Irish - Ireland
1401 0x0434: "xh_ZA", # Xhosa - South Africa
1402 0x0435: "zu_ZA", # Zulu
1403 0x0410: "it_IT", # Italian - Italy
1404 0x0810: "it_CH", # Italian - Switzerland
1405 0x0411: "ja_JP", # Japanese
1406 0x044b: "kn_IN", # Kannada - India
1407 0x043f: "kk_KZ", # Kazakh
1408 0x0457: "kok_IN",# Konkani
1409 0x0412: "ko_KR", # Korean
1410 0x0440: "ky_KG", # Kyrgyz
1411 0x0426: "lv_LV", # Latvian
1412 0x0427: "lt_LT", # Lithuanian
1413 0x046e: "lb_LU", # Luxembourgish
1414 0x042f: "mk_MK", # FYRO Macedonian
1415 0x043e: "ms_MY", # Malay - Malaysia
1416 0x083e: "ms_BN", # Malay - Brunei
1417 0x044c: "ml_IN", # Malayalam - India
1418 0x043a: "mt_MT", # Maltese
1419 0x0481: "mi_NZ", # Maori
1420 0x047a: "arn_CL",# Mapudungun
1421 0x044e: "mr_IN", # Marathi
1422 0x047c: "moh_CA",# Mohawk - Canada
1423 0x0450: "mn_MN", # Mongolian
1424 0x0461: "ne_NP", # Nepali
1425 0x0414: "nb_NO", # Norwegian - Bokmal
1426 0x0814: "nn_NO", # Norwegian - Nynorsk
1427 0x0482: "oc_FR", # Occitan - France
1428 0x0448: "or_IN", # Oriya - India
1429 0x0463: "ps_AF", # Pashto - Afghanistan
1430 0x0429: "fa_IR", # Persian
1431 0x0415: "pl_PL", # Polish
1432 0x0416: "pt_BR", # Portuguese - Brazil
1433 0x0816: "pt_PT", # Portuguese - Portugal
1434 0x0446: "pa_IN", # Punjabi
1435 0x046b: "quz_BO",# Quechua (Bolivia)
1436 0x086b: "quz_EC",# Quechua (Ecuador)
1437 0x0c6b: "quz_PE",# Quechua (Peru)
1438 0x0418: "ro_RO", # Romanian - Romania
1439 0x0417: "rm_CH", # Raeto-Romanese
1440 0x0419: "ru_RU", # Russian
1441 0x243b: "smn_FI",# Sami Finland
1442 0x103b: "smj_NO",# Sami Norway
1443 0x143b: "smj_SE",# Sami Sweden
1444 0x043b: "se_NO", # Sami Northern Norway
1445 0x083b: "se_SE", # Sami Northern Sweden
1446 0x0c3b: "se_FI", # Sami Northern Finland
1447 0x203b: "sms_FI",# Sami Skolt
1448 0x183b: "sma_NO",# Sami Southern Norway
1449 0x1c3b: "sma_SE",# Sami Southern Sweden
1450 0x044f: "sa_IN", # Sanskrit
1451 0x0c1a: "sr_SP", # Serbian - Cyrillic
1452 0x1c1a: "sr_BA", # Serbian - Bosnia Cyrillic
1453 0x081a: "sr_SP", # Serbian - Latin
1454 0x181a: "sr_BA", # Serbian - Bosnia Latin
1455 0x046c: "ns_ZA", # Northern Sotho
1456 0x0432: "tn_ZA", # Setswana - Southern Africa
1457 0x041b: "sk_SK", # Slovak
1458 0x0424: "sl_SI", # Slovenian
1459 0x040a: "es_ES", # Spanish - Spain
1460 0x080a: "es_MX", # Spanish - Mexico
1461 0x0c0a: "es_ES", # Spanish - Spain (Modern)
1462 0x100a: "es_GT", # Spanish - Guatemala
1463 0x140a: "es_CR", # Spanish - Costa Rica
1464 0x180a: "es_PA", # Spanish - Panama
1465 0x1c0a: "es_DO", # Spanish - Dominican Republic
1466 0x200a: "es_VE", # Spanish - Venezuela
1467 0x240a: "es_CO", # Spanish - Colombia
1468 0x280a: "es_PE", # Spanish - Peru
1469 0x2c0a: "es_AR", # Spanish - Argentina
1470 0x300a: "es_EC", # Spanish - Ecuador
1471 0x340a: "es_CL", # Spanish - Chile
1472 0x380a: "es_UR", # Spanish - Uruguay
1473 0x3c0a: "es_PY", # Spanish - Paraguay
1474 0x400a: "es_BO", # Spanish - Bolivia
1475 0x440a: "es_SV", # Spanish - El Salvador
1476 0x480a: "es_HN", # Spanish - Honduras
1477 0x4c0a: "es_NI", # Spanish - Nicaragua
1478 0x500a: "es_PR", # Spanish - Puerto Rico
1479 0x0441: "sw_KE", # Swahili
1480 0x041d: "sv_SE", # Swedish - Sweden
1481 0x081d: "sv_FI", # Swedish - Finland
1482 0x045a: "syr_SY",# Syriac
1483 0x0449: "ta_IN", # Tamil
1484 0x0444: "tt_RU", # Tatar
1485 0x044a: "te_IN", # Telugu
1486 0x041e: "th_TH", # Thai
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001487 0x041f: "tr_TR", # Turkish
Georg Brandlb709c2c2006-01-20 09:07:35 +00001488 0x0422: "uk_UA", # Ukrainian
1489 0x0420: "ur_PK", # Urdu
1490 0x0820: "ur_IN", # Urdu - India
1491 0x0443: "uz_UZ", # Uzbek - Latin
1492 0x0843: "uz_UZ", # Uzbek - Cyrillic
1493 0x042a: "vi_VN", # Vietnamese
1494 0x0452: "cy_GB", # Welsh
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001495}
1496
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001497def _print_locale():
1498
1499 """ Test function.
1500 """
1501 categories = {}
1502 def _init_categories(categories=categories):
1503 for k,v in globals().items():
1504 if k[:3] == 'LC_':
1505 categories[k] = v
1506 _init_categories()
1507 del categories['LC_ALL']
1508
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001509 print('Locale defaults as determined by getdefaultlocale():')
1510 print('-'*72)
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001511 lang, enc = getdefaultlocale()
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001512 print('Language: ', lang or '(undefined)')
1513 print('Encoding: ', enc or '(undefined)')
1514 print()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001515
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001516 print('Locale settings on startup:')
1517 print('-'*72)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001518 for name,category in categories.items():
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001519 print(name, '...')
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001520 lang, enc = getlocale(category)
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001521 print(' Language: ', lang or '(undefined)')
1522 print(' Encoding: ', enc or '(undefined)')
1523 print()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001524
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001525 print()
1526 print('Locale settings after calling resetlocale():')
1527 print('-'*72)
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001528 resetlocale()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001529 for name,category in categories.items():
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001530 print(name, '...')
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001531 lang, enc = getlocale(category)
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001532 print(' Language: ', lang or '(undefined)')
1533 print(' Encoding: ', enc or '(undefined)')
1534 print()
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001535
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001536 try:
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001537 setlocale(LC_ALL, "")
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001538 except:
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001539 print('NOTE:')
1540 print('setlocale(LC_ALL, "") does not support the default locale')
1541 print('given in the OS environment variables.')
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001542 else:
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001543 print()
1544 print('Locale settings after calling setlocale(LC_ALL, ""):')
1545 print('-'*72)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001546 for name,category in categories.items():
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001547 print(name, '...')
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001548 lang, enc = getlocale(category)
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001549 print(' Language: ', lang or '(undefined)')
1550 print(' Encoding: ', enc or '(undefined)')
1551 print()
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001552
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001553###
Guido van Rossumeef1d4e1997-11-19 19:01:43 +00001554
Tim Peters1baf8292001-01-24 10:13:46 +00001555try:
1556 LC_MESSAGES
Skip Montanaro0897f0c2002-03-25 21:40:36 +00001557except NameError:
Tim Peters1baf8292001-01-24 10:13:46 +00001558 pass
1559else:
1560 __all__.append("LC_MESSAGES")
1561
Guido van Rossumeef1d4e1997-11-19 19:01:43 +00001562if __name__=='__main__':
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001563 print('Locale aliasing:')
1564 print()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001565 _print_locale()
Guido van Rossumbe19ed72007-02-09 05:37:30 +00001566 print()
1567 print('Number formatting:')
1568 print()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001569 _test()