4 # |
4 # |
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 import encoding |
8 import encoding |
9 import gettext, sys, os |
9 import gettext, sys, os, locale |
10 |
10 |
11 # modelled after templater.templatepath: |
11 # modelled after templater.templatepath: |
12 if getattr(sys, 'frozen', None) is not None: |
12 if getattr(sys, 'frozen', None) is not None: |
13 module = sys.executable |
13 module = sys.executable |
14 else: |
14 else: |
18 for dir in ('.', '..'): |
18 for dir in ('.', '..'): |
19 localedir = os.path.join(base, dir, 'locale') |
19 localedir = os.path.join(base, dir, 'locale') |
20 if os.path.isdir(localedir): |
20 if os.path.isdir(localedir): |
21 break |
21 break |
22 |
22 |
23 t = gettext.translation('hg', localedir, fallback=True) |
23 _languages = None |
|
24 if (os.name == 'nt' |
|
25 and 'LANGUAGE' not in os.environ |
|
26 and 'LC_ALL' not in os.environ |
|
27 and 'LC_MESSAGES' not in os.environ |
|
28 and 'LANG' not in os.environ): |
|
29 # Try to detect UI language by "User Interface Language Management" API |
|
30 # if no locale variables are set. Note that locale.getdefaultlocale() |
|
31 # uses GetLocaleInfo(), which may be different from UI language. |
|
32 # (See http://msdn.microsoft.com/en-us/library/dd374098(v=VS.85).aspx ) |
|
33 try: |
|
34 import ctypes |
|
35 langid = ctypes.windll.kernel32.GetUserDefaultUILanguage() |
|
36 _languages = [locale.windows_locale[langid]] |
|
37 except (ImportError, AttributeError, KeyError): |
|
38 # ctypes not found or unknown langid |
|
39 pass |
|
40 |
|
41 t = gettext.translation('hg', localedir, _languages, fallback=True) |
24 |
42 |
25 def gettext(message): |
43 def gettext(message): |
26 """Translate message. |
44 """Translate message. |
27 |
45 |
28 The message is looked up in the catalog to get a Unicode string, |
46 The message is looked up in the catalog to get a Unicode string, |