i18n of Django admin message "was changed successfully"

222 views
Skip to first unread message

Erik Wognsen

unread,
Sep 26, 2011, 11:53:13 PM9/26/11
to djang...@googlegroups.com
Hi,

django/contrib/admin/options.py contains the message 'The %(name)s "%(obj)s" was changed successfully.' and similar for "added" and "deleted" and some others.

This works well in languages that only use an article for definiteness. But what about other languages?

For example, in Danish "employee" is "ansat" but "the employee" is "den ansatte". The current translation for many languages including Danish simply uses a form of "%(name)s \"%(obj)s\" was changed successfully.". For example: 'ansat "Foo Bar" blev ....' or, in other words, '[lower case, indefinite form of model name] "Foo Bar" was changed successfully'.

Is it possible to handle 'The %(name)s' such that the translator may specify an upper case and definite version of the model name?

Regards,
Erik Wognsen

Sergiy Kuzmenko

unread,
Sep 27, 2011, 2:47:52 PM9/27/11
to djang...@googlegroups.com
In general noun interpolation is a non trivial task. It might be possible that for a limited subset of messages (addition, deletion and modification) there is a common denominator for an "alternative" verbose model name that will do the trick in all languages. But it might not be so. Different languages could require multiple word forms for what in Danish you describe as "definite version".

Also in some cases, the context itself may be altered by the noun you are interpolating. For example, the phrase "No %(name)s found" could be translated in French as "Aucun %(name)s trouvé" if the noun is in masculine or "Aucune %(name)s trouvée" if the noun is in feminine. Even though this example does not directly relate to messages generated by Django admin, it gives an idea about complexities involved in generating messages on the fly.

So I tend to think there is no easy fix for this. And yes, in some languages Django admin messages read funny.

My way to deal with this problem is to construct a (sometimes rather artificial) translation string utilizing the "dictionary form" of the noun that is being interpolated. For example, when translating "No %(name)s found" I could have tried to say something like "No object of type %(name)s was found" instead.

Sergiy
> --
> You received this message because you are subscribed to the Google Groups "Django internationalization and localization" group.
> To post to this group, send email to djang...@googlegroups.com.
> To unsubscribe from this group, send email to django-i18n...@googlegroups.com <django-i18n%2Bunsu...@googlegroups.com>.
> For more options, visit this group at http://groups.google.com/group/django-i18n?hl=en.
>

Erik Wognsen

unread,
Sep 29, 2011, 9:01:43 AM9/29/11
to djang...@googlegroups.com

Yes, I have seen some of the languages use tricks like "object of type" and slashes for gender ("%(name)s \"%(obj)s\" modificato/a correttamente.")

But many times the indefinite noun will do as well ('employee "Xyz" was changed...') , so maybe we can get the capitalization right? ('Employee "Xyz" was...')

Does gettext support something for that?

Otherwise, the first letter of the message can be made uppercase directly in Python, e.g. "msg = msg[0].upper() + msg[1:]" after msg is set in contrib/admin/options.py.

Regards,
Erik Wognsen

To unsubscribe from this group, send email to django-i18n...@googlegroups.com.

Sergiy Kuzmenko

unread,
Sep 29, 2011, 1:46:48 PM9/29/11
to djang...@googlegroups.com
According to gettext manual[1] one can use \u to uppercase the next char. But I have no idea whether "\u%(name)s" works. If it does not, a small patch for Django admin to fix this would be nice.

Erik Wognsen

unread,
Sep 30, 2011, 2:13:51 PM9/30/11
to djang...@googlegroups.com
On Thu, Sep 29, 2011 at 19:46, Sergiy Kuzmenko <s.kuz...@gmail.com> wrote:
According to gettext manual[1] one can use \u to uppercase the next char. But I have no idea whether "\u%(name)s" works.

"\u" in my po-file gives me "invalid control sequence" when I compilemessages, whether "\u" is followed by "%(name)s" or normal text. Other escape sequences such as "\t" and "\n" still work.
 
If it does not, a small patch for Django admin to fix this would be nice.

Do you mean the Python fix above? Or fixing the use of gettext?
 

Ramiro Morales

unread,
Sep 30, 2011, 3:32:23 PM9/30/11
to djang...@googlegroups.com
On Thu, Sep 29, 2011 at 2:46 PM, Sergiy Kuzmenko <s.kuz...@gmail.com> wrote:
> According to gettext manual[1] one can use \u to uppercase the next char.
> But I have no idea whether "\u%(name)s" works. If it does not, a small patch
> for Django admin to fix this would be nice.
> [1] http://www.gnu.org/software/gettext/manual/gettext.html#Interpolation-I

That section of the documentation is Perl-specific AFAICT.

--
Ramiro Morales

Sergiy Kuzmenko

unread,
Oct 1, 2011, 7:00:15 PM10/1/11
to djang...@googlegroups.com
> According to gettext manual[1] one can use \u to uppercase the next char.
> But I have no idea whether "\u%(name)s" works. If it does not, a small patch
> for Django admin to fix this would be nice.
> [1] http://www.gnu.org/software/gettext/manual/gettext.html#Interpolation-I

That section of the documentation is Perl-specific AFAICT.

Yes I goofed here. Now that I think again about the question, there is nothing gettext can do about uppercasing. It simply returns a translated string and variable interpolation happens in Python code.

If the translation must start with the interpolated word the only way to address it would be upper case the first character in Python code before outputting the message.

SK

Erik Wognsen

unread,
Oct 1, 2011, 7:09:03 PM10/1/11
to djang...@googlegroups.com
Ok. Does the i18n group have the possibility of deciding and committing this or should it go through a regular bug report?

--

Sergiy Kuzmenko

unread,
Oct 1, 2011, 7:23:28 PM10/1/11
to djang...@googlegroups.com
I believe you should file a bug report.
Cheers

Erik Wognsen

unread,
Oct 1, 2011, 10:14:16 PM10/1/11
to djang...@googlegroups.com
Ok, I filed a bug and patch [1], but it turned out there was already a ticket on this topic [2], which has a simpler patch that simply capitalizes the first letter of every message to the user. The things that needs to be answered by this list is:

Is this acceptable to do this for all languages and writing systems?

Also, is it ok to do it for all messages, even in English? Is there a reason to start a message with lowercase? I think it's a bit intrusive to capitalize all messages.

/Erik

[1] https://code.djangoproject.com/ticket/16973
[2] https://code.djangoproject.com/ticket/16350

Sergiy Kuzmenko

unread,
Oct 1, 2011, 10:44:36 PM10/1/11
to djang...@googlegroups.com
It is probably safe to uppercase first letter. There are writing systems where there is no distinction between upper and lower case (e.g., Georgian). For such writing systems uppercasing is essentially a noop. Just tried that in python shell:

>>> v = u"ქართული"
>>> v.upper() == v
True

Not sure is uppercasing is meaningful in RTL systems (Hebrew, Arabic)

SK
Reply all
Reply to author
Forward
0 new messages