Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#14806 closed New feature (fixed)

No template tag to support contextual translations

Reported by: Jani Tiainen Owned by: Julien Phalip
Component: Internationalization Version: master
Severity: Normal Keywords: i18n
Cc: claude@…, Craig Blaszczyk Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Implementation of #9988 provides only Python side solution. There is no built-in tag for contextual translations for templates.

Attachments (4)

14806.template-tags-pgettext.diff (14.5 KB) - added by Julien Phalip 5 years ago.
14806.template-tags-pgettext.2.diff (14.5 KB) - added by Julien Phalip 5 years ago.
14806.template-tags-pgettext.3.diff (28.7 KB) - added by Julien Phalip 5 years ago.
14806.template-tags-pgettext.4.diff (29.8 KB) - added by Julien Phalip 5 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 6 years ago by Jani Tiainen

Summary: No template tag to support conNo template tag to support contextual translations

comment:2 Changed 6 years ago by Jannis Leidel

Component: Template systemInternationalization
Triage Stage: UnreviewedAccepted

Yeah, this would probably should look like this:

with blocktrans

{% blocktrans with article.price as amount count i.length as years context "price" %}
    That will cost $ {{ amount }} per year.
{% plural %}
    That will cost $ {{ amount }} per {{ years }} years.
{% endblocktrans %}

with trans:

{% trans "yeah" context "greeting" noop %}

comment:3 Changed 6 years ago by Jannis Leidel

milestone: 1.4
Version: 1.3-alphaSVN

Unfortunately we are in feature freeze mode, pushing to 1.4.

comment:4 Changed 6 years ago by anonymous

milestone: 1.4
Severity: Normal
Type: New feature

comment:5 Changed 5 years ago by Julien Phalip

Easy pickings: unset
Owner: changed from nobody to Julien Phalip
UI/UX: unset

I'm working on this. Will post a patch soon.

comment:6 Changed 5 years ago by Aymeric Augustin

herve (who reported #17045, a duplicate) is already working on a patch. He's "herve" on FreeNode too, you may want to check his status first.

Version 0, edited 5 years ago by Aymeric Augustin (next)

comment:7 Changed 5 years ago by Claude Paroz

Cc: claude@… added

comment:8 Changed 5 years ago by Julien Phalip

Needs documentation: set
Needs tests: set

I've posted a work in progress. {% Blocktrans %} and {% trans %} are both implemented, although only there are only tests for {% blocktrans %} at this stage. This will also need docs.

Changed 5 years ago by Julien Phalip

Changed 5 years ago by Julien Phalip

comment:9 Changed 5 years ago by Julien Phalip

Needs documentation: unset
Needs tests: unset

OK, I think that's it. Any feedback welcome. Thanks!

Changed 5 years ago by Julien Phalip

comment:10 Changed 5 years ago by Aymeric Augustin

The patch looks very good and the documentation is clear.

I have only one question: shouldn't this example read context "greeting" rather than context="greeting"? It looks inconsistent with the docstring of do_block_translate and the regexps.

{% blocktrans with name=user.username context="greeting" %}Hi {{ name }}{% endblocktrans %} 

Unfortunately, I couldn't apply the patch to my checkout, even with git apply:

error: cannot apply binary patch to 'tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo' without full index line
error: tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo: patch does not apply

As a consequence, my review is based on code inspection. I didn't run the tests, but they look solid.

Changed 5 years ago by Julien Phalip

comment:11 Changed 5 years ago by Julien Phalip

That's right, the syntax is context "xxx" and not context="xxx" -- I've fixed the doc example in the latest patch. I've also regenerated the *.mo file. I hope it works this time. Thanks for looking at the patch!

comment:12 Changed 5 years ago by Julien Phalip

Resolution: fixed
Status: newclosed

In [17015]:

Fixed #14806 -- Added support for contextual translations to the trans and blocktrans template tags. Thanks to jtiai for the report.

comment:13 Changed 5 years ago by Craig Blaszczyk

Cc: Craig Blaszczyk added
Note: See TracTickets for help on using tickets.
Back to Top