Opened 4 years ago

Last modified 4 years ago

#32356 closed New feature

Add url argument to translate tag — at Version 2

Reported by: Peter Bittner Owned by: nobody
Component: Internationalization Version: dev
Severity: Normal Keywords:
Cc: Claude Paroz Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Peter Bittner)

Context

Correct translation of extracted text is difficult without appropriate context. That's why Django offers the "context" argument to the "translate" (former "trans") tag and the "pgettext" functions, to add a text description to the generated entry in PO files.

However, this is rarely enough. Especially for translators, which often are not developers, a description only is not enough, not even when supported by a file location (file name + line number). A supporting image (e.g. screenshot) or a link to the live (Web) application would yield better translation support.

Proposal

Hence, we should add a "url" argument, in addition to "context", to the "translate" tag.

The value of the "url" should generate a "#:" prefixed comment, a reference in PO file terms. See https://www.gnu.org/software/gettext/manual/gettext.html#PO-Files

That value may then be flexibly used by translation tools to their liking (e.g. Rosetta may decide to generate links in their Web UI in the "Occurrence(s)" column).

Examples

{% translate "Vote again?" context "Polls app tutorial results page" url "https://examples.djangoproject.org/polls/1/" %}

or

{% url 'polls:detail' question.id as results_page_path %}

{% translate "Vote again?" context "Polls app tutorial results page" url results_page_path %}

would result in

#: polls/templates/polls/results.html:10
#: https://examples.djangoproject.org/polls/1/
#, fuzzy
msgctxt "Polls app tutorial results page"
msgid "Vote again?"
msgstr "Wieder abstimmen?"

See Django's polls app tutorial for a development context, e.g.

Technical notes

For simplicity we may only hold simple text in the "url" value. But, as simple text and hard-coded URL paths outdate fairly easily, we may want to use Django's URL resolving features, namely:

django.shortcuts.resolve_url(to, *args, **kwargs)

The example above shows a way that may need little technical implementation, and no new concepts to learn. To make the generated URL base value useful this may required to pass in or specify (e.g. in the Django settings) some values used for generation of usable URLs.

Related source code

template tag (django.templatetags.i18n)
https://github.com/django/django/blob/master/django/templatetags/i18n.py
gettext functions (django.utils.module)
https://github.com/django/django/blob/master/django/utils/translation/__init__.py
management command (django.core.management.commands.makemessages)
https://github.com/django/django/blob/master/django/core/management/commands/makemessages.py

Change History (2)

comment:1 by Peter Bittner, 4 years ago

Type: UncategorizedNew feature

comment:2 by Peter Bittner, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top