210b53cd5179f6ed92df85cafd68812086a53d23
[mussorgsky] / src / i18n.py
1 import os, sys
2 import locale
3 import gettext
4
5 # Change this variable to your app name!
6 #  The translation files will be under 
7 #  @LOCALE_DIR@/@LANGUAGE@/LC_MESSAGES/@APP_NAME@.mo
8 #
9 APP_NAME = "mussorgsky"
10
11 # This is ok for maemo. Not sure in a regular desktop:
12 #
13 APP_DIR = os.path.join (sys.prefix,
14                         'share')
15 LOCALE_DIR = os.path.join(APP_DIR, 'locale')
16
17
18 # Now we need to choose the language. We will provide a list, and gettext
19 # will use the first translation available in the list
20 #
21 #  In maemo it is in the LANG environment variable
22 #  (on desktop is usually LANGUAGES)
23 #
24 DEFAULT_LANGUAGES = os.environ.get('LANG', '').split(':')
25 DEFAULT_LANGUAGES += ['en_US']
26
27 # Try to get the languages from the default locale
28 lc, encoding = locale.getdefaultlocale()
29 if lc:
30     languages = [lc]
31
32 # Concat all languages (env + default locale), 
33 #  and here we have the languages and location of the translations
34 #
35 languages += DEFAULT_LANGUAGES
36 mo_location = LOCALE_DIR
37
38 # Lets tell those details to gettext
39 #  (nothing to change here for you)
40 gettext.install (True)
41 gettext.bindtextdomain (APP_NAME,
42                         mo_location)
43 gettext.textdomain (APP_NAME)
44 language = gettext.translation (APP_NAME,
45                                 mo_location,
46                                 languages = languages,
47                                 fallback = True)
48
49 # And now in your modules you can do:
50 #
51 # import i18n
52 # _ = i18n.language.gettext
53 #
54