Skip to main content

Translate URL patterns and prefix URLs with language-code.

Project description

This Django pluggable makes it possible to translate URL patterns by using gettext. As well it contains a custom patterns function for prefixing URLs with the active language-code (eg: /en/news/, /nl/nieuws/) and a middleware to activate the language code in the prefix (for incoming request).

Examples

# urls.py
from django.conf.urls.defaults import patterns, include, url
from django.utils.translation import ugettext_lazy as _

from i18nurls.defaults import locale_prefixed_patterns


patterns = locale_prefixed_patterns('',
    url(_(r'^users/register/$', 'your.view', name='account-register')),
)

# In your shell, after updating your translations (with makemessages / compilemessages)
>>> activate('nl')
>>> reverse('account-register')
'/nl/gebruikers/registeren/'

>>> activate('nl')
>>> reverse('account-register')
'/en/users/register/'

Installation

  • Add i18nurls to your settings.INSTALLED_APPS

  • Add i18nurls.middleware.LocaleMiddleware to your settings.MIDDLEWARE_CLASSES. Note: This middleware replaces the default Django LocaleMiddleware.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-i18nurls-0.5.tar.gz (6.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page