diff --git a/ckan/lib/i18n.py b/ckan/lib/i18n.py index 87e7312e6a0..3ed29401a1b 100644 --- a/ckan/lib/i18n.py +++ b/ckan/lib/i18n.py @@ -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