【问题标题】:Symfony 2.8 - Assign YAML variable under sentance variableSymfony 2.8 - 在语句变量下分配 YAML 变量
【发布时间】:2019-10-15 10:33:17
【问题描述】:

我有一个像这样的 YAML 变量

test: 'Hello jack, please update your profile'

我想在另一个变量上命名,并在句子下赋值

test: 'Hello %name%, please update your profile'
name: 'jack'

但是这个办法,不行,有什么办法吗?

【问题讨论】:

  • doesn't work 是什么意思?您是否收到错误或变量无法识别?您是在 Symfony 配置、翻译或其他自定义用例中使用它吗?
  • 你的导师怎么说?通常有一些选项可以获得课堂作业的帮助。
  • @dbrumann,是的,我在翻译时使用它,消息显示如下Hello %name%, please update your profile

标签: symfony yaml


【解决方案1】:

Symfony 翻译组件允许'message placeholders'

yaml 文件:

# translations/app.en.yaml ('app' is the 'message domain')
say_hello: 'Hello {name}, please update your profile'

来自 PHP

// prints "Hello ....!"
echo $translator->trans('say_hello', ['name' => 'Sayou']);

使用Twig Templates

{% trans with {'%name%': 'Sayou'} from 'app' %}say_hello{% endtrans %}

Twig 的输出:

你好,Sayou,请更新你的个人资料

【讨论】:

    猜你喜欢
    • 2014-12-04
    • 1970-01-01
    • 2018-04-02
    • 2018-07-31
    • 1970-01-01
    • 2013-05-07
    • 2011-09-09
    • 2014-03-05
    • 1970-01-01
    相关资源
    最近更新 更多