I have correctly set LOCALE_PATHS
in my settings.
LANGUAGE_CODE
is set to it
.
As a test, the only language I translated the app into is it
.
In one of my views I have {% trans "MY_MESSAGE_ID" %}
and in django.po
I have
msgid "MY_MESSAGE_ID"
msgstr "It is working"
If a visitor with it
language opens the app, he sees "It is working"
If a visitor with en
language opens the app, he sees "MY_MESSAGE_ID"
Django should never display msgid
to the end-user. Django should serve the first available translation as a fallback, especially if I defined it in LANGUAGE_CODE
. Is there any way to achieve this behavior?
The solution to this problem, I read, is to use "It is working"
as a message id. I believe this solution is unacceptable for these reasons:
Making a en
translation would be useless, since the message ids are
already the translation itself.
Some message ids would be extremely long.
"Message id" refers to something which must be language-agnostic.
If I wanted to change the default language, I'd have to re-write the entire application text content.
Django, like many others uses the gettext
internally; likewise the .mo
, .po
formats belong and are produced by their utilities. You are not using the full power of gettext
if you do not use the full message as the msgid
.
See for example the documentation for glibc:
SYNOPSIS
#include <libintl.h> char * gettext (const char * msgid); char * dgettext (const char * domainname, const char * msgid); char * dcgettext (const char * domainname, const char * msgid, int category);
DESCRIPTION
The gettext, dgettext and dcgettext functions attempt to translate a text string into the user's native language, by looking up the translation in a message catalog.
The msgid argument identifies the message to be translated. By convention, it is the English version of the message, with non-ASCII characters replaced by ASCII approximations. This choice allows the translators to work with message catalogs, called PO files, that contain both the English and the translated versions of each message, and can be installed using the msgfmt utility.
In addition, with GNU gettext comes the utility msgen
, that
Creates an English translation catalog. The input file is the last created English PO file, or a PO Template file (generally created by xgettext). Untranslated entries are assigned a translation that is identical to the msgid.
Furthermore, the gettext
utilities can find fuzzy matches for new messages, which will speed up translation effort, and also notice when a translation is out of date and mark it for retranslation. This is impossible if you use nonsensical message IDs in your templates.