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