Skip to main content

Django application to provide useful utils and reusable parts of code for multi-languages sites.

Project description

django-lang PyPi license

PyPi status PyPi version PyPi python version PyPi downloads PyPi downloads PyPi downloads

GitHub GitHub release GitHub release

Test codecov.io pre-commit.ci status gitthub.com

Check Demo Project

  • Check the demo repo on GitHub

Requirements

  • Python 3.8+ supported.
  • Django 3.2+ supported.

Setup

  1. Install from pip:
    pip install django-lang
    
  2. Modify settings.py by adding the app to INSTALLED_APPS:
    INSTALLED_APPS = [
        # ...
        "lang",
        # ...
    ]
    
  3. Modify settings.py by adding the app to INSTALLED_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",
                ],
            },
        },
    ]
    
  4. 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>
    
  5. Modify your project's base template base.html to include attributes using translate_url template's tag:
    <head>
        ...
        <meta name="language" content="{{ LANGUAGE_CODE }}" />
        {% include "hreflang.html" %}
        ...
    </head>
    
  6. 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>
    

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

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.4.2.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

django_lang-0.4.2-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-lang-0.4.2.tar.gz.

File metadata

  • Download URL: django-lang-0.4.2.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for django-lang-0.4.2.tar.gz
Algorithm Hash digest
SHA256 7bde61806b3a4dc88c9691b0937980bfc4aa6a888e8f243ce515adfa2cce87dd
MD5 58c6a7975e3bfabe9251383dba0eb90a
BLAKE2b-256 f072e2d759e460c87c77fa686412da439fe887807e1308dd8a093ee2d0fd8755

See more details on using hashes here.

File details

Details for the file django_lang-0.4.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_lang-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 11fb3000ea562889b9520ab0afa61349ad57cf5d1c0a162168c6ee348e35cd64
MD5 725f604d6cf2deb9926f045e0d591467
BLAKE2b-256 59f1525fcf13bfca9846bf18d455b32db43e0a7602260664c9dc31f00764e6d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page