1 """i18n and l10n support for git-cola"""
3 import gettext
as _gettext
7 from cola
import compat
9 from cola
import resources
11 _null_translation
= _gettext
.NullTranslations()
12 _translation
= _null_translation
16 txt
= _translation
.ugettext(s
)
17 if txt
[-6:-4] == '@@': # handle @@verb / @@noun
22 def ngettext(s
, p
, n
):
23 return _translation
.ungettext(s
, p
, n
)
32 if sys
.platform
== 'win32':
35 compat
.setenv('LANG', locale
)
36 compat
.setenv('LC_MESSAGES', locale
)
37 _install_custom_language()
38 _gettext
.textdomain('messages')
39 _translation
= _gettext
.translation('git-cola',
40 localedir
=_get_locale_dir(),
45 _translation
= _null_translation
48 def _get_locale_dir():
49 return resources
.prefix('share', 'locale')
52 def _install_custom_language():
53 """Allow a custom language to be set in ~/.config/git-cola/language"""
54 lang_file
= resources
.config_home('language')
55 if not core
.exists(lang_file
):
58 lang
= core
.read(lang_file
).strip()
62 compat
.setenv('LANGUAGE', lang
)
65 def _check_win32_locale():
66 for i
in ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'):
75 # use only user's default locale
76 lang
= locale
.getdefaultlocale()[0]
78 # using ctypes to determine all locales
79 lcid_user
= ctypes
.windll
.kernel32
.GetUserDefaultLCID()
80 lcid_system
= ctypes
.windll
.kernel32
.GetSystemDefaultLCID()
81 if lcid_user
!= lcid_system
:
82 lcid
= [lcid_user
, lcid_system
]
85 lang
= [locale
.windows_locale
.get(i
) for i
in lcid
]
86 lang
= ':'.join([i
for i
in lang
if i
])
87 # set lang code for gettext
89 compat
.setenv('LANGUAGE', lang
)