django-lang 
GitHub

Test

Check Demo Project
- Check the demo repo on GitHub
Requirements
- Python 3.9+ supported.
- Django 3.2+ supported.
Setup
-
Install from pip:
pip install django-lang
-
Modify
settings.pyby adding the app toINSTALLED_APPS:INSTALLED_APPS = [ # ... "lang", # ... ]
-
Modify
settings.pyby adding the app toINSTALLED_APPS:TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [os.path.join(PROJECT_DIR, "templates")], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "lang.context_processors.from_settings", "lang.context_processors.seo_i18n", ], }, }, ]
Optional:
lang.context_processors.language_switcher_next(fillsredirect_tofor the packaged language form).
Optional: SetLanguageNextPathMiddleware
Only needed if you use translated URL segments (gettext_lazy under i18n_patterns) and see language switches that POST to set_language but stay on the wrong prefix. Short how-to: docs/set_language_middleware.md.
- Modify your project's base template
base.htmlto include language's switcher styles:<head> ... <link rel="stylesheet" type="text/css" href="{% static 'lang/css/nav-link.css' %}"> ... </head>
- Modify your project's base template
base.htmlto include attributes usingtranslate_urltemplate's tag:<head> ... <meta name="language" content="{{ LANGUAGE_CODE }}" /> {% include "hreflang.html" %} ... </head>
- Modify your project's nav template
nav.htmlto include language's switcher:<nav class="navbar"> ... <ul class="nav navbar-nav"> {% include "lang/nav-link.html" %} </ul> ... </nav>
Configuration: lang.conf and APP_CONFIG
Built-in maps live in lang.defaults. At runtime, :mod:lang.conf resolves values lazily:
- Top-level Django settings (
LANGUAGE_HREFLANG_MAP,LANGUAGE_WIKIPEDIA_SAMEAS,OG_LOCALE_BY_LANGUAGE,HREFLANG_DEFAULT_LANGUAGE,LANGUAGE_FLAG_MAP), if set. - Partial dicts under
settings.APP_CONFIG["lang"]merged onto the package defaults (for the threeLANGUAGE_*/OG_*maps and flag overrides). - Otherwise the content of
lang.defaults.
You do not need to import lang.defaults from settings.py. Typical site-only override for x-default::
APP_CONFIG = {
"lang": {
"HREFLANG_DEFAULT_LANGUAGE": "it",
},
}
Or use the usual flat settings (full replacement for the dict keys, or HREFLANG_DEFAULT_LANGUAGE at top level) if you prefer.
Optional: language control beside the hamburger on small viewports
nav-link-standalone.css shows the extra switcher next to the menu toggle below the lg breakpoint (~992px) and hides the duplicate inside the collapsed drawer. Optional script display-standalone-class.js only adds class display-standalone on <html> for installed web apps; layout no longer depends on it.
- In
settings.py, add the optional context processor soredirect_tois filled forset_language’snext(unless you passredirect_tofrom each view):"lang.context_processors.language_switcher_next",
- In the base layout
<head>, afternav-link.css, add:<link rel="stylesheet" href="{% static 'lang/css/nav-link-standalone.css' %}"> <script src="{% static 'lang/js/display-standalone-class.js' %}"></script>
- Next to your mobile menu button, include:
{% include "lang/nav-link-standalone.html" %}
Packaged templates:
hreflang.html(app template root) —<link rel="alternate" hreflang="…">for the current view.lang/nav-link.html— language<select>(optional context:lang_switcher_id,lang_switcher_extra_class).lang/nav-link-standalone.html— duplicate switcher beside the mobile toggle (small viewports / PWA).
Run Example Project
git clone --depth=50 --branch=django-lang https://github.com/DLRSP/example.git DLRSP/example
cd DLRSP/example
python manage.py runserver
Now browser the app @ http://127.0.0.1:8000
References
- brainstorm.it - Language's switching
- hakibenita.com - Url's translation for "hreflang" html's attributes
Metadata
Release files for django-lang 0.6.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_lang-0.6.12.tar.gz | 32.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_lang-0.6.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.7 kB
Release files / django_lang-0.6.12.tar.gz
| Download URL | django_lang-0.6.12.tar.gz |
|---|---|
| Size | 32.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e509f3f2cd8853837325a7da9decfa08380457d7543a0774a78f59dedc1ed194
|
|
BLAKE2b-256 checksum How to use checksums |
b25b75ef8517ada6da1957d9da1ab40ee82841b4b8541d8ca314811f85489db8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / django_lang-0.6.12-py3-none-any.whl
| Download URL | django_lang-0.6.12-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b688e3f199075435605a774877dfbb20fa4dc801acbd640865ddeafa663657a
|
|
BLAKE2b-256 checksum How to use checksums |
790350b37f6bd4226e6313e78aed6f58493ccdb2943783a67982476914c1025a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for django-lang 0.6.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.