von Susanne Klaus
•
21 Mai, 2021
1. Create folder "locale" in your app directory: $ mkdir locale And add this in settings.py: #beginning of your file from django.utils.translation import gettext_lazy as _ #Then add "LocaleMiddleware" after SessionMiddleware MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', ... #end of file LANGUAGES = [ ('de', _('German')), ('en', _('English')), ] -> That's it. 2. Next add this:{% load i18n %} {% get_current_language as LANGUAGE_CODE %} {% block content %}{% translate 'Translate this' %}This creates the directory and file with all to {% translate 'What do you like to translate'%} tags. 4. Go to the just created file "locale/de/LC_MESSAGES/django.po" and translate your text: For example: msgid "Forgot Password?" msgstr "Passwort vergessen?" 5. Now you need to compile the messages (again in your app directory): $ django-admin compilemessages 6. Voilà - hier ist die Übersetzung. It depends on your Browser language. For reference: https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#url-internationalization