Django application to provide useful utils and reusable parts of code for multi-languages sites.
Project description
django-lang
GitHub
Test
Check Demo Project
- Check the demo repo on GitHub
Requirements
- Python 3.8+ supported.
- Django 3.2+ supported.
Setup
- Install from pip:
pip install django-lang
- Modify
settings.py
by adding the app toINSTALLED_APPS
:
INSTALLED_APPS = [
# ...
"lang",
# ...
]
- 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 nav template
nav.html
to include language's switcher:
<ul class="nav navbar-nav">
{% include "lang/nav-link.html" %}
</ul>
- Modify your project's base template
base.html
to include language's templatetagsurls
:
{% load i18n urls %}
- Modify your project's base template
base.html
to include attributes usingtranslate_url
template's tag:
<head>
...
<!-- hreflang -->
<meta name="language" content="{{ LANGUAGE_CODE }}" />
{% get_available_languages as LANGUAGES %}
{% for language_code, language_name in LANGUAGES %}
<link rel="alternate" hreflang="{{ language_code }}" href="{% translate_url language_code %}" />
{% endfor %}
<link rel="alternate" href="{% translate_url 'it' %}" hreflang="x-default" />
...
</head>
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
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-lang-0.3.0.tar.gz
(115.8 kB
view hashes)
Built Distribution
Close
Hashes for django_lang-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e6d695e530984d6f4826efb175e3c2a00c1205d4a7762bccc82536dc3a2c3bf |
|
MD5 | 05e4ac03024fbbdcb5c3cc1608924250 |
|
BLAKE2b-256 | 61eb12d4a5e1d0612882f07cb13d5e685cda2d1eacc40fef7af8c950dab9ae53 |