qt: Make the 'text' field optional in create_button()
[git-cola.git] / cola / i18n.py
blob9f1b03321e2d4c94531c97239a5abae2254477e7
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(locale):
26 global _translation
27 if sys.platform == 'win32':
28 _check_win32_locale()
29 if locale:
30 os.environ['LANG'] = locale
31 os.environ['LC_MESSAGES'] = locale
32 _gettext.textdomain('messages')
33 _translation = _gettext.translation('git-cola',
34 localedir=_get_locale_dir(),
35 fallback=True)
37 def uninstall():
38 global _translation
39 _translation = _null_translation
42 def _get_locale_dir():
43 return resources.prefix('share', 'locale')
46 def _check_win32_locale():
47 for i in ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'):
48 if os.environ.get(i):
49 break
50 else:
51 lang = None
52 import locale
53 try:
54 import ctypes
55 except ImportError:
56 # use only user's default locale
57 lang = locale.getdefaultlocale()[0]
58 else:
59 # using ctypes to determine all locales
60 lcid_user = ctypes.windll.kernel32.GetUserDefaultLCID()
61 lcid_system = ctypes.windll.kernel32.GetSystemDefaultLCID()
62 if lcid_user != lcid_system:
63 lcid = [lcid_user, lcid_system]
64 else:
65 lcid = [lcid_user]
66 lang = [locale.windows_locale.get(i) for i in lcid]
67 lang = ':'.join([i for i in lang if i])
68 # set lang code for gettext
69 if lang:
70 os.environ['LANGUAGE'] = lang
73 # additional strings for translation
74 if 0:
75 # file kinds
76 N_('file')
77 N_('directory')
78 N_('symlink')
79 # bugs status
80 N_('fixed')
81 # qcat titles for various file types
82 N_('View text file')
83 N_('View image file')
84 N_('View binary file')
85 N_('View symlink')
86 N_('View directory')
88 N_("No changes selected to commit")
89 N_("No changes selected to revert")