What if we "cheat" makemessages like this:

{% if 0 %}
    {% trans 'This user blocked you.' context 'female' %}
    {% trans 'This user blocked you.' context 'male' %}
    {% trans 'This user blocked you.' context 'other' %}
{% endif %}

{% trans 'This user blocked you.' context user.gender %}

(or maybe we should filter user.gender with a filter that returns "female",
"male" or "other" (because they are integers).

It looks better to me and less work to "cheat" makemessages like this,
unless there is a better solution? Because translations which don't exist
in the code will be commented every time we run makemessages. Maybe this is
a feature we can add to the next Django release? And then we will not have
to "cheat"?

Thanks,
Uri.

*Uri Even-Chen*
[image: photo] Phone: +972-54-3995700
Email: [email protected]
Website: http://www.speedysoftware.com/uri/en/
<http://www.facebook.com/urievenchen>  <http://plus.google.com/+urievenchen>
  <http://www.linkedin.com/in/urievenchen>  <http://github.com/urievenchen>
<http://twitter.com/urievenchen>

On Thu, Mar 2, 2017 at 4:00 PM, Jani Tiainen <[email protected]> wrote:

> Unfortunately makemessages can't guess what your context is if it's
> variable (I'm not sure would it even consider it as a translatable text at
> all)
> First version would guarantee you to have translatable strings with
> genders, latter one either generates one string (and you have to manually
> create missing ones) or it won't find it at all.
>
> You could test that very quickly with simple template with given fragments.
>
>
> On 02.03.2017 14:59, Uri Even-Chen wrote:
>
> Hi,
>
> I'm working with Gleb on Speedy Match [
> <https://github.com/urievenchen/speedy-net>https://github.com/
> urievenchen/speedy-net]. We need to translate to Hebrew according to
> context of the user's gender. Gleb suggested that the code will be
> something like this:
>
> {% if user.gender == GENDER_FEMALE %}
>     {% trans 'This user blocked you.' context 'female' %}{% elif user.gender 
> == GENDER_MALE  %}
>     {% trans 'This user blocked you.' context 'male' %}
> {% else %}
>     {% trans 'This user blocked you.' context 'other' %}
> {% endif %}
>
>
> But, is it possible to change it to something like this:
>
> {% trans 'This user blocked you.' context user.gender %}
>
> While still auto-generate the django.po files? Genders are always either
> "female", "male" or "other". But some text may be related to genders of 2
> users - the one using the site right now and another user. How do we do it
> then? I was thinking about context like "female_female", "female_male" etc.
> Anyway we don't want the templates to include many times the same text (3
> or 9 times), we prefer that each text will appear only once.
>
> Thanks,
> Uri.
>
> *Uri Even-Chen*
> [image: photo] Phone: +972-54-3995700
> Email: <[email protected]>[email protected]
> Website: <http://www.speedysoftware.com/uri/en/>
> http://www.speedysoftware.com/uri/en/
> <http://www.facebook.com/urievenchen>
> <http://plus.google.com/+urievenchen>
> <http://www.linkedin.com/in/urievenchen>  <http://github.com/urievenchen>
> <http://twitter.com/urievenchen>
>
> On Wed, Mar 1, 2017 at 4:15 PM, Jani Tiainen <[email protected]> wrote:
>
>> In theory you just define genders to your PO file with translations and
>> it should work.
>>
>> Not sure will that disable autogeneration and update for your PO file
>> after that.
>> On 01.03.2017 14:59, Gleb Tocarenco wrote:
>>
>> Hello,
>>
>> I am running in with an issue with Django translation tag in case context
>> is present as a dynamic variable.
>>
>> {% trans 'You have new message' context user.gender %}
>>
>>
>> In this case django.po files doesn't contains words related to gender
>> context.
>>
>> My question is if there is possibility to use context in translation tag
>> as dynamic variable and generate django.po records based on it?
>>
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to <[email protected]>
>> [email protected].
>> 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/5c01a596-23a2-418f-9045-44a947efde0d%40googlegroups.com>
>> https://groups.google.com/d/msgid/django-users/5c01a596-23a2
>> -418f-9045-44a947efde0d%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> Jani Tiainen
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to <[email protected]>
>> [email protected].
>> 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/269918e9-6e13-5967-3b8b-fc3ec8028a4c%40gmail.com?utm_medium=email&utm_source=footer>
>> https://groups.google.com/d/msgid/django-users/269918e9-6e13
>> -5967-3b8b-fc3ec8028a4c%40gmail.com.
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/CAMQ2MsG8J0aTnmGoqvVZhDQ9sE5YE3iuZmtqvtYPNgAPiuBPFA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> https://groups.google.com/d/msgid/django-users/
> CAMQ2MsG8J0aTnmGoqvVZhDQ9sE5YE3iuZmtqvtYPNgAPiuBPFA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Jani Tiainen
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/d6b61216-63cb-86f9-9467-61a18a964c21%40gmail.com
> <https://groups.google.com/d/msgid/django-users/d6b61216-63cb-86f9-9467-61a18a964c21%40gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAMQ2MsHvKJK0Q9RHLVwGkLhyOWrtYQKSmMDQyMrXtYkWu9zdMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to