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:
<!-- beginning of your file (after static) -->
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% block content %}
<!-- add this wheresoever your want to translate words -->
{% translate 'Translate this' %}
<!-- add this end of file --
{% endblock content %}
in your template *.html files.
3. Go back to your app directory and enter:
$ django-admin makemessages -l de
-> 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