- Check the demo repo on GitHub
- Python 3.8+ supported.
- Django 3.2+ supported.
- Install from pip:
pip install django-lang
- Modify
settings.py
by adding the app toINSTALLED_APPS
:INSTALLED_APPS = [ # ... "lang", # ... ]
- Modify
settings.py
by 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", ], }, }, ]
- Modify your project's base template
base.html
to 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.html
to include attributes usingtranslate_url
template's tag:<head> ... <meta name="language" content="{{ LANGUAGE_CODE }}" /> {% include "hreflang.html" %} ... </head>
- Modify your project's nav template
nav.html
to include language's switcher:<nav class="navbar"> ... <ul class="nav navbar-nav"> {% include "nav-link.html" %} </ul> ... </nav>
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
- brainstorm.it - Language's switching
- hakibenita.com - Url's translation for "hreflang" html's attributes