#32356: Add url argument to translate tag -------------------------------------+------------------------------------- Reporter: Peter Bittner | Owner: nobody Type: New feature | Status: closed Component: | Version: master Internationalization | Severity: Normal | Resolution: invalid Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Description changed by Peter Bittner:
Old description: > == 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. > > * https://docs.djangoproject.com/en/stable/intro/tutorial01/ > * https://docs.djangoproject.com/en/stable/intro/tutorial03/ > * https://docs.djangoproject.com/en/stable/intro/tutorial04/ > > == 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 New description: == 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. * https://docs.djangoproject.com/en/stable/intro/tutorial01/ * https://docs.djangoproject.com/en/stable/intro/tutorial03/ * https://docs.djangoproject.com/en/stable/intro/tutorial04/ == 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 require passing in or specifying (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 -- -- Ticket URL: <https://code.djangoproject.com/ticket/32356#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.36cdd24c489f1a5fd04e3972cebfc83f%40djangoproject.com.