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
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.2.0.tar.gz
(115.3 kB
view hashes)
Built Distribution
Close
Hashes for django_lang-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e85be2f45165d42dbee3d7bc9c09465bce5fd1937eb2477f57e3277d8080084a |
|
MD5 | ec8adf553cecc0efb43486806fd412d2 |
|
BLAKE2b-256 | b6ac50b6614c6799115aa51fb63c9d464a42a74f9d80efb2b512c0fd69aeeb4c |