Opened 5 years ago

Closed 4 years ago

Last modified 3 years ago

#14806 closed New feature (fixed)

No template tag to support contextual translations

Reported by: jtiai Owned by: julien
Component: Internationalization Version: master
Severity: Normal Keywords: i18n
Cc: claude@…, jakul 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 4 years ago.
14806.template-tags-pgettext.2.diff (14.5 KB) - added by julien 4 years ago.
14806.template-tags-pgettext.3.diff (28.7 KB) - added by julien 4 years ago.
14806.template-tags-pgettext.4.diff (29.8 KB) - added by julien 4 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 5 years ago by jtiai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from No template tag to support con to No template tag to support contextual translations

comment:2 Changed 5 years ago by jezdez

  • Component changed from Template system to Internationalization
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by jezdez

  • milestone set to 1.4
  • Version changed from 1.3-alpha to SVN

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

comment:4 Changed 4 years ago by anonymous

  • milestone 1.4 deleted
  • Severity set to Normal
  • Type set to New feature

comment:5 Changed 4 years ago by julien

  • Easy pickings unset
  • Owner changed from nobody to julien
  • UI/UX unset

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

comment:6 Changed 4 years ago by aaugustin

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 4 years ago by aaugustin (next)

comment:7 Changed 4 years ago by claudep

  • Cc claude@… added

comment:8 Changed 4 years ago by julien

  • 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 4 years ago by julien

Changed 4 years ago by julien

comment:9 Changed 4 years ago by julien

  • Needs documentation unset
  • Needs tests unset

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

Changed 4 years ago by julien

comment:10 Changed 4 years ago by aaugustin

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 4 years ago by julien

comment:11 Changed 4 years ago by julien

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 4 years ago by julien

  • Resolution set to fixed
  • Status changed from new to closed

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 3 years ago by jakul

  • Cc jakul added
Note: See TracTickets for help on using tickets.
Back to Top