doc: Update references to 'cola.gitcmd'
[git-cola.git] / cola / i18n.py
blob732618296d029e136fa3c2ebaa306b19b22b036d
1 """i18n and l10n support for git-cola"""
3 import gettext as _gettext
4 import os
5 import sys
7 from cola import resources
9 _null_translation = _gettext.NullTranslations()
10 _translation = _null_translation
13 def gettext(s):
14 return _translation.ugettext(s)
17 def ngettext(s, p, n):
18 return _translation.ungettext(s, p, n)
21 def N_(s):
22 return s
25 def install():
26 global _translation
27 if sys.platform == 'win32':
28 _check_win32_locale()
29 _translation = _gettext.translation('git-cola',
30 localedir=_get_locale_dir(),
31 fallback=True)
33 def uninstall():
34 global _translation
35 _translation = _null_translation
38 def _get_locale_dir():
39 return resources.prefix('share', 'locale')
42 def _check_win32_locale():
43 for i in ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'):
44 if os.environ.get(i):
45 break
46 else:
47 lang = None
48 import locale
49 try:
50 import ctypes
51 except ImportError:
52 # use only user's default locale
53 lang = locale.getdefaultlocale()[0]
54 else:
55 # using ctypes to determine all locales
56 lcid_user = ctypes.windll.kernel32.GetUserDefaultLCID()
57 lcid_system = ctypes.windll.kernel32.GetSystemDefaultLCID()
58 if lcid_user != lcid_system:
59 lcid = [lcid_user, lcid_system]
60 else:
61 lcid = [lcid_user]
62 lang = [locale.windows_locale.get(i) for i in lcid]
63 lang = ':'.join([i for i in lang if i])
64 # set lang code for gettext
65 if lang:
66 os.environ['LANGUAGE'] = lang
69 # additional strings for translation
70 if 0:
71 # file kinds
72 N_('file')
73 N_('directory')
74 N_('symlink')
75 # bugs status
76 N_('fixed')
77 # qcat titles for various file types
78 N_('View text file')
79 N_('View image file')
80 N_('View binary file')
81 N_('View symlink')
82 N_('View directory')
84 N_("No changes selected to commit")
85 N_("No changes selected to revert")