在Twig中使用Transchoice的纯文本中断行(Symfony2)

时间:2014-01-09 08:48:30

标签: symfony twig

我正在编写一个纯文本邮件版本,我需要\ n用于新行。

几乎一切正常但我的transchoice过滤器有问题,正如我在断行被打印为文本而不是断行之前所说的那样

foo.twig.txt

{{ 'Foo.plain.intro'|transchoice(nr, {'%nr%': nr, '%name%': entity.name}) }}

messages.en

首先尝试:

Foo.hello.test: '{1} Hello %name% \n there is one test found. \n See you later. | ]1,Inf[ Hello %name%, \n  there are %nr% tests found. \n See you later.'

第一次尝试后,一个元素的输出是:

Hello tester \n there is one test found. \n See you later.

第二次尝试:

Foo.hello.test:  "{1} Hello %name% \n there is one test found. \n See you later. | ]1,Inf[ Hello %name%, \n  there are %nr% tests found. \n See you later."

第二次输出:

{1} Hello tester
there is one test found.
See you later.

第三次尝试:

Foo.hello.test:  '{1} "Hello %name% \n there is one test found. \n See you later." | ]1,Inf[ "Hello %name%, \n  there are %nr% tests found. \n See you later."'

第三输出:

"Hello tester \n there is one test found \n See you later."

我还尝试更改包括原始过滤器的树枝部分:

{{ 'Foo.plain.intro'|transchoice(nr, {'%nr%': nr, '%name%': entity.name})|raw }}

对于第三次尝试,包括原始过滤器,输出为:

"Hello tester \n there is one test found \n See you later."

是否存在类似的形式,对于普通翻译字符串,翻译必须使用双引号来识别\ n:

messages.en

Foo.hello: "Hello %name%, \n see you later"

1 个答案:

答案 0 :(得分:0)

您可以使用|来表示换行符。

Foo.hello: |
  Hello %name%, 
  see you later

阅读 yaml format