aad683d86d9d06e5c6c2a8186189c7a15b8f32d5
[mussorgsky] / src / i18n.py
1 import os, sys
2 import locale
3 import gettext
4
5 APP_NAME = "mussorgsky"
6
7 APP_DIR = os.path.join (sys.prefix,
8                         'share')
9
10 LOCALE_DIR = os.path.join(APP_DIR, 'locale')
11
12 DEFAULT_LANGUAGES = os.environ.get('LANG', '').split(':')
13 DEFAULT_LANGUAGES += ['en_US']
14
15 # Init i18n stuff
16 lc, encoding = locale.getdefaultlocale()
17
18 if lc:
19     languages = [lc]
20
21 # DEBUG: to test translation without installation
22 #languages = ["es_ES"]
23 #mo_location = os.path.realpath(os.path.dirname(sys.argv[1]))
24 #print languages
25
26 languages += DEFAULT_LANGUAGES
27 mo_location = LOCALE_DIR
28
29 #print "Loading translations from: ", mo_location
30
31 gettext.install (True)
32 gettext.bindtextdomain (APP_NAME,
33                         mo_location)
34 gettext.textdomain (APP_NAME)
35 language = gettext.translation (APP_NAME,
36                                 mo_location,
37                                 languages = languages,
38                                 fallback = True)