Symfony2 twig 在 {% trans %} 标签中翻译变量值 [英] Symfony2 twig translate variable values in {% trans %} tag

查看:18
本文介绍了Symfony2 twig 在 {% trans %} 标签中翻译变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个 Symfony2 项目,并有一个问题.在一个 twig 模板中,我从控制器接收到一个变量.这是一个字符串,我需要翻译它.但是语法

I'm working on a Symfony2 project and have a question from it. In one twig template I receive a variable from controller. It's a string and I need to translate it. But the syntax

{% trans %}{{ post['name'] }}{% endtrans %}

返回错误消息必须是...中的简单文本".

returns error "A message must be a simple text in...".

那么有没有办法翻译变量值???

So is there a way to translate the variable values???

推荐答案

使用 过滤器:

{{ post['name']|trans }}

这篇关于Symfony2 twig 在 {% trans %} 标签中翻译变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆