-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_test.py
51 lines (38 loc) · 1.08 KB
/
simple_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""A simple test of gettext support on Windows."""
LANG_ENV_VARS = ["LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG"]
import locale, os
def check_os():
if os.name != "nt":
import warnings
warnings.warn(
"This test is only intended for Windows NT-based systems.")
def print_locale():
for key in LANG_ENV_VARS:
print key, str(os.environ.get(key))
def is_locale_set():
for key in LANG_ENV_VARS:
if key in os.environ:
return True
return False
def init_locale():
# getdefaultlocale returns (locale, encoding). We only need the first.
def_locale = locale.getdefaultlocale()[0]
os.environ["LANG"] = def_locale
def init_gettext():
import gettext
gettext.install("test", localedir="locale", unicode=True)
def main():
check_os()
print "Current locale:"
print_locale()
print
if not is_locale_set():
init_locale()
print "Adjusted locale:"
print_locale()
print
init_gettext()
print _(u"Hello world!")
if __name__ == "__main__":
main()