Skip to content

NidalChateur/multilang_site

Repository files navigation

Python Django Poetry Black Flake8 Docker

Presentation

Blogs is a multilingual deployed application built with :

  • Django internationalization (i18n) for language support.
  • Django Mail and JWT for password reset functionality.
  • Django Admin to manage data.
  • OpenAI chatbot for interactive user engagement.
  • Cryptography to secure authenticated user data.
  • JavaScript and Django REST Framework for dynamic search functionality.
  • Pillow to resize and save blog images efficiently.
  • Bootstrap for the frontend.

Uses cases

  • Logged-in users: You can change the current language (fr-en), create, read, update, and delete (CRUD) posts, and search through them. All of it is possible in the navigation.

  • Visitors: You can change the current language (fr-en), read posts and search through the content. All of it is possible in the navigation.

Run locally the app

  1. Set environnement variables

  2. Install decencies

    • python -m venv env or python3 -m venv env

    • env/scripts/activate or source env/bin/activate

    • pip install -m requirements/dev_freeze.txt

  3. Apply migrations

    • python manage.py migrate
  4. Run

    • python manage.py runserver

Translation Steps Documentation (i18n)

  1. Configure settings.py, templates and python files

    • settings.py :
        from django.utils.translation import gettext_lazy as _
    
        MIDDLEWARE = [
        "django.middleware.security.SecurityMiddleware",
        "django.contrib.sessions.middleware.SessionMiddleware",
    
        # add this middleware used by i18n
        "django.middleware.locale.LocaleMiddleware",
        #
    
        "django.middleware.common.CommonMiddleware",
        "django.middleware.csrf.CsrfViewMiddleware",
        "django.contrib.auth.middleware.AuthenticationMiddleware",
        "django.contrib.messages.middleware.MessageMiddleware",
        "django.middleware.clickjacking.XFrameOptionsMiddleware",
        ]
    
    
        LOCALE_PATHS = [
            BASE_DIR / "locale",
        ]
    
    
        LANGUAGES = [
            ("fr", _("French")),
            ("en", _("English")),
        ]
    
    
        LANGUAGE_CODE = "en"
    
        TIME_ZONE = "UTC"
    
        USE_I18N = True
    
        USE_TZ = True
    
        USE_L10N = True
    
    • templates (html files) :
    {% load i18n %}
    <p>{% translate 'No post' %}.</p>
    
    
    • forms.py and models.py :
        from django.utils.translation import gettext_lazy as _
    
        title=_("Title") 
    
    
    • views.py :
        from django.utils.translation import gettext as _
    
        title=_("Title") 
    
    
  2. Create django.po files for manual translation

    mkdir locale

    py .\manage.py makemessages -l en --ignore=env/*

    py .\manage.py makemessages -l fr --ignore=env/*

  3. Update django.po files (if modifications are made)

    py .\manage.py makemessages -a --ignore=env/*

  4. Manually edit the django.po files for translation

    Open and edit the generated django.po files in the locale directory. Translate the message strings under each language's respective section (msgid for original text and msgstr for translations).

  5. Compile translations

    py .\manage.py compilemessages