1 """i18n and l10n support for git-cola"""
2 from __future__
import division
, absolute_import
, unicode_literals
3 import gettext
as _gettext
9 from . import resources
11 _null_translation
= _gettext
.NullTranslations()
12 _translation
= _null_translation
17 txt
= _translation
.ugettext(s
)
18 except AttributeError:
20 _translation
.ugettext
= _translation
.gettext
21 txt
= _translation
.gettext(s
)
22 if txt
[-6:-4] == '@@': # handle @@verb / @@noun
27 def ngettext(s
, p
, n
):
29 txt
= _translation
.ungettext(s
, p
, n
)
30 except AttributeError:
32 _translation
.ungettext
= _translation
.ngettext
33 txt
= _translation
.ngettext(s
, p
, n
)
42 # pylint: disable=global-statement
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(),
58 # pylint: disable=global-statement
60 _translation
= _null_translation
63 def _get_locale_dir():
64 return resources
.prefix('share', 'locale')
67 def _install_custom_language():
68 """Allow a custom language to be set in ~/.config/git-cola/language"""
69 lang_file
= resources
.config_home('language')
70 if not core
.exists(lang_file
):
73 lang
= core
.read(lang_file
).strip()
74 except (OSError, IOError):
77 compat
.setenv('LANGUAGE', lang
)
80 def _check_win32_locale():
81 for i
in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
90 # use only user's default locale
91 lang
= locale
.getdefaultlocale()[0]
93 # using ctypes to determine all locales
94 lcid_user
= ctypes
.windll
.kernel32
.GetUserDefaultLCID()
95 lcid_system
= ctypes
.windll
.kernel32
.GetSystemDefaultLCID()
96 if lcid_user
!= lcid_system
:
97 lcid
= [lcid_user
, lcid_system
]
100 lang
= [locale
.windows_locale
.get(i
) for i
in lcid
]
101 lang
= ':'.join([i
for i
in lang
if i
])
102 # set lang code for gettext
104 compat
.setenv('LANGUAGE', lang
)