can use a translation object for the given language and the current site (app_dir)
written by Benjamin Dauvergne fix #477
This commit is contained in:
parent
7853eaa1ca
commit
7c6685c6c6
|
@ -94,6 +94,7 @@ class QommonPublisher(Publisher):
|
|||
auto_create_appdir = True
|
||||
missing_appdir_redirect = None
|
||||
use_sms_feature = False
|
||||
app_translations = dict()
|
||||
|
||||
def get_root_url(self):
|
||||
return self.get_request().environ['SCRIPT_NAME'] + '/'
|
||||
|
@ -257,11 +258,21 @@ class QommonPublisher(Publisher):
|
|||
return output
|
||||
return template.decorate(output, response)
|
||||
|
||||
def get_translation(self, lang):
|
||||
'''Retrieve a translation object for the given language and the current site.'''
|
||||
app_translation_path = os.path.join(self.app_dir, '%s.mo' % lang)
|
||||
if os.path.exists(app_translation_path):
|
||||
trans = gettext.GNUTranslations(file(app_translation_path))
|
||||
trans.add_fallback(self.translations[lang])
|
||||
else:
|
||||
trans = self.translations[lang]
|
||||
return trans
|
||||
|
||||
def install_lang(self, lang = None):
|
||||
if lang is None or not self.translations.has_key(lang):
|
||||
gettext.install(self.APP_NAME) # will use environment variable to get language
|
||||
else:
|
||||
self.translations[lang].install()
|
||||
self.get_translation(lang).install()
|
||||
_1 = _
|
||||
__builtin__.__dict__['_'] = lambda x: unicode(_1(str(x)), 'utf-8').encode(self.site_charset)
|
||||
__builtin__.__dict__['_1'] = _1
|
||||
|
|
Loading…
Reference in New Issue