Skip to content

DLRSP/django-lang

Repository files navigation

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

About

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

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published