blob: fd549bbde12b62e4e834ab171e8f74faddb99c70 [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
Marc-André Lemburg5431bc32000-06-07 09:11:40 +000015
Fredrik Lundh6c86b992000-07-09 17:12:58 +000016# Try importing the _locale module.
17#
18# If this fails, fall back on a basic 'C' locale emulation.
Guido van Rossumeef1d4e1997-11-19 19:01:43 +000019
Tim Peters1baf8292001-01-24 10:13:46 +000020# Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before
21# trying the import. So __all__ is also fiddled at the end of the file.
Skip Montanaro17ab1232001-01-24 06:27:27 +000022__all__ = ["setlocale","Error","localeconv","strcoll","strxfrm",
23 "format","str","atof","atoi","LC_CTYPE","LC_COLLATE",
Tim Peters1baf8292001-01-24 10:13:46 +000024 "LC_TIME","LC_MONETARY","LC_NUMERIC", "LC_ALL","CHAR_MAX"]
Skip Montanaro17ab1232001-01-24 06:27:27 +000025
Marc-André Lemburg23481142000-06-08 17:49:41 +000026try:
Fredrik Lundh6c86b992000-07-09 17:12:58 +000027
Marc-André Lemburg23481142000-06-08 17:49:41 +000028 from _locale import *
29
30except ImportError:
31
Fredrik Lundh6c86b992000-07-09 17:12:58 +000032 # Locale emulation
33
Marc-André Lemburg23481142000-06-08 17:49:41 +000034 CHAR_MAX = 127
35 LC_ALL = 6
36 LC_COLLATE = 3
37 LC_CTYPE = 0
38 LC_MESSAGES = 5
39 LC_MONETARY = 4
40 LC_NUMERIC = 1
41 LC_TIME = 2
42 Error = ValueError
43
44 def localeconv():
Fredrik Lundh6c86b992000-07-09 17:12:58 +000045 """ localeconv() -> dict.
Marc-André Lemburg23481142000-06-08 17:49:41 +000046 Returns numeric and monetary locale-specific parameters.
47 """
48 # 'C' locale default values
49 return {'grouping': [127],
50 'currency_symbol': '',
51 'n_sign_posn': 127,
Fredrik Lundh6c86b992000-07-09 17:12:58 +000052 'p_cs_precedes': 127,
53 'n_cs_precedes': 127,
54 'mon_grouping': [],
Marc-André Lemburg23481142000-06-08 17:49:41 +000055 'n_sep_by_space': 127,
56 'decimal_point': '.',
57 'negative_sign': '',
58 'positive_sign': '',
Fredrik Lundh6c86b992000-07-09 17:12:58 +000059 'p_sep_by_space': 127,
Marc-André Lemburg23481142000-06-08 17:49:41 +000060 'int_curr_symbol': '',
Fredrik Lundh6c86b992000-07-09 17:12:58 +000061 'p_sign_posn': 127,
Marc-André Lemburg23481142000-06-08 17:49:41 +000062 'thousands_sep': '',
Fredrik Lundh6c86b992000-07-09 17:12:58 +000063 'mon_thousands_sep': '',
64 'frac_digits': 127,
Marc-André Lemburg23481142000-06-08 17:49:41 +000065 'mon_decimal_point': '',
66 'int_frac_digits': 127}
Fredrik Lundh6c86b992000-07-09 17:12:58 +000067
Marc-André Lemburg23481142000-06-08 17:49:41 +000068 def setlocale(category, value=None):
Fredrik Lundh6c86b992000-07-09 17:12:58 +000069 """ setlocale(integer,string=None) -> string.
Marc-André Lemburg23481142000-06-08 17:49:41 +000070 Activates/queries locale processing.
71 """
Martin v. Löwis103d6e72003-03-30 15:42:13 +000072 if value not in (None, '', 'C'):
Fredrik Lundh6c86b992000-07-09 17:12:58 +000073 raise Error, '_locale emulation only supports "C" locale'
Marc-André Lemburg23481142000-06-08 17:49:41 +000074 return 'C'
75
76 def strcoll(a,b):
Fredrik Lundh6c86b992000-07-09 17:12:58 +000077 """ strcoll(string,string) -> int.
Marc-André Lemburg23481142000-06-08 17:49:41 +000078 Compares two strings according to the locale.
79 """
80 return cmp(a,b)
81
82 def strxfrm(s):
Fredrik Lundh6c86b992000-07-09 17:12:58 +000083 """ strxfrm(string) -> string.
Marc-André Lemburg23481142000-06-08 17:49:41 +000084 Returns a string that behaves for cmp locale-aware.
85 """
86 return s
Marc-André Lemburg5431bc32000-06-07 09:11:40 +000087
88### Number formatting APIs
89
90# Author: Martin von Loewis
Thomas Wouters477c8d52006-05-27 19:21:47 +000091# improved by Georg Brandl
Guido van Rossumeef1d4e1997-11-19 19:01:43 +000092
93#perform the grouping from right to left
Thomas Wouters477c8d52006-05-27 19:21:47 +000094def _group(s, monetary=False):
95 conv = localeconv()
96 thousands_sep = conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
97 grouping = conv[monetary and 'mon_grouping' or 'grouping']
98 if not grouping:
99 return (s, 0)
100 result = ""
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000101 seps = 0
102 spaces = ""
103 if s[-1] == ' ':
104 sp = s.find(' ')
105 spaces = s[sp:]
106 s = s[:sp]
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000107 while s and grouping:
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000108 # if grouping is -1, we are done
Thomas Wouters477c8d52006-05-27 19:21:47 +0000109 if grouping[0] == CHAR_MAX:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000110 break
111 # 0: re-use last group ad infinitum
Thomas Wouters477c8d52006-05-27 19:21:47 +0000112 elif grouping[0] != 0:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000113 #process last group
Thomas Wouters477c8d52006-05-27 19:21:47 +0000114 group = grouping[0]
115 grouping = grouping[1:]
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000116 if result:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000117 result = s[-group:] + thousands_sep + result
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000118 seps += 1
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000119 else:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000120 result = s[-group:]
121 s = s[:-group]
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000122 if s and s[-1] not in "0123456789":
123 # the leading string is only spaces and signs
Thomas Wouters477c8d52006-05-27 19:21:47 +0000124 return s + result + spaces, seps
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000125 if not result:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000126 return s + spaces, seps
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000127 if s:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000128 result = s + thousands_sep + result
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000129 seps += 1
Thomas Wouters477c8d52006-05-27 19:21:47 +0000130 return result + spaces, seps
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000131
Thomas Wouters477c8d52006-05-27 19:21:47 +0000132def format(percent, value, grouping=False, monetary=False, *additional):
133 """Returns the locale-aware substitution of a %? specifier
134 (percent).
135
136 additional is for format strings which contain one or more
137 '*' modifiers."""
138 # this is only for one-percent-specifier strings and this should be checked
139 if percent[0] != '%':
140 raise ValueError("format() must be given exactly one %char "
141 "format specifier")
142 if additional:
143 formatted = percent % ((value,) + additional)
144 else:
145 formatted = percent % value
146 # floats and decimal ints need special action!
147 if percent[-1] in 'eEfFgG':
148 seps = 0
149 parts = formatted.split('.')
150 if grouping:
151 parts[0], seps = _group(parts[0], monetary=monetary)
152 decimal_point = localeconv()[monetary and 'mon_decimal_point'
153 or 'decimal_point']
154 formatted = decimal_point.join(parts)
155 while seps:
156 sp = formatted.find(' ')
157 if sp == -1: break
158 formatted = formatted[:sp] + formatted[sp+1:]
159 seps -= 1
160 elif percent[-1] in 'diu':
161 if grouping:
162 formatted = _group(formatted, monetary=monetary)[0]
163 return formatted
164
165import re, operator
166_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
167 r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
168
169def format_string(f, val, grouping=False):
170 """Formats a string in the same way that the % formatting would use,
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000171 but takes the current locale into account.
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000172 Grouping is applied if the third parameter is true."""
Thomas Wouters477c8d52006-05-27 19:21:47 +0000173 percents = list(_percent_re.finditer(f))
174 new_f = _percent_re.sub('%s', f)
175
176 if isinstance(val, tuple):
177 new_val = list(val)
178 i = 0
179 for perc in percents:
180 starcount = perc.group('modifiers').count('*')
181 new_val[i] = format(perc.group(), new_val[i], grouping, False, *new_val[i+1:i+1+starcount])
182 del new_val[i+1:i+1+starcount]
183 i += (1 + starcount)
184 val = tuple(new_val)
185 elif operator.isMappingType(val):
186 for perc in percents:
187 key = perc.group("key")
188 val[key] = format(perc.group(), val[key], grouping)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000189 else:
Thomas Wouters477c8d52006-05-27 19:21:47 +0000190 # val is a single value
191 val = format(percents[0].group(), val, grouping)
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000192
Thomas Wouters477c8d52006-05-27 19:21:47 +0000193 return new_f % val
Martin v. Löwis88ad12a2001-04-13 08:09:50 +0000194
Thomas Wouters477c8d52006-05-27 19:21:47 +0000195def currency(val, symbol=True, grouping=False, international=False):
196 """Formats val according to the currency settings
197 in the current locale."""
198 conv = localeconv()
199
200 # check for illegal values
201 digits = conv[international and 'int_frac_digits' or 'frac_digits']
202 if digits == 127:
203 raise ValueError("Currency formatting is not possible using "
204 "the 'C' locale.")
205
206 s = format('%%.%if' % digits, abs(val), grouping, monetary=True)
207 # '<' and '>' are markers if the sign must be inserted between symbol and value
208 s = '<' + s + '>'
209
210 if symbol:
211 smb = conv[international and 'int_curr_symbol' or 'currency_symbol']
212 precedes = conv[val<0 and 'n_cs_precedes' or 'p_cs_precedes']
213 separated = conv[val<0 and 'n_sep_by_space' or 'p_sep_by_space']
214
215 if precedes:
216 s = smb + (separated and ' ' or '') + s
217 else:
218 s = s + (separated and ' ' or '') + smb
219
220 sign_pos = conv[val<0 and 'n_sign_posn' or 'p_sign_posn']
221 sign = conv[val<0 and 'negative_sign' or 'positive_sign']
222
223 if sign_pos == 0:
224 s = '(' + s + ')'
225 elif sign_pos == 1:
226 s = sign + s
227 elif sign_pos == 2:
228 s = s + sign
229 elif sign_pos == 3:
230 s = s.replace('<', sign)
231 elif sign_pos == 4:
232 s = s.replace('>', sign)
233 else:
234 # the default if nothing specified;
235 # this should be the most fitting sign position
236 s = sign + s
237
238 return s.replace('<', '').replace('>', '')
Martin v. Löwisdb786872001-01-21 18:52:33 +0000239
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000240def str(val):
241 """Convert float to integer, taking the locale into account."""
Thomas Wouters477c8d52006-05-27 19:21:47 +0000242 return format("%.12g", val)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000243
Thomas Wouters477c8d52006-05-27 19:21:47 +0000244def atof(string, func=float):
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000245 "Parses a string as a float according to the locale settings."
246 #First, get rid of the grouping
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000247 ts = localeconv()['thousands_sep']
248 if ts:
Skip Montanaro249369c2004-04-10 16:39:32 +0000249 string = string.replace(ts, '')
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000250 #next, replace the decimal point with a dot
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000251 dd = localeconv()['decimal_point']
252 if dd:
Skip Montanaro249369c2004-04-10 16:39:32 +0000253 string = string.replace(dd, '.')
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000254 #finally, parse the string
Skip Montanaro249369c2004-04-10 16:39:32 +0000255 return func(string)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000256
257def atoi(str):
258 "Converts a string to an integer according to the locale settings."
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000259 return atof(str, int)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000260
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000261def _test():
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000262 setlocale(LC_ALL, "")
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000263 #do grouping
Thomas Wouters477c8d52006-05-27 19:21:47 +0000264 s1 = format("%d", 123456789,1)
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000265 print s1, "is", atoi(s1)
Guido van Rossumeef1d4e1997-11-19 19:01:43 +0000266 #standard formatting
Thomas Wouters477c8d52006-05-27 19:21:47 +0000267 s1 = str(3.14)
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000268 print s1, "is", atof(s1)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000269
270### Locale name aliasing engine
271
272# Author: Marc-Andre Lemburg, mal@lemburg.com
Fredrik Lundh37a09822002-10-19 20:19:10 +0000273# Various tweaks by Fredrik Lundh <fredrik@pythonware.com>
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000274
275# store away the low-level version of setlocale (it's
276# overridden below)
277_setlocale = setlocale
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000278
279def normalize(localename):
280
281 """ Returns a normalized locale code for the given locale
282 name.
283
284 The returned locale code is formatted for use with
285 setlocale().
286
287 If normalization fails, the original name is returned
288 unchanged.
289
290 If the given encoding is not known, the function defaults to
291 the default encoding for the locale code just like setlocale()
292 does.
293
294 """
295 # Normalize the locale name and extract the encoding
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000296 fullname = localename.lower()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000297 if ':' in fullname:
298 # ':' is sometimes used as encoding delimiter.
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000299 fullname = fullname.replace(':', '.')
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000300 if '.' in fullname:
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000301 langname, encoding = fullname.split('.')[:2]
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000302 fullname = langname + '.' + encoding
303 else:
304 langname = fullname
305 encoding = ''
306
307 # First lookup: fullname (possibly with encoding)
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000308 norm_encoding = encoding.replace('-', '')
309 norm_encoding = norm_encoding.replace('_', '')
310 lookup_name = langname + '.' + encoding
311 code = locale_alias.get(lookup_name, None)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000312 if code is not None:
313 return code
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000314 #print 'first lookup failed'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000315
316 # Second try: langname (without encoding)
317 code = locale_alias.get(langname, None)
318 if code is not None:
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000319 #print 'langname lookup succeeded'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000320 if '.' in code:
Eric S. Raymondbe9b5072001-02-09 10:48:30 +0000321 langname, defenc = code.split('.')
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000322 else:
323 langname = code
324 defenc = ''
325 if encoding:
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000326 # Convert the encoding to a C lib compatible encoding string
327 norm_encoding = encodings.normalize_encoding(encoding)
328 #print 'norm encoding: %r' % norm_encoding
329 norm_encoding = encodings.aliases.aliases.get(norm_encoding,
330 norm_encoding)
331 #print 'aliased encoding: %r' % norm_encoding
332 encoding = locale_encoding_alias.get(norm_encoding,
333 norm_encoding)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000334 else:
335 encoding = defenc
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000336 #print 'found encoding %r' % encoding
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000337 if encoding:
338 return langname + '.' + encoding
339 else:
340 return langname
341
342 else:
343 return localename
344
345def _parse_localename(localename):
346
347 """ Parses the locale code for localename and returns the
348 result as tuple (language code, encoding).
349
350 The localename is normalized and passed through the locale
351 alias engine. A ValueError is raised in case the locale name
352 cannot be parsed.
353
354 The language code corresponds to RFC 1766. code and encoding
355 can be None in case the values cannot be determined or are
Jeremy Hyltona05e2932000-06-28 14:48:01 +0000356 unknown to this implementation.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000357
358 """
359 code = normalize(localename)
Georg Brandlb709c2c2006-01-20 09:07:35 +0000360 if '@' in code:
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000361 # Deal with locale modifiers
362 code, modifier = code.split('@')
363 if modifier == 'euro' and '.' not in code:
364 # Assume Latin-9 for @euro locales. This is bogus,
365 # since some systems may use other encodings for these
366 # locales. Also, we ignore other modifiers.
367 return code, 'iso-8859-15'
Tim Peters230a60c2002-11-09 05:08:07 +0000368
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000369 if '.' in code:
Raymond Hettinger346e67f2005-01-01 06:10:26 +0000370 return tuple(code.split('.')[:2])
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000371 elif code == 'C':
372 return None, None
Andrew M. Kuchling1f877ef2001-08-13 14:50:44 +0000373 raise ValueError, 'unknown locale: %s' % localename
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000374
375def _build_localename(localetuple):
376
377 """ Builds a locale code from the given tuple (language code,
378 encoding).
379
380 No aliasing or normalizing takes place.
381
382 """
383 language, encoding = localetuple
384 if language is None:
385 language = 'C'
386 if encoding is None:
387 return language
388 else:
389 return language + '.' + encoding
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000390
Matthias Klosef3f231f2005-09-20 07:02:49 +0000391def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000392
393 """ Tries to determine the default locale settings and returns
394 them as tuple (language code, encoding).
395
396 According to POSIX, a program which has not called
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000397 setlocale(LC_ALL, "") runs using the portable 'C' locale.
398 Calling setlocale(LC_ALL, "") lets it use the default locale as
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000399 defined by the LANG variable. Since we don't want to interfere
Thomas Wouters7e474022000-07-16 12:04:32 +0000400 with the current locale setting we thus emulate the behavior
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000401 in the way described above.
402
403 To maintain compatibility with other platforms, not only the
404 LANG variable is tested, but a list of variables given as
405 envvars parameter. The first found to be defined will be
406 used. envvars defaults to the search path used in GNU gettext;
407 it must always contain the variable name 'LANG'.
408
409 Except for the code 'C', the language code corresponds to RFC
410 1766. code and encoding can be None in case the values cannot
411 be determined.
412
413 """
Fredrik Lundh04661322000-07-09 23:16:10 +0000414
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000415 try:
416 # check if it's supported by the _locale module
417 import _locale
418 code, encoding = _locale._getdefaultlocale()
Fredrik Lundh04661322000-07-09 23:16:10 +0000419 except (ImportError, AttributeError):
420 pass
421 else:
Fredrik Lundh663809e2000-07-10 19:32:19 +0000422 # make sure the code/encoding values are valid
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000423 if sys.platform == "win32" and code and code[:2] == "0x":
424 # map windows language identifier to language name
425 code = windows_locale.get(int(code, 0))
Fredrik Lundh663809e2000-07-10 19:32:19 +0000426 # ...add other platform-specific processing here, if
427 # necessary...
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000428 return code, encoding
Fredrik Lundh04661322000-07-09 23:16:10 +0000429
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000430 # fall back on POSIX behaviour
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000431 import os
432 lookup = os.environ.get
433 for variable in envvars:
434 localename = lookup(variable,None)
Martin v. Löwisc8ae31d2004-07-26 12:45:18 +0000435 if localename:
Matthias Klosef3f231f2005-09-20 07:02:49 +0000436 if variable == 'LANGUAGE':
437 localename = localename.split(':')[0]
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000438 break
439 else:
440 localename = 'C'
441 return _parse_localename(localename)
442
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000443
444def getlocale(category=LC_CTYPE):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000445
446 """ Returns the current setting for the given locale category as
447 tuple (language code, encoding).
448
449 category may be one of the LC_* value except LC_ALL. It
450 defaults to LC_CTYPE.
451
452 Except for the code 'C', the language code corresponds to RFC
453 1766. code and encoding can be None in case the values cannot
454 be determined.
455
456 """
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000457 localename = _setlocale(category)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000458 if category == LC_ALL and ';' in localename:
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000459 raise TypeError, 'category LC_ALL is not supported'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000460 return _parse_localename(localename)
461
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000462def setlocale(category, locale=None):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000463
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000464 """ Set the locale for the given category. The locale can be
465 a string, a locale tuple (language code, encoding), or None.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000466
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000467 Locale tuples are converted to strings the locale aliasing
468 engine. Locale strings are passed directly to the C lib.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000469
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000470 category may be given as one of the LC_* values.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000471
472 """
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000473 if locale and type(locale) is not type(""):
474 # convert to string
475 locale = normalize(_build_localename(locale))
476 return _setlocale(category, locale)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000477
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000478def resetlocale(category=LC_ALL):
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000479
480 """ Sets the locale for category to the default setting.
481
482 The default setting is determined by calling
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000483 getdefaultlocale(). category defaults to LC_ALL.
484
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000485 """
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000486 _setlocale(category, _build_localename(getdefaultlocale()))
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000487
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000488if sys.platform in ('win32', 'darwin', 'mac'):
489 # On Win32, this will return the ANSI code page
490 # On the Mac, it should return the system encoding;
491 # it might return "ascii" instead
492 def getpreferredencoding(do_setlocale = True):
493 """Return the charset that the user is likely using."""
494 import _locale
Tim Petersa326f472002-11-05 03:49:09 +0000495 return _locale._getdefaultlocale()[1]
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000496else:
497 # On Unix, if CODESET is available, use that.
498 try:
499 CODESET
500 except NameError:
501 # Fall back to parsing environment variables :-(
502 def getpreferredencoding(do_setlocale = True):
503 """Return the charset that the user is likely using,
504 by looking at environment variables."""
505 return getdefaultlocale()[1]
506 else:
507 def getpreferredencoding(do_setlocale = True):
508 """Return the charset that the user is likely using,
509 according to the system configuration."""
510 if do_setlocale:
511 oldloc = setlocale(LC_CTYPE)
512 setlocale(LC_CTYPE, "")
513 result = nl_langinfo(CODESET)
514 setlocale(LC_CTYPE, oldloc)
515 return result
516 else:
517 return nl_langinfo(CODESET)
Tim Peters230a60c2002-11-09 05:08:07 +0000518
Martin v. Löwisf0a46682002-11-03 17:20:12 +0000519
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000520### Database
521#
522# The following data was extracted from the locale.alias file which
523# comes with X11 and then hand edited removing the explicit encoding
524# definitions and adding some more aliases. The file is usually
525# available as /usr/lib/X11/locale/locale.alias.
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000526#
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000527
528#
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000529# The local_encoding_alias table maps lowercase encoding alias names
530# to C locale encoding names (case-sensitive). Note that normalize()
531# first looks up the encoding in the encodings.aliases dictionary and
532# then applies this mapping to find the correct C lib name for the
533# encoding.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000534#
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000535locale_encoding_alias = {
536
537 # Mappings for non-standard encoding names used in locale names
538 '437': 'C',
539 'c': 'C',
540 'en': 'ISO8859-1',
541 'jis': 'JIS7',
542 'jis7': 'JIS7',
543 'ajec': 'eucJP',
544
545 # Mappings from Python codec names to C lib encoding names
546 'ascii': 'ISO8859-1',
547 'latin_1': 'ISO8859-1',
548 'iso8859_1': 'ISO8859-1',
549 'iso8859_10': 'ISO8859-10',
550 'iso8859_11': 'ISO8859-11',
551 'iso8859_13': 'ISO8859-13',
552 'iso8859_14': 'ISO8859-14',
553 'iso8859_15': 'ISO8859-15',
554 'iso8859_2': 'ISO8859-2',
555 'iso8859_3': 'ISO8859-3',
556 'iso8859_4': 'ISO8859-4',
557 'iso8859_5': 'ISO8859-5',
558 'iso8859_6': 'ISO8859-6',
559 'iso8859_7': 'ISO8859-7',
560 'iso8859_8': 'ISO8859-8',
561 'iso8859_9': 'ISO8859-9',
562 'iso2022_jp': 'JIS7',
563 'shift_jis': 'SJIS',
564 'tactis': 'TACTIS',
565 'euc_jp': 'eucJP',
566 'euc_kr': 'eucKR',
Marc-André Lemburgb4cebd42004-12-13 19:56:01 +0000567 'utf_8': 'UTF8',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000568 'koi8_r': 'KOI8-R',
569 'koi8_u': 'KOI8-U',
570 # XXX This list is still incomplete. If you know more
571 # mappings, please file a bug report. Thanks.
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000572}
573
Fredrik Lundh6c86b992000-07-09 17:12:58 +0000574#
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000575# The locale_alias table maps lowercase alias names to C locale names
576# (case-sensitive). Encodings are always separated from the locale
577# name using a dot ('.'); they should only be given in case the
578# language name is needed to interpret the given encoding alias
579# correctly (CJK codes often have this need).
580#
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000581# Note that the normalize() function which uses this tables
582# removes '_' and '-' characters from the encoding part of the
583# locale name before doing the lookup. This saves a lot of
584# space in the table.
585#
586# MAL 2004-12-10:
587# Updated alias mapping to most recent locale.alias file
588# from X.org distribution using makelocalealias.py.
589#
590# These are the differences compared to the old mapping (Python 2.4
591# and older):
592#
593# updated 'bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
594# updated 'bg_bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
595# updated 'bulgarian' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
596# updated 'cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
597# updated 'cz_cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
598# updated 'czech' -> 'cs_CS.ISO8859-2' to 'cs_CZ.ISO8859-2'
599# updated 'dutch' -> 'nl_BE.ISO8859-1' to 'nl_NL.ISO8859-1'
600# updated 'et' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
601# updated 'et_ee' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
602# updated 'fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
603# updated 'fi_fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
604# updated 'iw' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
605# updated 'iw_il' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
606# updated 'japanese' -> 'ja_JP.SJIS' to 'ja_JP.eucJP'
607# updated 'lt' -> 'lt_LT.ISO8859-4' to 'lt_LT.ISO8859-13'
608# updated 'lv' -> 'lv_LV.ISO8859-4' to 'lv_LV.ISO8859-13'
609# updated 'sl' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
610# updated 'slovene' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
611# updated 'th_th' -> 'th_TH.TACTIS' to 'th_TH.ISO8859-11'
612# updated 'zh_cn' -> 'zh_CN.eucCN' to 'zh_CN.gb2312'
613# updated 'zh_cn.big5' -> 'zh_TW.eucTW' to 'zh_TW.big5'
614# updated 'zh_tw' -> 'zh_TW.eucTW' to 'zh_TW.big5'
615#
Marc-André Lemburg5431bc32000-06-07 09:11:40 +0000616locale_alias = {
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000617 'a3': 'a3_AZ.KOI8-C',
618 'a3_az': 'a3_AZ.KOI8-C',
619 'a3_az.koi8c': 'a3_AZ.KOI8-C',
620 'af': 'af_ZA.ISO8859-1',
621 'af_za': 'af_ZA.ISO8859-1',
622 'af_za.iso88591': 'af_ZA.ISO8859-1',
623 'am': 'am_ET.UTF-8',
624 'american': 'en_US.ISO8859-1',
625 'american.iso88591': 'en_US.ISO8859-1',
626 'ar': 'ar_AA.ISO8859-6',
627 'ar_aa': 'ar_AA.ISO8859-6',
628 'ar_aa.iso88596': 'ar_AA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000629 'ar_ae': 'ar_AE.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000630 'ar_bh': 'ar_BH.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000631 'ar_dz': 'ar_DZ.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000632 'ar_eg': 'ar_EG.ISO8859-6',
633 'ar_eg.iso88596': 'ar_EG.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000634 'ar_iq': 'ar_IQ.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000635 'ar_jo': 'ar_JO.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000636 'ar_kw': 'ar_KW.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000637 'ar_lb': 'ar_LB.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000638 'ar_ly': 'ar_LY.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000639 'ar_ma': 'ar_MA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000640 'ar_om': 'ar_OM.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000641 'ar_qa': 'ar_QA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000642 'ar_sa': 'ar_SA.ISO8859-6',
643 'ar_sa.iso88596': 'ar_SA.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000644 'ar_sd': 'ar_SD.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000645 'ar_sy': 'ar_SY.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000646 'ar_tn': 'ar_TN.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000647 'ar_ye': 'ar_YE.ISO8859-6',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000648 'arabic': 'ar_AA.ISO8859-6',
649 'arabic.iso88596': 'ar_AA.ISO8859-6',
650 'az': 'az_AZ.ISO8859-9E',
651 'az_az': 'az_AZ.ISO8859-9E',
652 'az_az.iso88599e': 'az_AZ.ISO8859-9E',
653 'be': 'be_BY.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000654 'be_by': 'be_BY.CP1251',
655 'be_by.cp1251': 'be_BY.CP1251',
656 'be_by.microsoftcp1251': 'be_BY.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000657 'bg': 'bg_BG.CP1251',
658 'bg_bg': 'bg_BG.CP1251',
659 'bg_bg.cp1251': 'bg_BG.CP1251',
660 'bg_bg.iso88595': 'bg_BG.ISO8859-5',
661 'bg_bg.koi8r': 'bg_BG.KOI8-R',
662 'bg_bg.microsoftcp1251': 'bg_BG.CP1251',
663 'bokmal': 'nb_NO.ISO8859-1',
664 'bokm\xe5l': 'nb_NO.ISO8859-1',
665 'br': 'br_FR.ISO8859-1',
666 'br_fr': 'br_FR.ISO8859-1',
667 'br_fr.iso88591': 'br_FR.ISO8859-1',
668 'br_fr.iso885914': 'br_FR.ISO8859-14',
669 'br_fr.iso885915': 'br_FR.ISO8859-15',
670 'br_fr@euro': 'br_FR.ISO8859-15',
671 'bulgarian': 'bg_BG.CP1251',
672 'c': 'C',
673 'c-french': 'fr_CA.ISO8859-1',
674 'c-french.iso88591': 'fr_CA.ISO8859-1',
675 'c.en': 'C',
676 'c.iso88591': 'en_US.ISO8859-1',
677 'c_c': 'C',
678 'c_c.c': 'C',
679 'ca': 'ca_ES.ISO8859-1',
680 'ca_es': 'ca_ES.ISO8859-1',
681 'ca_es.iso88591': 'ca_ES.ISO8859-1',
682 'ca_es.iso885915': 'ca_ES.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000683 'ca_es@euro': 'ca_ES.ISO8859-15',
684 'catalan': 'ca_ES.ISO8859-1',
685 'cextend': 'en_US.ISO8859-1',
686 'cextend.en': 'en_US.ISO8859-1',
687 'chinese-s': 'zh_CN.eucCN',
688 'chinese-t': 'zh_TW.eucTW',
689 'croatian': 'hr_HR.ISO8859-2',
690 'cs': 'cs_CZ.ISO8859-2',
691 'cs_cs': 'cs_CZ.ISO8859-2',
692 'cs_cs.iso88592': 'cs_CZ.ISO8859-2',
693 'cs_cz': 'cs_CZ.ISO8859-2',
694 'cs_cz.iso88592': 'cs_CZ.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000695 'cy': 'cy_GB.ISO8859-1',
696 'cy_gb': 'cy_GB.ISO8859-1',
697 'cy_gb.iso88591': 'cy_GB.ISO8859-1',
698 'cy_gb.iso885914': 'cy_GB.ISO8859-14',
699 'cy_gb.iso885915': 'cy_GB.ISO8859-15',
700 'cy_gb@euro': 'cy_GB.ISO8859-15',
701 'cz': 'cs_CZ.ISO8859-2',
702 'cz_cz': 'cs_CZ.ISO8859-2',
703 'czech': 'cs_CZ.ISO8859-2',
704 'da': 'da_DK.ISO8859-1',
705 'da_dk': 'da_DK.ISO8859-1',
706 'da_dk.88591': 'da_DK.ISO8859-1',
707 'da_dk.885915': 'da_DK.ISO8859-15',
708 'da_dk.iso88591': 'da_DK.ISO8859-1',
709 'da_dk.iso885915': 'da_DK.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000710 'da_dk@euro': 'da_DK.ISO8859-15',
711 'danish': 'da_DK.ISO8859-1',
712 'danish.iso88591': 'da_DK.ISO8859-1',
713 'dansk': 'da_DK.ISO8859-1',
714 'de': 'de_DE.ISO8859-1',
715 'de_at': 'de_AT.ISO8859-1',
716 'de_at.iso88591': 'de_AT.ISO8859-1',
717 'de_at.iso885915': 'de_AT.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000718 'de_at@euro': 'de_AT.ISO8859-15',
719 'de_be': 'de_BE.ISO8859-1',
720 'de_be.iso88591': 'de_BE.ISO8859-1',
721 'de_be.iso885915': 'de_BE.ISO8859-15',
722 'de_be@euro': 'de_BE.ISO8859-15',
723 'de_ch': 'de_CH.ISO8859-1',
724 'de_ch.iso88591': 'de_CH.ISO8859-1',
725 'de_ch.iso885915': 'de_CH.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000726 'de_ch@euro': 'de_CH.ISO8859-15',
727 'de_de': 'de_DE.ISO8859-1',
728 'de_de.88591': 'de_DE.ISO8859-1',
729 'de_de.885915': 'de_DE.ISO8859-15',
730 'de_de.885915@euro': 'de_DE.ISO8859-15',
731 'de_de.iso88591': 'de_DE.ISO8859-1',
732 'de_de.iso885915': 'de_DE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000733 'de_de@euro': 'de_DE.ISO8859-15',
734 'de_lu': 'de_LU.ISO8859-1',
735 'de_lu.iso88591': 'de_LU.ISO8859-1',
736 'de_lu.iso885915': 'de_LU.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000737 'de_lu@euro': 'de_LU.ISO8859-15',
738 'deutsch': 'de_DE.ISO8859-1',
739 'dutch': 'nl_NL.ISO8859-1',
740 'dutch.iso88591': 'nl_BE.ISO8859-1',
741 'ee': 'ee_EE.ISO8859-4',
742 'ee_ee': 'ee_EE.ISO8859-4',
743 'ee_ee.iso88594': 'ee_EE.ISO8859-4',
744 'eesti': 'et_EE.ISO8859-1',
745 'el': 'el_GR.ISO8859-7',
746 'el_gr': 'el_GR.ISO8859-7',
747 'el_gr.iso88597': 'el_GR.ISO8859-7',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000748 'el_gr@euro': 'el_GR.ISO8859-15',
749 'en': 'en_US.ISO8859-1',
750 'en.iso88591': 'en_US.ISO8859-1',
751 'en_au': 'en_AU.ISO8859-1',
752 'en_au.iso88591': 'en_AU.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000753 'en_be': 'en_BE.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000754 'en_be@euro': 'en_BE.ISO8859-15',
755 'en_bw': 'en_BW.ISO8859-1',
756 'en_ca': 'en_CA.ISO8859-1',
757 'en_ca.iso88591': 'en_CA.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000758 'en_gb': 'en_GB.ISO8859-1',
759 'en_gb.88591': 'en_GB.ISO8859-1',
760 'en_gb.iso88591': 'en_GB.ISO8859-1',
761 'en_gb.iso885915': 'en_GB.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000762 'en_gb@euro': 'en_GB.ISO8859-15',
763 'en_hk': 'en_HK.ISO8859-1',
764 'en_ie': 'en_IE.ISO8859-1',
765 'en_ie.iso88591': 'en_IE.ISO8859-1',
766 'en_ie.iso885915': 'en_IE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000767 'en_ie@euro': 'en_IE.ISO8859-15',
768 'en_in': 'en_IN.ISO8859-1',
769 'en_nz': 'en_NZ.ISO8859-1',
770 'en_nz.iso88591': 'en_NZ.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000771 'en_ph': 'en_PH.ISO8859-1',
772 'en_sg': 'en_SG.ISO8859-1',
773 'en_uk': 'en_GB.ISO8859-1',
774 'en_us': 'en_US.ISO8859-1',
775 'en_us.88591': 'en_US.ISO8859-1',
776 'en_us.885915': 'en_US.ISO8859-15',
777 'en_us.iso88591': 'en_US.ISO8859-1',
778 'en_us.iso885915': 'en_US.ISO8859-15',
779 'en_us.iso885915@euro': 'en_US.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000780 'en_us@euro': 'en_US.ISO8859-15',
781 'en_us@euro@euro': 'en_US.ISO8859-15',
782 'en_za': 'en_ZA.ISO8859-1',
783 'en_za.88591': 'en_ZA.ISO8859-1',
784 'en_za.iso88591': 'en_ZA.ISO8859-1',
785 'en_za.iso885915': 'en_ZA.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000786 'en_za@euro': 'en_ZA.ISO8859-15',
787 'en_zw': 'en_ZW.ISO8859-1',
788 'eng_gb': 'en_GB.ISO8859-1',
789 'eng_gb.8859': 'en_GB.ISO8859-1',
790 'english': 'en_EN.ISO8859-1',
791 'english.iso88591': 'en_EN.ISO8859-1',
792 'english_uk': 'en_GB.ISO8859-1',
793 'english_uk.8859': 'en_GB.ISO8859-1',
794 'english_united-states': 'en_US.ISO8859-1',
795 'english_united-states.437': 'C',
796 'english_us': 'en_US.ISO8859-1',
797 'english_us.8859': 'en_US.ISO8859-1',
798 'english_us.ascii': 'en_US.ISO8859-1',
799 'eo': 'eo_XX.ISO8859-3',
800 'eo_eo': 'eo_EO.ISO8859-3',
801 'eo_eo.iso88593': 'eo_EO.ISO8859-3',
802 'eo_xx': 'eo_XX.ISO8859-3',
803 'eo_xx.iso88593': 'eo_XX.ISO8859-3',
804 'es': 'es_ES.ISO8859-1',
805 'es_ar': 'es_AR.ISO8859-1',
806 'es_ar.iso88591': 'es_AR.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000807 'es_bo': 'es_BO.ISO8859-1',
808 'es_bo.iso88591': 'es_BO.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000809 'es_cl': 'es_CL.ISO8859-1',
810 'es_cl.iso88591': 'es_CL.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000811 'es_co': 'es_CO.ISO8859-1',
812 'es_co.iso88591': 'es_CO.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000813 'es_cr': 'es_CR.ISO8859-1',
814 'es_cr.iso88591': 'es_CR.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000815 'es_do': 'es_DO.ISO8859-1',
816 'es_do.iso88591': 'es_DO.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000817 'es_ec': 'es_EC.ISO8859-1',
818 'es_ec.iso88591': 'es_EC.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000819 'es_es': 'es_ES.ISO8859-1',
820 'es_es.88591': 'es_ES.ISO8859-1',
821 'es_es.iso88591': 'es_ES.ISO8859-1',
822 'es_es.iso885915': 'es_ES.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000823 'es_es@euro': 'es_ES.ISO8859-15',
824 'es_gt': 'es_GT.ISO8859-1',
825 'es_gt.iso88591': 'es_GT.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000826 'es_hn': 'es_HN.ISO8859-1',
827 'es_hn.iso88591': 'es_HN.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000828 'es_mx': 'es_MX.ISO8859-1',
829 'es_mx.iso88591': 'es_MX.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000830 'es_ni': 'es_NI.ISO8859-1',
831 'es_ni.iso88591': 'es_NI.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000832 'es_pa': 'es_PA.ISO8859-1',
833 'es_pa.iso88591': 'es_PA.ISO8859-1',
834 'es_pa.iso885915': 'es_PA.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000835 'es_pa@euro': 'es_PA.ISO8859-15',
836 'es_pe': 'es_PE.ISO8859-1',
837 'es_pe.iso88591': 'es_PE.ISO8859-1',
838 'es_pe.iso885915': 'es_PE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000839 'es_pe@euro': 'es_PE.ISO8859-15',
840 'es_pr': 'es_PR.ISO8859-1',
841 'es_pr.iso88591': 'es_PR.ISO8859-1',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000842 'es_py': 'es_PY.ISO8859-1',
843 'es_py.iso88591': 'es_PY.ISO8859-1',
844 'es_py.iso885915': 'es_PY.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000845 'es_py@euro': 'es_PY.ISO8859-15',
846 'es_sv': 'es_SV.ISO8859-1',
847 'es_sv.iso88591': 'es_SV.ISO8859-1',
848 'es_sv.iso885915': 'es_SV.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000849 'es_sv@euro': 'es_SV.ISO8859-15',
850 'es_us': 'es_US.ISO8859-1',
851 'es_uy': 'es_UY.ISO8859-1',
852 'es_uy.iso88591': 'es_UY.ISO8859-1',
853 'es_uy.iso885915': 'es_UY.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000854 'es_uy@euro': 'es_UY.ISO8859-15',
855 'es_ve': 'es_VE.ISO8859-1',
856 'es_ve.iso88591': 'es_VE.ISO8859-1',
857 'es_ve.iso885915': 'es_VE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000858 'es_ve@euro': 'es_VE.ISO8859-15',
859 'estonian': 'et_EE.ISO8859-1',
860 'et': 'et_EE.ISO8859-15',
861 'et_ee': 'et_EE.ISO8859-15',
862 'et_ee.iso88591': 'et_EE.ISO8859-1',
863 'et_ee.iso885913': 'et_EE.ISO8859-13',
864 'et_ee.iso885915': 'et_EE.ISO8859-15',
865 'et_ee.iso88594': 'et_EE.ISO8859-4',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000866 'et_ee@euro': 'et_EE.ISO8859-15',
867 'eu': 'eu_ES.ISO8859-1',
868 'eu_es': 'eu_ES.ISO8859-1',
869 'eu_es.iso88591': 'eu_ES.ISO8859-1',
870 'eu_es.iso885915': 'eu_ES.ISO8859-15',
871 'eu_es@euro': 'eu_ES.ISO8859-15',
872 'fa': 'fa_IR.UTF-8',
873 'fa_ir': 'fa_IR.UTF-8',
874 'fa_ir.isiri3342': 'fa_IR.ISIRI-3342',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000875 'fi': 'fi_FI.ISO8859-15',
876 'fi_fi': 'fi_FI.ISO8859-15',
877 'fi_fi.88591': 'fi_FI.ISO8859-1',
878 'fi_fi.iso88591': 'fi_FI.ISO8859-1',
879 'fi_fi.iso885915': 'fi_FI.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000880 'fi_fi.utf8@euro': 'fi_FI.UTF-8',
881 'fi_fi@euro': 'fi_FI.ISO8859-15',
882 'finnish': 'fi_FI.ISO8859-1',
883 'finnish.iso88591': 'fi_FI.ISO8859-1',
884 'fo': 'fo_FO.ISO8859-1',
885 'fo_fo': 'fo_FO.ISO8859-1',
886 'fo_fo.iso88591': 'fo_FO.ISO8859-1',
887 'fo_fo.iso885915': 'fo_FO.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000888 'fo_fo@euro': 'fo_FO.ISO8859-15',
889 'fr': 'fr_FR.ISO8859-1',
890 'fr_be': 'fr_BE.ISO8859-1',
891 'fr_be.88591': 'fr_BE.ISO8859-1',
892 'fr_be.iso88591': 'fr_BE.ISO8859-1',
893 'fr_be.iso885915': 'fr_BE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000894 'fr_be@euro': 'fr_BE.ISO8859-15',
895 'fr_ca': 'fr_CA.ISO8859-1',
896 'fr_ca.88591': 'fr_CA.ISO8859-1',
897 'fr_ca.iso88591': 'fr_CA.ISO8859-1',
898 'fr_ca.iso885915': 'fr_CA.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000899 'fr_ca@euro': 'fr_CA.ISO8859-15',
900 'fr_ch': 'fr_CH.ISO8859-1',
901 'fr_ch.88591': 'fr_CH.ISO8859-1',
902 'fr_ch.iso88591': 'fr_CH.ISO8859-1',
903 'fr_ch.iso885915': 'fr_CH.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000904 'fr_ch@euro': 'fr_CH.ISO8859-15',
905 'fr_fr': 'fr_FR.ISO8859-1',
906 'fr_fr.88591': 'fr_FR.ISO8859-1',
907 'fr_fr.iso88591': 'fr_FR.ISO8859-1',
908 'fr_fr.iso885915': 'fr_FR.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000909 'fr_fr@euro': 'fr_FR.ISO8859-15',
910 'fr_lu': 'fr_LU.ISO8859-1',
911 'fr_lu.88591': 'fr_LU.ISO8859-1',
912 'fr_lu.iso88591': 'fr_LU.ISO8859-1',
913 'fr_lu.iso885915': 'fr_LU.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000914 'fr_lu@euro': 'fr_LU.ISO8859-15',
915 'fran\xe7ais': 'fr_FR.ISO8859-1',
916 'fre_fr': 'fr_FR.ISO8859-1',
917 'fre_fr.8859': 'fr_FR.ISO8859-1',
918 'french': 'fr_FR.ISO8859-1',
919 'french.iso88591': 'fr_CH.ISO8859-1',
920 'french_france': 'fr_FR.ISO8859-1',
921 'french_france.8859': 'fr_FR.ISO8859-1',
922 'ga': 'ga_IE.ISO8859-1',
923 'ga_ie': 'ga_IE.ISO8859-1',
924 'ga_ie.iso88591': 'ga_IE.ISO8859-1',
925 'ga_ie.iso885914': 'ga_IE.ISO8859-14',
926 'ga_ie.iso885915': 'ga_IE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000927 'ga_ie@euro': 'ga_IE.ISO8859-15',
928 'galego': 'gl_ES.ISO8859-1',
929 'galician': 'gl_ES.ISO8859-1',
930 'gd': 'gd_GB.ISO8859-1',
931 'gd_gb': 'gd_GB.ISO8859-1',
932 'gd_gb.iso88591': 'gd_GB.ISO8859-1',
933 'gd_gb.iso885914': 'gd_GB.ISO8859-14',
934 'gd_gb.iso885915': 'gd_GB.ISO8859-15',
935 'gd_gb@euro': 'gd_GB.ISO8859-15',
936 'ger_de': 'de_DE.ISO8859-1',
937 'ger_de.8859': 'de_DE.ISO8859-1',
938 'german': 'de_DE.ISO8859-1',
939 'german.iso88591': 'de_CH.ISO8859-1',
940 'german_germany': 'de_DE.ISO8859-1',
941 'german_germany.8859': 'de_DE.ISO8859-1',
942 'gl': 'gl_ES.ISO8859-1',
943 'gl_es': 'gl_ES.ISO8859-1',
944 'gl_es.iso88591': 'gl_ES.ISO8859-1',
945 'gl_es.iso885915': 'gl_ES.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000946 'gl_es@euro': 'gl_ES.ISO8859-15',
947 'greek': 'el_GR.ISO8859-7',
948 'greek.iso88597': 'el_GR.ISO8859-7',
949 'gv': 'gv_GB.ISO8859-1',
950 'gv_gb': 'gv_GB.ISO8859-1',
951 'gv_gb.iso88591': 'gv_GB.ISO8859-1',
952 'gv_gb.iso885914': 'gv_GB.ISO8859-14',
953 'gv_gb.iso885915': 'gv_GB.ISO8859-15',
954 'gv_gb@euro': 'gv_GB.ISO8859-15',
955 'he': 'he_IL.ISO8859-8',
956 'he_il': 'he_IL.ISO8859-8',
957 'he_il.cp1255': 'he_IL.CP1255',
958 'he_il.iso88598': 'he_IL.ISO8859-8',
959 'he_il.microsoftcp1255': 'he_IL.CP1255',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000960 'hebrew': 'iw_IL.ISO8859-8',
961 'hebrew.iso88598': 'iw_IL.ISO8859-8',
962 'hi': 'hi_IN.ISCII-DEV',
963 'hi_in': 'hi_IN.ISCII-DEV',
964 'hi_in.isciidev': 'hi_IN.ISCII-DEV',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000965 'hr': 'hr_HR.ISO8859-2',
966 'hr_hr': 'hr_HR.ISO8859-2',
967 'hr_hr.iso88592': 'hr_HR.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000968 'hrvatski': 'hr_HR.ISO8859-2',
969 'hu': 'hu_HU.ISO8859-2',
970 'hu_hu': 'hu_HU.ISO8859-2',
971 'hu_hu.iso88592': 'hu_HU.ISO8859-2',
972 'hungarian': 'hu_HU.ISO8859-2',
973 'icelandic': 'is_IS.ISO8859-1',
974 'icelandic.iso88591': 'is_IS.ISO8859-1',
975 'id': 'id_ID.ISO8859-1',
976 'id_id': 'id_ID.ISO8859-1',
977 'in': 'id_ID.ISO8859-1',
978 'in_id': 'id_ID.ISO8859-1',
979 'is': 'is_IS.ISO8859-1',
980 'is_is': 'is_IS.ISO8859-1',
981 'is_is.iso88591': 'is_IS.ISO8859-1',
982 'is_is.iso885915': 'is_IS.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000983 'is_is@euro': 'is_IS.ISO8859-15',
984 'iso-8859-1': 'en_US.ISO8859-1',
985 'iso-8859-15': 'en_US.ISO8859-15',
986 'iso8859-1': 'en_US.ISO8859-1',
987 'iso8859-15': 'en_US.ISO8859-15',
988 'iso_8859_1': 'en_US.ISO8859-1',
989 'iso_8859_15': 'en_US.ISO8859-15',
990 'it': 'it_IT.ISO8859-1',
991 'it_ch': 'it_CH.ISO8859-1',
992 'it_ch.iso88591': 'it_CH.ISO8859-1',
993 'it_ch.iso885915': 'it_CH.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000994 'it_ch@euro': 'it_CH.ISO8859-15',
995 'it_it': 'it_IT.ISO8859-1',
996 'it_it.88591': 'it_IT.ISO8859-1',
997 'it_it.iso88591': 'it_IT.ISO8859-1',
998 'it_it.iso885915': 'it_IT.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +0000999 'it_it@euro': 'it_IT.ISO8859-15',
1000 'italian': 'it_IT.ISO8859-1',
1001 'italian.iso88591': 'it_IT.ISO8859-1',
1002 'iu': 'iu_CA.NUNACOM-8',
1003 'iu_ca': 'iu_CA.NUNACOM-8',
1004 'iu_ca.nunacom8': 'iu_CA.NUNACOM-8',
1005 'iw': 'he_IL.ISO8859-8',
1006 'iw_il': 'he_IL.ISO8859-8',
1007 'iw_il.iso88598': 'he_IL.ISO8859-8',
1008 'ja': 'ja_JP.eucJP',
1009 'ja.jis': 'ja_JP.JIS7',
1010 'ja.sjis': 'ja_JP.SJIS',
1011 'ja_jp': 'ja_JP.eucJP',
1012 'ja_jp.ajec': 'ja_JP.eucJP',
1013 'ja_jp.euc': 'ja_JP.eucJP',
1014 'ja_jp.eucjp': 'ja_JP.eucJP',
1015 'ja_jp.iso-2022-jp': 'ja_JP.JIS7',
1016 'ja_jp.iso2022jp': 'ja_JP.JIS7',
1017 'ja_jp.jis': 'ja_JP.JIS7',
1018 'ja_jp.jis7': 'ja_JP.JIS7',
1019 'ja_jp.mscode': 'ja_JP.SJIS',
1020 'ja_jp.sjis': 'ja_JP.SJIS',
1021 'ja_jp.ujis': 'ja_JP.eucJP',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001022 'japan': 'ja_JP.eucJP',
1023 'japanese': 'ja_JP.eucJP',
1024 'japanese-euc': 'ja_JP.eucJP',
1025 'japanese.euc': 'ja_JP.eucJP',
1026 'japanese.sjis': 'ja_JP.SJIS',
1027 'jp_jp': 'ja_JP.eucJP',
1028 'ka': 'ka_GE.GEORGIAN-ACADEMY',
1029 'ka_ge': 'ka_GE.GEORGIAN-ACADEMY',
1030 'ka_ge.georgianacademy': 'ka_GE.GEORGIAN-ACADEMY',
1031 'ka_ge.georgianps': 'ka_GE.GEORGIAN-PS',
1032 'ka_ge.georgianrs': 'ka_GE.GEORGIAN-ACADEMY',
1033 'kl': 'kl_GL.ISO8859-1',
1034 'kl_gl': 'kl_GL.ISO8859-1',
1035 'kl_gl.iso88591': 'kl_GL.ISO8859-1',
1036 'kl_gl.iso885915': 'kl_GL.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001037 'kl_gl@euro': 'kl_GL.ISO8859-15',
1038 'ko': 'ko_KR.eucKR',
1039 'ko_kr': 'ko_KR.eucKR',
1040 'ko_kr.euc': 'ko_KR.eucKR',
1041 'ko_kr.euckr': 'ko_KR.eucKR',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001042 'korean': 'ko_KR.eucKR',
1043 'korean.euc': 'ko_KR.eucKR',
1044 'kw': 'kw_GB.ISO8859-1',
1045 'kw_gb': 'kw_GB.ISO8859-1',
1046 'kw_gb.iso88591': 'kw_GB.ISO8859-1',
1047 'kw_gb.iso885914': 'kw_GB.ISO8859-14',
1048 'kw_gb.iso885915': 'kw_GB.ISO8859-15',
1049 'kw_gb@euro': 'kw_GB.ISO8859-15',
1050 'lithuanian': 'lt_LT.ISO8859-13',
1051 'lo': 'lo_LA.MULELAO-1',
1052 'lo_la': 'lo_LA.MULELAO-1',
1053 'lo_la.cp1133': 'lo_LA.IBM-CP1133',
1054 'lo_la.ibmcp1133': 'lo_LA.IBM-CP1133',
1055 'lo_la.mulelao1': 'lo_LA.MULELAO-1',
1056 'lt': 'lt_LT.ISO8859-13',
1057 'lt_lt': 'lt_LT.ISO8859-13',
1058 'lt_lt.iso885913': 'lt_LT.ISO8859-13',
1059 'lt_lt.iso88594': 'lt_LT.ISO8859-4',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001060 'lv': 'lv_LV.ISO8859-13',
1061 'lv_lv': 'lv_LV.ISO8859-13',
1062 'lv_lv.iso885913': 'lv_LV.ISO8859-13',
1063 'lv_lv.iso88594': 'lv_LV.ISO8859-4',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001064 'mi': 'mi_NZ.ISO8859-1',
1065 'mi_nz': 'mi_NZ.ISO8859-1',
1066 'mi_nz.iso88591': 'mi_NZ.ISO8859-1',
1067 'mk': 'mk_MK.ISO8859-5',
1068 'mk_mk': 'mk_MK.ISO8859-5',
1069 'mk_mk.cp1251': 'mk_MK.CP1251',
1070 'mk_mk.iso88595': 'mk_MK.ISO8859-5',
1071 'mk_mk.microsoftcp1251': 'mk_MK.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001072 'ms': 'ms_MY.ISO8859-1',
1073 'ms_my': 'ms_MY.ISO8859-1',
1074 'ms_my.iso88591': 'ms_MY.ISO8859-1',
1075 'mt': 'mt_MT.ISO8859-3',
1076 'mt_mt': 'mt_MT.ISO8859-3',
1077 'mt_mt.iso88593': 'mt_MT.ISO8859-3',
1078 'nb': 'nb_NO.ISO8859-1',
1079 'nb_no': 'nb_NO.ISO8859-1',
1080 'nb_no.88591': 'nb_NO.ISO8859-1',
1081 'nb_no.iso88591': 'nb_NO.ISO8859-1',
1082 'nb_no.iso885915': 'nb_NO.ISO8859-15',
1083 'nb_no@euro': 'nb_NO.ISO8859-15',
1084 'nl': 'nl_NL.ISO8859-1',
1085 'nl_be': 'nl_BE.ISO8859-1',
1086 'nl_be.88591': 'nl_BE.ISO8859-1',
1087 'nl_be.iso88591': 'nl_BE.ISO8859-1',
1088 'nl_be.iso885915': 'nl_BE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001089 'nl_be@euro': 'nl_BE.ISO8859-15',
1090 'nl_nl': 'nl_NL.ISO8859-1',
1091 'nl_nl.88591': 'nl_NL.ISO8859-1',
1092 'nl_nl.iso88591': 'nl_NL.ISO8859-1',
1093 'nl_nl.iso885915': 'nl_NL.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001094 'nl_nl@euro': 'nl_NL.ISO8859-15',
1095 'nn': 'nn_NO.ISO8859-1',
1096 'nn_no': 'nn_NO.ISO8859-1',
1097 'nn_no.88591': 'nn_NO.ISO8859-1',
1098 'nn_no.iso88591': 'nn_NO.ISO8859-1',
1099 'nn_no.iso885915': 'nn_NO.ISO8859-15',
1100 'nn_no@euro': 'nn_NO.ISO8859-15',
1101 'no': 'no_NO.ISO8859-1',
1102 'no@nynorsk': 'ny_NO.ISO8859-1',
1103 'no_no': 'no_NO.ISO8859-1',
1104 'no_no.88591': 'no_NO.ISO8859-1',
1105 'no_no.iso88591': 'no_NO.ISO8859-1',
1106 'no_no.iso885915': 'no_NO.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001107 'no_no@euro': 'no_NO.ISO8859-15',
1108 'norwegian': 'no_NO.ISO8859-1',
1109 'norwegian.iso88591': 'no_NO.ISO8859-1',
1110 'ny': 'ny_NO.ISO8859-1',
1111 'ny_no': 'ny_NO.ISO8859-1',
1112 'ny_no.88591': 'ny_NO.ISO8859-1',
1113 'ny_no.iso88591': 'ny_NO.ISO8859-1',
1114 'ny_no.iso885915': 'ny_NO.ISO8859-15',
1115 'ny_no@euro': 'ny_NO.ISO8859-15',
1116 'nynorsk': 'nn_NO.ISO8859-1',
1117 'oc': 'oc_FR.ISO8859-1',
1118 'oc_fr': 'oc_FR.ISO8859-1',
1119 'oc_fr.iso88591': 'oc_FR.ISO8859-1',
1120 'oc_fr.iso885915': 'oc_FR.ISO8859-15',
1121 'oc_fr@euro': 'oc_FR.ISO8859-15',
1122 'pd': 'pd_US.ISO8859-1',
1123 'pd_de': 'pd_DE.ISO8859-1',
1124 'pd_de.iso88591': 'pd_DE.ISO8859-1',
1125 'pd_de.iso885915': 'pd_DE.ISO8859-15',
1126 'pd_de@euro': 'pd_DE.ISO8859-15',
1127 'pd_us': 'pd_US.ISO8859-1',
1128 'pd_us.iso88591': 'pd_US.ISO8859-1',
1129 'pd_us.iso885915': 'pd_US.ISO8859-15',
1130 'pd_us@euro': 'pd_US.ISO8859-15',
1131 'ph': 'ph_PH.ISO8859-1',
1132 'ph_ph': 'ph_PH.ISO8859-1',
1133 'ph_ph.iso88591': 'ph_PH.ISO8859-1',
1134 'pl': 'pl_PL.ISO8859-2',
1135 'pl_pl': 'pl_PL.ISO8859-2',
1136 'pl_pl.iso88592': 'pl_PL.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001137 'polish': 'pl_PL.ISO8859-2',
1138 'portuguese': 'pt_PT.ISO8859-1',
1139 'portuguese.iso88591': 'pt_PT.ISO8859-1',
1140 'portuguese_brazil': 'pt_BR.ISO8859-1',
1141 'portuguese_brazil.8859': 'pt_BR.ISO8859-1',
1142 'posix': 'C',
1143 'posix-utf2': 'C',
1144 'pp': 'pp_AN.ISO8859-1',
1145 'pp_an': 'pp_AN.ISO8859-1',
1146 'pp_an.iso88591': 'pp_AN.ISO8859-1',
1147 'pt': 'pt_PT.ISO8859-1',
1148 'pt_br': 'pt_BR.ISO8859-1',
1149 'pt_br.88591': 'pt_BR.ISO8859-1',
1150 'pt_br.iso88591': 'pt_BR.ISO8859-1',
1151 'pt_br.iso885915': 'pt_BR.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001152 'pt_br@euro': 'pt_BR.ISO8859-15',
1153 'pt_pt': 'pt_PT.ISO8859-1',
1154 'pt_pt.88591': 'pt_PT.ISO8859-1',
1155 'pt_pt.iso88591': 'pt_PT.ISO8859-1',
1156 'pt_pt.iso885915': 'pt_PT.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001157 'pt_pt.utf8@euro': 'pt_PT.UTF-8',
1158 'pt_pt@euro': 'pt_PT.ISO8859-15',
1159 'ro': 'ro_RO.ISO8859-2',
1160 'ro_ro': 'ro_RO.ISO8859-2',
1161 'ro_ro.iso88592': 'ro_RO.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001162 'romanian': 'ro_RO.ISO8859-2',
1163 'ru': 'ru_RU.ISO8859-5',
1164 'ru_ru': 'ru_RU.ISO8859-5',
1165 'ru_ru.cp1251': 'ru_RU.CP1251',
1166 'ru_ru.iso88595': 'ru_RU.ISO8859-5',
1167 'ru_ru.koi8r': 'ru_RU.KOI8-R',
1168 'ru_ru.microsoftcp1251': 'ru_RU.CP1251',
1169 'ru_ua': 'ru_UA.KOI8-U',
1170 'ru_ua.cp1251': 'ru_UA.CP1251',
1171 'ru_ua.koi8u': 'ru_UA.KOI8-U',
1172 'ru_ua.microsoftcp1251': 'ru_UA.CP1251',
1173 'rumanian': 'ro_RO.ISO8859-2',
1174 'russian': 'ru_RU.ISO8859-5',
1175 'se_no': 'se_NO.UTF-8',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001176 'serbocroatian': 'sh_YU.ISO8859-2',
1177 'sh': 'sh_YU.ISO8859-2',
1178 'sh_hr': 'sh_HR.ISO8859-2',
1179 'sh_hr.iso88592': 'sh_HR.ISO8859-2',
1180 'sh_sp': 'sh_YU.ISO8859-2',
1181 'sh_yu': 'sh_YU.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001182 'sk': 'sk_SK.ISO8859-2',
1183 'sk_sk': 'sk_SK.ISO8859-2',
1184 'sk_sk.iso88592': 'sk_SK.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001185 'sl': 'sl_SI.ISO8859-2',
1186 'sl_cs': 'sl_CS.ISO8859-2',
1187 'sl_si': 'sl_SI.ISO8859-2',
1188 'sl_si.iso88592': 'sl_SI.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001189 'slovak': 'sk_SK.ISO8859-2',
1190 'slovene': 'sl_SI.ISO8859-2',
1191 'slovenian': 'sl_SI.ISO8859-2',
1192 'sp': 'sp_YU.ISO8859-5',
1193 'sp_yu': 'sp_YU.ISO8859-5',
1194 'spanish': 'es_ES.ISO8859-1',
1195 'spanish.iso88591': 'es_ES.ISO8859-1',
1196 'spanish_spain': 'es_ES.ISO8859-1',
1197 'spanish_spain.8859': 'es_ES.ISO8859-1',
1198 'sq': 'sq_AL.ISO8859-2',
1199 'sq_al': 'sq_AL.ISO8859-2',
1200 'sq_al.iso88592': 'sq_AL.ISO8859-2',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001201 'sr': 'sr_YU.ISO8859-5',
1202 'sr@cyrillic': 'sr_YU.ISO8859-5',
1203 'sr_sp': 'sr_SP.ISO8859-2',
1204 'sr_yu': 'sr_YU.ISO8859-5',
1205 'sr_yu.cp1251@cyrillic': 'sr_YU.CP1251',
1206 'sr_yu.iso88592': 'sr_YU.ISO8859-2',
1207 'sr_yu.iso88595': 'sr_YU.ISO8859-5',
1208 'sr_yu.iso88595@cyrillic': 'sr_YU.ISO8859-5',
1209 'sr_yu.microsoftcp1251@cyrillic': 'sr_YU.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001210 'sr_yu.utf8@cyrillic': 'sr_YU.UTF-8',
1211 'sr_yu@cyrillic': 'sr_YU.ISO8859-5',
1212 'sv': 'sv_SE.ISO8859-1',
1213 'sv_fi': 'sv_FI.ISO8859-1',
1214 'sv_fi.iso88591': 'sv_FI.ISO8859-1',
1215 'sv_fi.iso885915': 'sv_FI.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001216 'sv_fi@euro': 'sv_FI.ISO8859-15',
1217 'sv_se': 'sv_SE.ISO8859-1',
1218 'sv_se.88591': 'sv_SE.ISO8859-1',
1219 'sv_se.iso88591': 'sv_SE.ISO8859-1',
1220 'sv_se.iso885915': 'sv_SE.ISO8859-15',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001221 'sv_se@euro': 'sv_SE.ISO8859-15',
1222 'swedish': 'sv_SE.ISO8859-1',
1223 'swedish.iso88591': 'sv_SE.ISO8859-1',
1224 'ta': 'ta_IN.TSCII-0',
1225 'ta_in': 'ta_IN.TSCII-0',
1226 'ta_in.tscii': 'ta_IN.TSCII-0',
1227 'ta_in.tscii0': 'ta_IN.TSCII-0',
1228 'tg': 'tg_TJ.KOI8-C',
1229 'tg_tj': 'tg_TJ.KOI8-C',
1230 'tg_tj.koi8c': 'tg_TJ.KOI8-C',
1231 'th': 'th_TH.ISO8859-11',
1232 'th_th': 'th_TH.ISO8859-11',
1233 'th_th.iso885911': 'th_TH.ISO8859-11',
1234 'th_th.tactis': 'th_TH.TIS620',
1235 'th_th.tis620': 'th_TH.TIS620',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001236 'thai': 'th_TH.ISO8859-11',
1237 'tl': 'tl_PH.ISO8859-1',
1238 'tl_ph': 'tl_PH.ISO8859-1',
1239 'tl_ph.iso88591': 'tl_PH.ISO8859-1',
1240 'tr': 'tr_TR.ISO8859-9',
1241 'tr_tr': 'tr_TR.ISO8859-9',
1242 'tr_tr.iso88599': 'tr_TR.ISO8859-9',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001243 'tt': 'tt_RU.TATAR-CYR',
1244 'tt_ru': 'tt_RU.TATAR-CYR',
1245 'tt_ru.koi8c': 'tt_RU.KOI8-C',
1246 'tt_ru.tatarcyr': 'tt_RU.TATAR-CYR',
1247 'turkish': 'tr_TR.ISO8859-9',
1248 'turkish.iso88599': 'tr_TR.ISO8859-9',
1249 'uk': 'uk_UA.KOI8-U',
1250 'uk_ua': 'uk_UA.KOI8-U',
1251 'uk_ua.cp1251': 'uk_UA.CP1251',
1252 'uk_ua.iso88595': 'uk_UA.ISO8859-5',
1253 'uk_ua.koi8u': 'uk_UA.KOI8-U',
1254 'uk_ua.microsoftcp1251': 'uk_UA.CP1251',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001255 'univ': 'en_US.utf',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001256 'universal': 'en_US.utf',
1257 'universal.utf8@ucs4': 'en_US.UTF-8',
1258 'ur': 'ur_PK.CP1256',
1259 'ur_pk': 'ur_PK.CP1256',
1260 'ur_pk.cp1256': 'ur_PK.CP1256',
1261 'ur_pk.microsoftcp1256': 'ur_PK.CP1256',
1262 'uz': 'uz_UZ.UTF-8',
1263 'uz_uz': 'uz_UZ.UTF-8',
1264 'vi': 'vi_VN.TCVN',
1265 'vi_vn': 'vi_VN.TCVN',
1266 'vi_vn.tcvn': 'vi_VN.TCVN',
1267 'vi_vn.tcvn5712': 'vi_VN.TCVN',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001268 'vi_vn.viscii': 'vi_VN.VISCII',
1269 'vi_vn.viscii111': 'vi_VN.VISCII',
1270 'wa': 'wa_BE.ISO8859-1',
1271 'wa_be': 'wa_BE.ISO8859-1',
1272 'wa_be.iso88591': 'wa_BE.ISO8859-1',
1273 'wa_be.iso885915': 'wa_BE.ISO8859-15',
1274 'wa_be@euro': 'wa_BE.ISO8859-15',
1275 'yi': 'yi_US.CP1255',
1276 'yi_us': 'yi_US.CP1255',
1277 'yi_us.cp1255': 'yi_US.CP1255',
1278 'yi_us.microsoftcp1255': 'yi_US.CP1255',
1279 'zh': 'zh_CN.eucCN',
1280 'zh_cn': 'zh_CN.gb2312',
1281 'zh_cn.big5': 'zh_TW.big5',
1282 'zh_cn.euc': 'zh_CN.eucCN',
1283 'zh_cn.gb18030': 'zh_CN.gb18030',
1284 'zh_cn.gb2312': 'zh_CN.gb2312',
1285 'zh_cn.gbk': 'zh_CN.gbk',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001286 'zh_hk': 'zh_HK.big5hkscs',
1287 'zh_hk.big5': 'zh_HK.big5',
1288 'zh_hk.big5hkscs': 'zh_HK.big5hkscs',
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001289 'zh_tw': 'zh_TW.big5',
1290 'zh_tw.big5': 'zh_TW.big5',
1291 'zh_tw.euc': 'zh_TW.eucTW',
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001292}
1293
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001294#
Georg Brandlb709c2c2006-01-20 09:07:35 +00001295# This maps Windows language identifiers to locale strings.
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001296#
Tim Peters777f1082006-01-20 20:03:24 +00001297# This list has been updated from
Georg Brandlb709c2c2006-01-20 09:07:35 +00001298# http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_238z.asp
1299# to include every locale up to Windows XP.
Fredrik Lundh37a09822002-10-19 20:19:10 +00001300#
Georg Brandl5035c1c2006-01-20 13:38:26 +00001301# NOTE: this mapping is incomplete. If your language is missing, please
1302# submit a bug report to Python bug manager, which you can find via:
1303# http://www.python.org/dev/
1304# Make sure you include the missing language identifier and the suggested
1305# locale code.
1306#
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001307
1308windows_locale = {
Georg Brandlb709c2c2006-01-20 09:07:35 +00001309 0x0436: "af_ZA", # Afrikaans
1310 0x041c: "sq_AL", # Albanian
1311 0x0401: "ar_SA", # Arabic - Saudi Arabia
1312 0x0801: "ar_IQ", # Arabic - Iraq
1313 0x0c01: "ar_EG", # Arabic - Egypt
1314 0x1001: "ar_LY", # Arabic - Libya
1315 0x1401: "ar_DZ", # Arabic - Algeria
1316 0x1801: "ar_MA", # Arabic - Morocco
1317 0x1c01: "ar_TN", # Arabic - Tunisia
1318 0x2001: "ar_OM", # Arabic - Oman
1319 0x2401: "ar_YE", # Arabic - Yemen
1320 0x2801: "ar_SY", # Arabic - Syria
1321 0x2c01: "ar_JO", # Arabic - Jordan
1322 0x3001: "ar_LB", # Arabic - Lebanon
1323 0x3401: "ar_KW", # Arabic - Kuwait
1324 0x3801: "ar_AE", # Arabic - United Arab Emirates
1325 0x3c01: "ar_BH", # Arabic - Bahrain
1326 0x4001: "ar_QA", # Arabic - Qatar
1327 0x042b: "hy_AM", # Armenian
1328 0x042c: "az_AZ", # Azeri Latin
1329 0x082c: "az_AZ", # Azeri - Cyrillic
1330 0x042d: "eu_ES", # Basque
1331 0x0423: "be_BY", # Belarusian
1332 0x0445: "bn_IN", # Begali
1333 0x201a: "bs_BA", # Bosnian
1334 0x141a: "bs_BA", # Bosnian - Cyrillic
1335 0x047e: "br_FR", # Breton - France
1336 0x0402: "bg_BG", # Bulgarian
1337 0x0403: "ca_ES", # Catalan
1338 0x0004: "zh_CHS",# Chinese - Simplified
1339 0x0404: "zh_TW", # Chinese - Taiwan
1340 0x0804: "zh_CN", # Chinese - PRC
1341 0x0c04: "zh_HK", # Chinese - Hong Kong S.A.R.
1342 0x1004: "zh_SG", # Chinese - Singapore
1343 0x1404: "zh_MO", # Chinese - Macao S.A.R.
1344 0x7c04: "zh_CHT",# Chinese - Traditional
1345 0x041a: "hr_HR", # Croatian
1346 0x101a: "hr_BA", # Croatian - Bosnia
1347 0x0405: "cs_CZ", # Czech
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001348 0x0406: "da_DK", # Danish
Georg Brandlb709c2c2006-01-20 09:07:35 +00001349 0x048c: "gbz_AF",# Dari - Afghanistan
1350 0x0465: "div_MV",# Divehi - Maldives
1351 0x0413: "nl_NL", # Dutch - The Netherlands
1352 0x0813: "nl_BE", # Dutch - Belgium
1353 0x0409: "en_US", # English - United States
1354 0x0809: "en_GB", # English - United Kingdom
1355 0x0c09: "en_AU", # English - Australia
1356 0x1009: "en_CA", # English - Canada
1357 0x1409: "en_NZ", # English - New Zealand
1358 0x1809: "en_IE", # English - Ireland
1359 0x1c09: "en_ZA", # English - South Africa
1360 0x2009: "en_JA", # English - Jamaica
1361 0x2409: "en_CB", # English - Carribbean
1362 0x2809: "en_BZ", # English - Belize
1363 0x2c09: "en_TT", # English - Trinidad
1364 0x3009: "en_ZW", # English - Zimbabwe
1365 0x3409: "en_PH", # English - Phillippines
1366 0x0425: "et_EE", # Estonian
1367 0x0438: "fo_FO", # Faroese
1368 0x0464: "fil_PH",# Filipino
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001369 0x040b: "fi_FI", # Finnish
Georg Brandlb709c2c2006-01-20 09:07:35 +00001370 0x040c: "fr_FR", # French - France
1371 0x080c: "fr_BE", # French - Belgium
1372 0x0c0c: "fr_CA", # French - Canada
1373 0x100c: "fr_CH", # French - Switzerland
1374 0x140c: "fr_LU", # French - Luxembourg
1375 0x180c: "fr_MC", # French - Monaco
1376 0x0462: "fy_NL", # Frisian - Netherlands
1377 0x0456: "gl_ES", # Galician
1378 0x0437: "ka_GE", # Georgian
1379 0x0407: "de_DE", # German - Germany
1380 0x0807: "de_CH", # German - Switzerland
1381 0x0c07: "de_AT", # German - Austria
1382 0x1007: "de_LU", # German - Luxembourg
1383 0x1407: "de_LI", # German - Liechtenstein
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001384 0x0408: "el_GR", # Greek
Georg Brandlb709c2c2006-01-20 09:07:35 +00001385 0x0447: "gu_IN", # Gujarati
1386 0x040d: "he_IL", # Hebrew
1387 0x0439: "hi_IN", # Hindi
1388 0x040e: "hu_HU", # Hungarian
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001389 0x040f: "is_IS", # Icelandic
Georg Brandlb709c2c2006-01-20 09:07:35 +00001390 0x0421: "id_ID", # Indonesian
1391 0x045d: "iu_CA", # Inuktitut
1392 0x085d: "iu_CA", # Inuktitut - Latin
1393 0x083c: "ga_IE", # Irish - Ireland
1394 0x0434: "xh_ZA", # Xhosa - South Africa
1395 0x0435: "zu_ZA", # Zulu
1396 0x0410: "it_IT", # Italian - Italy
1397 0x0810: "it_CH", # Italian - Switzerland
1398 0x0411: "ja_JP", # Japanese
1399 0x044b: "kn_IN", # Kannada - India
1400 0x043f: "kk_KZ", # Kazakh
1401 0x0457: "kok_IN",# Konkani
1402 0x0412: "ko_KR", # Korean
1403 0x0440: "ky_KG", # Kyrgyz
1404 0x0426: "lv_LV", # Latvian
1405 0x0427: "lt_LT", # Lithuanian
1406 0x046e: "lb_LU", # Luxembourgish
1407 0x042f: "mk_MK", # FYRO Macedonian
1408 0x043e: "ms_MY", # Malay - Malaysia
1409 0x083e: "ms_BN", # Malay - Brunei
1410 0x044c: "ml_IN", # Malayalam - India
1411 0x043a: "mt_MT", # Maltese
1412 0x0481: "mi_NZ", # Maori
1413 0x047a: "arn_CL",# Mapudungun
1414 0x044e: "mr_IN", # Marathi
1415 0x047c: "moh_CA",# Mohawk - Canada
1416 0x0450: "mn_MN", # Mongolian
1417 0x0461: "ne_NP", # Nepali
1418 0x0414: "nb_NO", # Norwegian - Bokmal
1419 0x0814: "nn_NO", # Norwegian - Nynorsk
1420 0x0482: "oc_FR", # Occitan - France
1421 0x0448: "or_IN", # Oriya - India
1422 0x0463: "ps_AF", # Pashto - Afghanistan
1423 0x0429: "fa_IR", # Persian
1424 0x0415: "pl_PL", # Polish
1425 0x0416: "pt_BR", # Portuguese - Brazil
1426 0x0816: "pt_PT", # Portuguese - Portugal
1427 0x0446: "pa_IN", # Punjabi
1428 0x046b: "quz_BO",# Quechua (Bolivia)
1429 0x086b: "quz_EC",# Quechua (Ecuador)
1430 0x0c6b: "quz_PE",# Quechua (Peru)
1431 0x0418: "ro_RO", # Romanian - Romania
1432 0x0417: "rm_CH", # Raeto-Romanese
1433 0x0419: "ru_RU", # Russian
1434 0x243b: "smn_FI",# Sami Finland
1435 0x103b: "smj_NO",# Sami Norway
1436 0x143b: "smj_SE",# Sami Sweden
1437 0x043b: "se_NO", # Sami Northern Norway
1438 0x083b: "se_SE", # Sami Northern Sweden
1439 0x0c3b: "se_FI", # Sami Northern Finland
1440 0x203b: "sms_FI",# Sami Skolt
1441 0x183b: "sma_NO",# Sami Southern Norway
1442 0x1c3b: "sma_SE",# Sami Southern Sweden
1443 0x044f: "sa_IN", # Sanskrit
1444 0x0c1a: "sr_SP", # Serbian - Cyrillic
1445 0x1c1a: "sr_BA", # Serbian - Bosnia Cyrillic
1446 0x081a: "sr_SP", # Serbian - Latin
1447 0x181a: "sr_BA", # Serbian - Bosnia Latin
1448 0x046c: "ns_ZA", # Northern Sotho
1449 0x0432: "tn_ZA", # Setswana - Southern Africa
1450 0x041b: "sk_SK", # Slovak
1451 0x0424: "sl_SI", # Slovenian
1452 0x040a: "es_ES", # Spanish - Spain
1453 0x080a: "es_MX", # Spanish - Mexico
1454 0x0c0a: "es_ES", # Spanish - Spain (Modern)
1455 0x100a: "es_GT", # Spanish - Guatemala
1456 0x140a: "es_CR", # Spanish - Costa Rica
1457 0x180a: "es_PA", # Spanish - Panama
1458 0x1c0a: "es_DO", # Spanish - Dominican Republic
1459 0x200a: "es_VE", # Spanish - Venezuela
1460 0x240a: "es_CO", # Spanish - Colombia
1461 0x280a: "es_PE", # Spanish - Peru
1462 0x2c0a: "es_AR", # Spanish - Argentina
1463 0x300a: "es_EC", # Spanish - Ecuador
1464 0x340a: "es_CL", # Spanish - Chile
1465 0x380a: "es_UR", # Spanish - Uruguay
1466 0x3c0a: "es_PY", # Spanish - Paraguay
1467 0x400a: "es_BO", # Spanish - Bolivia
1468 0x440a: "es_SV", # Spanish - El Salvador
1469 0x480a: "es_HN", # Spanish - Honduras
1470 0x4c0a: "es_NI", # Spanish - Nicaragua
1471 0x500a: "es_PR", # Spanish - Puerto Rico
1472 0x0441: "sw_KE", # Swahili
1473 0x041d: "sv_SE", # Swedish - Sweden
1474 0x081d: "sv_FI", # Swedish - Finland
1475 0x045a: "syr_SY",# Syriac
1476 0x0449: "ta_IN", # Tamil
1477 0x0444: "tt_RU", # Tatar
1478 0x044a: "te_IN", # Telugu
1479 0x041e: "th_TH", # Thai
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001480 0x041f: "tr_TR", # Turkish
Georg Brandlb709c2c2006-01-20 09:07:35 +00001481 0x0422: "uk_UA", # Ukrainian
1482 0x0420: "ur_PK", # Urdu
1483 0x0820: "ur_IN", # Urdu - India
1484 0x0443: "uz_UZ", # Uzbek - Latin
1485 0x0843: "uz_UZ", # Uzbek - Cyrillic
1486 0x042a: "vi_VN", # Vietnamese
1487 0x0452: "cy_GB", # Welsh
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001488}
1489
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001490def _print_locale():
1491
1492 """ Test function.
1493 """
1494 categories = {}
1495 def _init_categories(categories=categories):
1496 for k,v in globals().items():
1497 if k[:3] == 'LC_':
1498 categories[k] = v
1499 _init_categories()
1500 del categories['LC_ALL']
1501
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001502 print 'Locale defaults as determined by getdefaultlocale():'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001503 print '-'*72
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001504 lang, enc = getdefaultlocale()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001505 print 'Language: ', lang or '(undefined)'
1506 print 'Encoding: ', enc or '(undefined)'
1507 print
1508
1509 print 'Locale settings on startup:'
1510 print '-'*72
1511 for name,category in categories.items():
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001512 print name, '...'
1513 lang, enc = getlocale(category)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001514 print ' Language: ', lang or '(undefined)'
1515 print ' Encoding: ', enc or '(undefined)'
1516 print
1517
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001518 print
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001519 print 'Locale settings after calling resetlocale():'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001520 print '-'*72
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001521 resetlocale()
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001522 for name,category in categories.items():
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001523 print name, '...'
1524 lang, enc = getlocale(category)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001525 print ' Language: ', lang or '(undefined)'
1526 print ' Encoding: ', enc or '(undefined)'
1527 print
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001528
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001529 try:
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001530 setlocale(LC_ALL, "")
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001531 except:
1532 print 'NOTE:'
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001533 print 'setlocale(LC_ALL, "") does not support the default locale'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001534 print 'given in the OS environment variables.'
1535 else:
1536 print
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001537 print 'Locale settings after calling setlocale(LC_ALL, ""):'
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001538 print '-'*72
1539 for name,category in categories.items():
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001540 print name, '...'
1541 lang, enc = getlocale(category)
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001542 print ' Language: ', lang or '(undefined)'
1543 print ' Encoding: ', enc or '(undefined)'
1544 print
Fredrik Lundh6c86b992000-07-09 17:12:58 +00001545
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001546###
Guido van Rossumeef1d4e1997-11-19 19:01:43 +00001547
Tim Peters1baf8292001-01-24 10:13:46 +00001548try:
1549 LC_MESSAGES
Skip Montanaro0897f0c2002-03-25 21:40:36 +00001550except NameError:
Tim Peters1baf8292001-01-24 10:13:46 +00001551 pass
1552else:
1553 __all__.append("LC_MESSAGES")
1554
Guido van Rossumeef1d4e1997-11-19 19:01:43 +00001555if __name__=='__main__':
Marc-André Lemburg5431bc32000-06-07 09:11:40 +00001556 print 'Locale aliasing:'
1557 print
1558 _print_locale()
1559 print
1560 print 'Number formatting:'
1561 print
1562 _test()