【问题标题】:Using multiple variables in symfony translation strings without whitespace在没有空格的 symfony 翻译字符串中使用多个变量
【发布时间】:2015-03-13 17:41:52
【问题描述】:

如何在 symfony 翻译字符串中使用多个变量,它们之间没有空格?

这个例子有效,但变量之间有空格

{% trans with {
'%name%': customer.getPlausibleFirstName(),
'%city%': customer.getCity(),
'%accentStart%': '<strong>',
 '%accentEnd%': '</strong>',
 }%}%accentStart% %name% %accentEnd% from %accentStart% %city% %accentEnd% would like a quote{% endtrans %}

我真正想做的是:

{% trans with {
'%name%': customer.getPlausibleFirstName(),
'%city%': customer.getCity(),
'%accentStart%': '<strong>',
 '%accentEnd%': '</strong>',
 }%}%accentStart%%name%%accentEnd% from %accentStart%%city%%accentEnd% would like a quote{% endtrans %}

最后一个版本抛出以下错误:

Variable " from " does not exist in ApplicationBundle:Default:header.html.twig at line 13

我该如何解决这个问题?

【问题讨论】:

    标签: php symfony twig translate


    【解决方案1】:

    用另一个字符示例替换“%”:“|”

    {% trans with {
        '|name|': customer.getPlausibleFirstName(),
        '|city|': customer.getCity(),
        '|accentStart|': '<strong>',
        '|accentEnd|': '</strong>',
        }%}|accentStart||name||accentEnd| from |accentStart||city||accentEnd| would like a quote{% endtrans %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      相关资源
      最近更新 更多