【问题标题】:Twig interpolate variable into translated stringTwig 将变量内插到翻译后的字符串中
【发布时间】:2016-09-25 11:40:39
【问题描述】:

我有一个 Sylius 实例,其翻译文件已配置且工作正常

现在只需在我的twig 中使用这样的 sn-p:

{{ 'project.sylius.frontend.header.label'|trans }}

它从yaml 翻译文件中检索正确的字符串:

project.sylius.frontend.header.title: Welcome here

我想知道的是,如果有机会将带有插值标记的字符串直接存储在yaml中, 像这样:

project.sylius.frontend.cart_number: you are going to buy %n candies
project.sylius.frontend.delivery: delivery will be between the %whatever and %whatever

以及如何在twig文件中传递变量

【问题讨论】:

    标签: symfony twig translation sylius


    【解决方案1】:

    您可以将变量作为数组的第一个参数传递给 trans 过滤器,例如:

    yaml:

    project.sylius.frontend.cart_number: you are going to buy %number% candies
    

    树枝

    {{ 'project.sylius.frontend.cart_number '|trans({'%number%': '4'}) }}
    

    看看pluralization features

    希望有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 2016-01-17
      • 1970-01-01
      • 2017-05-11
      • 2017-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多