Symfony2 + Twig,翻译中的变量返回“消息必须是简单文本". [英] Symfony2+Twig, variable in translation return "A message must be a simple text"

查看:115
本文介绍了Symfony2 + Twig,翻译中的变量返回“消息必须是简单文本".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我做普通的PHP时,我只是在这样做:

When I was doing plain PHP, I was simply doing this:

printf(_("Hello %s !"), $name);

现在有了Twig,我必须使用trans标签.因此,我已经复制/粘贴了文档示例,这是我的完整模板:

Now with Twig, I must use the trans tag. So I've copy/paste the documentation example, and here's my full template:

{% extends 'MyAppBundle::layout.html.twig' %}

{% block content %}
    <h1>
        {% trans %}
            Hello {{ name }}!
        {% endtrans %}
    </h1>
{% endblock %}

Symfony为什么返回以下证据?

Why Symfony return the following exeption ?

消息必须是"MyAppBundle :: home.html.twig"中的简单文本

A message must be a simple text in "MyAppBundle::home.html.twig"

500内部服务器错误-Twig_Error_Syntax

500 Internal Server Error - Twig_Error_Syntax

推荐答案

Symfony2中的翻译精确语法与独立的Twig中的翻译精确语法略有不同.您需要查看Symfony2文档,以了解在树枝模板中进行翻译的情况,该文档位于这里.正确的语法如下所示:

The precise syntax for translations is a little different in Symfony2 than it is in standalone Twig. You'll want to check out the Symfony2 documentation for translations in twig templates, found here. The correct syntax would look something like this:

{% trans %}Hello %name%!{% endtrans %}

这篇关于Symfony2 + Twig,翻译中的变量返回“消息必须是简单文本".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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