1 """i18n and l10n support for git-cola"""
2 from __future__
import division
, absolute_import
, unicode_literals
4 import gettext
as _gettext
10 from . import resources
12 _null_translation
= _gettext
.NullTranslations()
13 _translation
= _null_translation
18 txt
= _translation
.ugettext(s
)
19 except AttributeError:
21 _translation
.ugettext
= _translation
.gettext
22 txt
= _translation
.gettext(s
)
23 if txt
[-6:-4] == '@@': # handle @@verb / @@noun
28 def ngettext(s
, p
, n
):
30 txt
= _translation
.ungettext(s
, p
, n
)
31 except AttributeError:
33 _translation
.ungettext
= _translation
.ngettext
34 txt
= _translation
.ngettext(s
, p
, n
)
44 if sys
.platform
== 'win32':
47 compat
.setenv('LANGUAGE', locale
)
48 compat
.setenv('LANG', locale
)
49 compat
.setenv('LC_MESSAGES', locale
)
50 _install_custom_language()
51 _gettext
.textdomain('messages')
52 _translation
= _gettext
.translation('git-cola',
53 localedir
=_get_locale_dir(),
59 _translation
= _null_translation
62 def _get_locale_dir():
63 return resources
.prefix('share', 'locale')
66 def _install_custom_language():
67 """Allow a custom language to be set in ~/.config/git-cola/language"""
68 lang_file
= resources
.config_home('language')
69 if not core
.exists(lang_file
):
72 lang
= core
.read(lang_file
).strip()
76 compat
.setenv('LANGUAGE', lang
)
79 def _check_win32_locale():
80 for i
in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
89 # use only user's default locale
90 lang
= locale
.getdefaultlocale()[0]
92 # using ctypes to determine all locales
93 lcid_user
= ctypes
.windll
.kernel32
.GetUserDefaultLCID()
94 lcid_system
= ctypes
.windll
.kernel32
.GetSystemDefaultLCID()
95 if lcid_user
!= lcid_system
:
96 lcid
= [lcid_user
, lcid_system
]
99 lang
= [locale
.windows_locale
.get(i
) for i
in lcid
]
100 lang
= ':'.join([i
for i
in lang
if i
])
101 # set lang code for gettext
103 compat
.setenv('LANGUAGE', lang
)