https://github.com/laura-barluzzi/django-user-language-middleware
Django middleware to translate with language in user model
https://github.com/laura-barluzzi/django-user-language-middleware
django django2 localization middleware python2 python3
Last synced: 4 months ago
JSON representation
Django middleware to translate with language in user model
- Host: GitHub
- URL: https://github.com/laura-barluzzi/django-user-language-middleware
- Owner: laura-barluzzi
- License: apache-2.0
- Created: 2018-04-09T23:58:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-03T12:20:28.000Z (about 5 years ago)
- Last Synced: 2025-04-13T04:08:53.590Z (about 1 year ago)
- Topics: django, django2, localization, middleware, python2, python3
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
************************
User Language Middleware
************************
.. image:: https://travis-ci.org/laura-barluzzi/django-user-language-middleware.svg?branch=master
:target: https://travis-ci.org/laura-barluzzi/django-user-language-middleware
.. image:: https://img.shields.io/pypi/v/django-user-language-middleware.svg
:target: https://pypi.python.org/pypi/django-user-language-middleware/
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:
.. code-block:: python
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:
.. code-block:: sh
pip install django-user-language-middleware
and then add it to your middleware class list to listen to requests:
.. code-block:: python
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