Skip to content

Django middleware ↔️ for setting a default language (by ignoring HTTP Accepted-Language header)

License

Notifications You must be signed in to change notification settings

yifaneye/django-default-language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-default-language

django-default-language is a Django middleware for setting a default language in bi/multilingual Django project.

Installation

Use the package manager pip to install django-default-language.

pip install django-default-language

Usage

Step 1. Add DefaultLanguageMiddleware (in settings.py file)

MIDDLEWARE = [
    # ...
    'language.DefaultLanguageMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    # ...
]

Make sure DefaultLanguageMiddleware is before LocaleMiddleware. Otherwise, Django will default to use the requesting browser's default language from the 'Accept-Language' request header (e.g. Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5).

Step 2. Specify default language (in settings.py file)

LANGUAGE_CODE = 'zh-Hans'  # default language

Contributing

Pull requests are welcome.

License

MIT

About

Django middleware ↔️ for setting a default language (by ignoring HTTP Accepted-Language header)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages