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]. 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*

photo   Phone:+972-54-3995700 <tel:+972-54-3995700>
Email:u...@speedy.net <mailto:u...@speedy.net>
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 Wed, Mar 1, 2017 at 4:15 PM, Jani Tiainen <rede...@gmail.com <mailto:rede...@gmail.com>> 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 django-users+unsubscr...@googlegroups.com
    <mailto:django-users+unsubscr...@googlegroups.com>.
    To post to this group, send email to
    django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
    Visit this group at https://groups.google.com/group/django-users
    <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
    <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 django-users+unsubscr...@googlegroups.com
    <mailto:django-users+unsubscr...@googlegroups.com>.
    To post to this group, send email to django-users@googlegroups.com
    <mailto:django-users@googlegroups.com>.
    Visit this group at https://groups.google.com/group/django-users
    <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
    
<https://groups.google.com/d/msgid/django-users/269918e9-6e13-5967-3b8b-fc3ec8028a4c%40gmail.com?utm_medium=email&utm_source=footer>.


    For more options, visit https://groups.google.com/d/optout
    <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 django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@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/CAMQ2MsG8J0aTnmGoqvVZhDQ9sE5YE3iuZmtqvtYPNgAPiuBPFA%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAMQ2MsG8J0aTnmGoqvVZhDQ9sE5YE3iuZmtqvtYPNgAPiuBPFA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/d6b61216-63cb-86f9-9467-61a18a964c21%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to