projects
/
mussorgsky
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Verbose comments in the i18n
[mussorgsky]
/
src
/
i18n.py
diff --git
a/src/i18n.py
b/src/i18n.py
index
aad683d
..
210b53c
100644
(file)
--- a/
src/i18n.py
+++ b/
src/i18n.py
@@
-2,32
+2,41
@@
import os, sys
import locale
import gettext
import locale
import gettext
+# Change this variable to your app name!
+# The translation files will be under
+# @LOCALE_DIR@/@LANGUAGE@/LC_MESSAGES/@APP_NAME@.mo
+#
APP_NAME = "mussorgsky"
APP_NAME = "mussorgsky"
+# This is ok for maemo. Not sure in a regular desktop:
+#
APP_DIR = os.path.join (sys.prefix,
'share')
APP_DIR = os.path.join (sys.prefix,
'share')
-
LOCALE_DIR = os.path.join(APP_DIR, 'locale')
LOCALE_DIR = os.path.join(APP_DIR, 'locale')
+
+# Now we need to choose the language. We will provide a list, and gettext
+# will use the first translation available in the list
+#
+# In maemo it is in the LANG environment variable
+# (on desktop is usually LANGUAGES)
+#
DEFAULT_LANGUAGES = os.environ.get('LANG', '').split(':')
DEFAULT_LANGUAGES += ['en_US']
DEFAULT_LANGUAGES = os.environ.get('LANG', '').split(':')
DEFAULT_LANGUAGES += ['en_US']
-# Init i18n stuff
+# Try to get the languages from the default locale
lc, encoding = locale.getdefaultlocale()
lc, encoding = locale.getdefaultlocale()
-
if lc:
languages = [lc]
if lc:
languages = [lc]
-# DEBUG: to test translation without installation
-#languages = ["es_ES"]
-#mo_location = os.path.realpath(os.path.dirname(sys.argv[1]))
-#print languages
-
+# Concat all languages (env + default locale),
+# and here we have the languages and location of the translations
+#
languages += DEFAULT_LANGUAGES
mo_location = LOCALE_DIR
languages += DEFAULT_LANGUAGES
mo_location = LOCALE_DIR
-#print "Loading translations from: ", mo_location
-
+# Lets tell those details to gettext
+# (nothing to change here for you)
gettext.install (True)
gettext.bindtextdomain (APP_NAME,
mo_location)
gettext.install (True)
gettext.bindtextdomain (APP_NAME,
mo_location)
@@
-36,3
+45,10
@@
language = gettext.translation (APP_NAME,
mo_location,
languages = languages,
fallback = True)
mo_location,
languages = languages,
fallback = True)
+
+# And now in your modules you can do:
+#
+# import i18n
+# _ = i18n.language.gettext
+#
+