{% trans 'You have new message' context user.gender %}
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.
--
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/5c01a596-23a2-418f-9045-44a947efde0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- Jani Tiainen
{% 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 %}
{% trans 'This user blocked you.' context user.gender %}
| ||
|
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+unsubscribe@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/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 django-users+unsubscribe@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/269918e9-6e13-5967-3b8b-fc3ec8028a4c%40gmail.com.
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)
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/CAMQ2MsG8J0aTnmGoqvVZhDQ9sE5YE3iuZmtqvtYPNgAPiuBPFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
-- Jani Tiainen
{% if 0 %}
{% trans 'This user blocked you.' context 'female' %}
{% trans 'This user blocked you.' context 'male' %}
{% trans 'This user blocked you.' context 'other' %}
{% endif %}
(or maybe we should filter user.gender with a filter that returns "female", "male" or "other" (because they are integers).{% trans 'This user blocked you.' context user.gender %}
| ||
|
To view this discussion on the web visit 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 django-users+unsubscribe@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/d6b61216-63cb-86f9-9467-61a18a964c21%40gmail.com.
On Thursday 02 March 2017 19:43:07 Uri Even-Chen wrote:
> Maybe this is a feature we can add to the next Django release? And
> then we will not have to "cheat"?
This would be a difficult thing to do, unless the trans tag is altered, cause otherwise how would specify the available contexts for a context? Your makemessages command would get complex.
Something like this maybe:
{%trans 'dancer' context_choices=gender_choices choice=request.user.gender %}
Then makemessages should generate a string with msgctxt for each of the choices. You could do this already, by rolling your own "trans" tag and "makemessages" command.
--
Melvyn Sopacua
Then makemessages should generate a string with msgctxt for each of the choices. You could do this already, by rolling your own "trans" tag and "makemessages" command.
On Thursday 02 March 2017 20:54:07 Uri Even-Chen wrote:
> > Then makemessages should generate a string with msgctxt for each of
> > the choices. You could do this already, by rolling your own "trans"
> > tag and "makemessages" command.
> >
> >
> I don't understand, how can I do it already? I want makemessages to
> generate a string with all the possible contexts (which may be for
> example 3 options or 9), and not to have to "cheat" it by {% if 0 %}
> etc. But how do I do it? By the way where is the makemessages code?
Wel, you can create your own commands:
https://docs.djangoproject.com/en/1.10/howto/custom-management-commands/
And your own tags:
https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/
So if waiting for a next release that may or may not have this functionality does not fit your timeline, this is what you can do.
--
Melvyn Sopacua
Hi,
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 %}(or maybe we should filter user.gender with a filter that returns "female", "male" or "other" (because they are integers).{% trans 'This user blocked you.' context user.gender %}
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"?
-- Jani Tiainen