diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 87c62f9617d..a8b0ffa0429 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -105,13 +105,27 @@ def _add_i18n_to_url(url_to_amend, **kw): root = request.environ.get('SCRIPT_NAME', '') except TypeError: root = '' - if default_locale: - url = url_to_amend + # ckan.root_path is defined when we have none standard language + # position in the url + root_path = config.get('ckan.root_path') + if root_path: + # we have a special root specified so use that + if default_locale: + root = re.sub('/{{LANG}}', '', root_path) + else: + root = re.sub('{{LANG}}', locale, root_path) + # make sure we don't have a trailing / on the root + if root[-1] == '/': + root = root[:-1] + url = '%s%s' % (root, url_to_amend) else: - # we need to strip the root from the url and the add it before - # the language specification. - url = url_to_amend[len(root):] - url = '%s/%s%s' % (root, locale, url) + if default_locale: + url = url_to_amend + else: + # we need to strip the root from the url and the add it before + # the language specification. + url = url_to_amend[len(root):] + url = '%s/%s%s' % (root, locale, url) # stop the root being added twice in redirects if no_root: diff --git a/doc/i18n.rst b/doc/i18n.rst index 7dd5daf4517..07c2c50f95f 100644 --- a/doc/i18n.rst +++ b/doc/i18n.rst @@ -4,6 +4,8 @@ Internationalize CKAN CKAN is used in many countries, and adding a new language to the web interface is a simple process. +CKAN uses the url to determine which language is used. An example would be ``/fr/dataset`` would be shown in french. If CKAN is running under a directory then an example would be ``/root/fr/dataset``. For custom paths the ``ckan.root_path`` config option can be used and is of the form ``/path/from/root/with/{{LANG}}/substitution``. + .. Note: Storing metadata field values in more than one language is a separate topic. This is achieved by storing the translations in extra fields. A custom dataset form and dataset display template are recommended. Ask the CKAN team for more information. Supported Languages