Skip to content

Commit

Permalink
[2518] Allow custom i18n directory.
Browse files Browse the repository at this point in the history
Custom i18n directory can be set via the config
option ckan.i18n_directory.
  • Loading branch information
johnglover committed Jun 13, 2012
1 parent 934bfbd commit 977f623
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ckan/lib/i18n.py
Expand Up @@ -87,12 +87,25 @@ def get_available_locales():
available_locales = map(Locale.parse, get_locales())
return available_locales

def _set_lang(lang):
''' Allows a custom i18n directory to be specified.
Creates a fake config file to pass to pylons.i18n.set_lang, which
sets the Pylons root path to desired i18n_directory.
This is needed as Pylons will only look for an i18n directory in
the application root.'''
if config.get('ckan.i18n_directory'):
fake_config = {'pylons.paths': {'root': config['ckan.i18n_directory']},
'pylons.package': config['pylons.package']}
i18n.set_lang(lang, pylons_config=fake_config)
else:
i18n.set_lang(lang)

def handle_request(request, tmpl_context):
''' Set the language for the request '''
lang = request.environ.get('CKAN_LANG') or \
config.get('ckan.locale_default', 'en')
config.get('ckan.locale_default', 'en')
if lang != 'en':
i18n.set_lang(lang)
_set_lang(lang)
tmpl_context.language = lang
return lang

Expand Down

0 comments on commit 977f623

Please sign in to comment.