I'm trying to translate my django project from English into German. It currently consists of two apps. The mainapp is translated correctly. The other app is fully translated in the django.po file but only a few translated strings will be shown and the other ones still remain in English.
For compilation of my language files (one for each of the currently two apps) I always execute the following commands in the root directory of my project:
django-admin makemessages -l de
# Now doing some translations
django-admin compilemessages
When I change any translation string and execute makemessage and compilemessage, django will still use the old translation and not the new one. So it looks like it worked some time ago but now something is going wrong with compiling/using the translations.
In this template for example the "Log in" and the "Sign up" string are translated correctly, but the "Need an account?" string is not because it was added when the translations didn't work anymore. But unfortunately I have no idea what changed and why it's not working anymore.
{% extends "mainapp/base.html" %}
{% load crispy_forms_tags %}
{% load i18n %}
{% block content %}
<div class="content-section">
<form method="POST"> {% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">{% trans "Log in" %}</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">{% trans "Log in" %}</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">{% trans "Need an account?" %}<a class="ml-2" href="{% url 'register' %}">{% trans "Sign up" %}</a></small>
</div>
</div>
{% endblock content%}
These are my settings:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'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',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_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',
],
},
},
]
LANGUAGE_CODE = 'en'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),)
I also took a look on this topic and all of it's referenced topics: Django: Only a single element gets translated
Thanks a lot for your help!
Here is the po file by the way:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-20 09:17+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: .\login\templates\login\login.html:9 .\login\templates\login\login.html:13
#: .\login\templates\login\logout.html:7
msgid "Log in"
msgstr "Anmelden"
#: .\login\templates\login\login.html:17
msgid "Need an account?"
msgstr "Noch kein Account?"
#: .\login\templates\login\login.html:17
#: .\login\templates\login\register.html:13
msgid "Sign up"
msgstr "Registrieren"
#: .\login\templates\login\logout.html:5
msgid "You have been logged out!"
msgstr "Sie wurden abgemeldet"
#: .\login\templates\login\logout.html:7
msgid "Home"
msgstr "Start"
#: .\login\templates\login\profile.html:16
msgid "Profile Info"
msgstr "Profil Info"
#: .\login\templates\login\profile.html:21
msgid "Update"
msgstr "Aktualisieren"
#: .\login\templates\login\register.html:9
msgid "Join today"
msgstr "Heute beitreten"
#: .\login\templates\login\register.html:17
msgid "Already have an account?"
msgstr "Sie haben bereits einen Account?"
#: .\login\templates\login\register.html:17
msgid "Sign in"
msgstr "Anmelden"