Skip to main content

Django middleware to translate with language in user model

Project description

https://travis-ci.org/laura-barluzzi/django-user-language-middleware.svg?branch=master

What’s this?

This package contains a middleware that activates translations based on the language field in the user model. This enables easy user-specific localization of a Django application: just add a language string field to the user model, install this middleware and you’re good to go!

Usage

Add a language field to your user model:

class User(auth_base.AbstractBaseUser, auth.PermissionsMixin):
    # ...
    language = models.CharField(max_length=10,
                                choices=settings.LANGUAGES,
                                default=settings.LANGUAGE_CODE)

Install the middleware from pip:

pip install django-user-language-middleware

and then add it to your middleware class list to listen to requests:

MIDDLEWARE = [  # Or MIDDLEWARE_CLASSES on Django < 1.10
    ...
    'user_language_middleware.UserLanguageMiddleware',
    ...
]

Supported versions

Python: - 2.7 - 3.4 to 3.6

Django: - 1.8 to 1.11 - 2.0

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-user-language-middleware-0.0.1.tar.gz (2.7 kB view details)

Uploaded Source

File details

Details for the file django-user-language-middleware-0.0.1.tar.gz.

File metadata

File hashes

Hashes for django-user-language-middleware-0.0.1.tar.gz
Algorithm Hash digest
SHA256 507beea440ec5a29c5683e12b978ece41505b0fa42fdad602ebde07169a3b153
MD5 9a8afbbf6f9bf4be2bda6f133c742b5a
BLAKE2b-256 02bbe304f27e6be722bb38c8303c72836116753b2f7d312aba5da8b4a9dbb04a

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