From 839edcebb39f55acf163266f1ce1f0dc537de95b Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 12 Jun 2015 13:51:28 +0100 Subject: Fixed #21695 -- Added asvar option to blocktrans. Thanks Bojan Mihelac for the initial patch. --- docs/releases/1.9.txt | 3 +++ docs/topics/i18n/translation.txt | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 9f2dd6ccd1..b80d14f985 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -332,6 +332,9 @@ Internationalization project and it will find all the app message files that were created by :djadmin:`makemessages`. +* :ttag:`blocktrans` supports assigning its output to a variable using + ``asvar``. + Management Commands ^^^^^^^^^^^^^^^^^^^ diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index 1ab2dae273..e19ee1220b 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -580,8 +580,9 @@ use the following syntax:: {{ the_title }} -In practice you'll use this to get strings that are used in multiple places -or should be used as arguments for other template tags or filters:: +In practice you'll use this to get a string you can use in multiple places in a +template or so you can use the output as an argument for other template tags or +filters:: {% trans "starting point" as start %} {% trans "end point" as end %} @@ -682,6 +683,21 @@ be retrieved (and stored) beforehand:: This is a URL: {{ the_url }} {% endblocktrans %} +If you'd like to retrieve a translated string without displaying it, you can +use the following syntax:: + + {% blocktrans asvar the_title %}The title is {{ title }}.{% endblocktrans %} + {{ the_title }} + + +In practice you'll use this to get a string you can use in multiple places in a +template or so you can use the output as an argument for other template tags or +filters. + +.. versionchanged:: 1.9 + + The ``asvar`` syntax was added. + ``{% blocktrans %}`` also supports :ref:`contextual markers` using the ``context`` keyword: -- cgit v1.3