可以在 Symfony2 + Twig 中使用变量进行翻译吗? [英] Translating using variables in Symfony2 + Twig is possible?

查看:30
本文介绍了可以在 Symfony2 + Twig 中使用变量进行翻译吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个输出未翻译的字符串:

The first output the string not translated:

{{ chart.name~'.short'|trans({}, "charts") }}

这个有效(与 chart.name~'.short' 应该输出的文本相同):

This one works (is the same text that chart.name~'.short' should output):

{{ 'charts.region.area.short'|trans({}, "charts") }}

我错过了什么吗?在 Twig 中翻译动态文本似乎是不可能的?

Am i missing something? It seems it's impossible to translating dynamic text in Twig?

编辑:工作设置一个变量(为什么?):

EDIT: working setting a variable (why?):

{% set name = chart.name ~ '.short' %}
{{ name|trans({}, "charts") }}

推荐答案

Symfony/Twig 正在尝试翻译 .short 并将其与 chart.name 的内容连接起来.使用括号获得预期输出:

Symfony/Twig is trying to translate .short and concatenate it with contents of chart.name. Use parentheses to get the expected output:

{{ (chart.name~'.short')|trans({}, "charts") }}

这篇关于可以在 Symfony2 + Twig 中使用变量进行翻译吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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