@@ -97,6 +97,9 @@ of text (called a *message*), use the
97
97
:method: `Symfony\\ Component\\ Translation\\ Translator::trans ` method. Suppose,
98
98
for example, that you're translating a simple message from inside a controller::
99
99
100
+ // ...
101
+ use Symfony\Component\HttpFoundation\Response;
102
+
100
103
public function indexAction()
101
104
{
102
105
$t = $this->get('translator')->trans('Symfony2 is great');
@@ -171,6 +174,9 @@ Message Placeholders
171
174
172
175
Sometimes, a message containing a variable needs to be translated::
173
176
177
+ // ...
178
+ use Symfony\Component\HttpFoundation\Response;
179
+
174
180
public function indexAction($name)
175
181
{
176
182
$t = $this->get('translator')->trans('Hello '.$name);
@@ -184,14 +190,17 @@ will try to look up the exact message, including the variable portions
184
190
for every possible iteration of the ``$name `` variable, you can replace the
185
191
variable with a "placeholder"::
186
192
193
+ // ...
194
+ use Symfony\Component\HttpFoundation\Response;
195
+
187
196
public function indexAction($name)
188
197
{
189
198
$t = $this->get('translator')->trans(
190
199
'Hello %name%',
191
200
array('%name%' => $name)
192
201
);
193
202
194
- new Response($t);
203
+ return new Response($t);
195
204
}
196
205
197
206
Symfony2 will now look for a translation of the raw message (``Hello %name% ``)
@@ -786,9 +795,9 @@ texts* and complex expressions:
786
795
787
796
Using the translation tags or filters have the same effect, but with
788
797
one subtle difference: automatic output escaping is only applied to
789
- variables translated using a filter. In other words, if you need to
790
- be sure that your translated variable is *not * output escaped, you must
791
- apply the raw filter after the translation filter:
798
+ translations using a filter. In other words, if you need to be sure
799
+ that your translated is *not * output escaped, you must apply the
800
+ `` raw `` filter after the translation filter:
792
801
793
802
.. code-block :: jinja
794
803
@@ -799,11 +808,9 @@ texts* and complex expressions:
799
808
800
809
{% set message = '<h3>foo</h3>' %}
801
810
802
- {# a variable translated via a filter is escaped by default #}
811
+ {# strings and variables translated via a filter is escaped by default #}
803
812
{{ message|trans|raw }}
804
-
805
- {# but static strings are never escaped #}
806
- {{ '<h3>foo</h3>'|trans }}
813
+ {{ '<h3>bar</h3>'|trans|raw }}
807
814
808
815
.. versionadded :: 2.1
809
816
You can now set the translation domain for an entire Twig template with a
0 commit comments