pcari.templatetags.localize_url module

This module defines a custom tag for generating URLs for switching languages.

pcari.templatetags.localize_url.localize_url(url_example, language)

Localize a URL for a given language.

Parameters:
  • url_example – A sample URL of any language that starts with settings.URL_ROOT.
  • language – The code of the language to localize for.
Returns:

The localized URL as a string.

>>> # With `settings.URL_ROOT` set to `/pcari`
>>> localize_url('/pcari/en/landing/', 'tl')
'/pcari/tl/landing/'
>>> # With `settings.URL_ROOT` set to '/'
>>> localize_url('/en/landing', 'tl')
`/tl/landing`