Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings MussOrgsky: Music Organizer for Maemo
Summary Forums Tracker Lists Tasks Docs News SCM Files
1 import os, sys
2 import locale
3 import gettext
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"
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')
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']
27 # Try to get the languages from the default locale
28 languages = []
29 lc, encoding = locale.getdefaultlocale()
30 if lc:
31     languages = [lc]
33 # Concat all languages (env + default locale), 
34 #  and here we have the languages and location of the translations
35 #
36 languages += DEFAULT_LANGUAGES
37 mo_location = LOCALE_DIR
39 # Lets tell those details to gettext
40 #  (nothing to change here for you)
41 gettext.install (True)
42 gettext.bindtextdomain (APP_NAME,
43                         mo_location)
44 gettext.textdomain (APP_NAME)
45 language = gettext.translation (APP_NAME,
46                                 mo_location,
47                                 languages = languages,
48                                 fallback = True)
50 # And now in your modules you can do:
51 #
52 # import i18n
53 # _ = i18n.language.gettext
54 #

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment