Translation with context

17 views
Skip to first unread message

אורי

unread,
Dec 25, 2018, 4:57:33 AM12/25/18
to django...@googlegroups.com
Hi,

We are using Django for Speedy Net and Speedy Match (currently Django 1.11.17, we can't upgrade to a newer version of Django because of one of our requirements, django-modeltranslation). I have a problem with translating strings with context. We use context mainly for translating strings differently depending on the user's gender, which translates differently in languages such as Hebrew, although the English strings are the same. For example, I have this code:

raise ValidationError(pgettext_lazy(context=self.instance.get_gender(), message="You can't change your username."))


The problem is that manage.py makemessages doesn't recognize the context here. A workaround we found is to include this text manually in files we don't use at all, such as __translations.py or __translations.html (you can see them on https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-23_a/speedy/core/base/__translations.py and https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2018-12-23_a/speedy/core/templates/__translations.html respectively), and there we can include the same strings with context:

Either:

pgettext_lazy(context="female", message='Your new password has been saved.')
pgettext_lazy(context="male", message='Your new password has been saved.')
pgettext_lazy(context="other", message='Your new password has been saved.')

Or:

{% trans "You can't change your username." context 'female' %}
{% trans "You can't change your username." context 'male' %}
{% trans "You can't change your username." context 'other' %}

But this is a lot of work and we have each string 4 times in our code (not including translations), and it's very difficult to maintain such a code. And as I said, these files are not used at all, they are only for ./make_all_messages.sh to work properly. So my question is - is there a way to pass all the possible contexts as a list to manage.py makemessages? For example add another argument to pgettext_lazy or add a specific comment which will be read by manage.py makemessages? I checked and currently we use translation with context about 100 times in this project, and it would be a lot of work to generate all this code (100 * 3 times) just for manage.py makemessages to work.

By the way, the method get_gender() always returns one of these strings: "female", "male" or "other". There is also another method, get_match_gender(), which returns the same values.

Is it possible to define the context "other" as default, so if a different context (or none) is passed and there is no translation with the given context, "other" will be used?

By the way, did someone ask this question before? Is there any solution I don't know?

Thanks,
אורי (Uri)

אורי

unread,
Dec 25, 2018, 6:12:47 AM12/25/18
to django...@googlegroups.com
Hi,

I think receiving such a message from this mailing list is spam.

Thanks,
אורי (Uri)


---------- Forwarded message ---------
From: <aphi...@gmail.com>
Date: Tue, Dec 25, 2018 at 12:40 PM
Subject: Re: Translation with context
To: <u...@speedy.net>


BitBounce
     
     

Hello! I use a new email filtering service called BitBounce to filter my email. To deliver your email to my inbox, please click the button below and pay the small cryptocurrency fee. Thank you!

$0.05 to deliver your email.

We’ve never met — I’ll pay your fee.

I know you — Add me to your whitelist.

     
     

BitBounce is powered by
 the Credo cryptocurrency

I’m from a business — 
what are my delivery options

BitBounce and Credo are
transacted through CredoEx

Made by Turing Technology Inc. in San Mateo, California Sign Up for BitBounce

Atul Anand

unread,
Dec 25, 2018, 6:32:16 AM12/25/18
to django...@googlegroups.com
I also got the same. The sender of these should be blocked.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABD5YeGn83-OzGzLf_oL9MkMrDUwvcVMFhepbGC5jBd1Sj6osw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Jani Tiainen

unread,
Dec 25, 2018, 6:43:18 AM12/25/18
to django...@googlegroups.com
Hi,

Django doesn't have translation system of own but relies on gettext tools (and python wrappers) to handle translations. Those tools doesn't know anything that your python code returns to context so no, there is no simple way to do that automatically. 

It's a limitation of gettext that there is not simple way handle genders etc, in translations.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.


--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

Jason

unread,
Dec 25, 2018, 8:16:40 AM12/25/18
to Django users
https://twitter.com/AdamChainz/status/1076912927612026881

this is also affecting the django-dev mailing list too.  you can file a support ticket with them too.
Reply all
Reply to author
Forward
0 new messages