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 language_prefixed_patterns


patterns = language_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('en')
>>> reverse('account-register')
'/en/users/register/'

Installation

  • Install the django-i18nurls package (eg: pip install django-i18nurls).

  • 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.2.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file django-i18nurls-0.5.2.tar.gz.

File metadata

File hashes

Hashes for django-i18nurls-0.5.2.tar.gz
Algorithm Hash digest
SHA256 2f2cdec898d7346714dd09ed6075d06987a02482a2f0af8ef40a1a1cc3d74a14
MD5 62d710d05d6d01022b14cad4a72c96f8
BLAKE2b-256 631e2cf2eda9e9abc0e0ef3e3e97847a8e052dd6833b7ace6f758c449308fbf7

See more details on using hashes here.

Supported by

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