Opened 14 years ago

Closed 13 years ago

Last modified 13 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: dev
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 13 years ago.
14806.template-tags-pgettext.2.diff (14.5 KB ) - added by Julien Phalip 13 years ago.
14806.template-tags-pgettext.3.diff (28.7 KB ) - added by Julien Phalip 13 years ago.
14806.template-tags-pgettext.4.diff (29.8 KB ) - added by Julien Phalip 13 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 by Jani Tiainen, 14 years ago

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

comment:2 by Jannis Leidel, 14 years ago

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 by Jannis Leidel, 14 years ago

milestone: 1.4
Version: 1.3-alphaSVN

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

comment:4 by anonymous, 14 years ago

milestone: 1.4
Severity: Normal
Type: New feature

comment:5 by Julien Phalip, 13 years ago

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 by Aymeric Augustin, 13 years ago

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 13 years ago by Aymeric Augustin (next)

comment:7 by Claude Paroz, 13 years ago

Cc: claude@… added

comment:8 by Julien Phalip, 13 years ago

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.

by Julien Phalip, 13 years ago

by Julien Phalip, 13 years ago

comment:9 by Julien Phalip, 13 years ago

Needs documentation: unset
Needs tests: unset

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

by Julien Phalip, 13 years ago

comment:10 by Aymeric Augustin, 13 years ago

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.

by Julien Phalip, 13 years ago

comment:11 by Julien Phalip, 13 years ago

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 by Julien Phalip, 13 years ago

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 by Craig Blaszczyk, 13 years ago

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