Symfony2+Twig,翻译中的变量返回“A message must be a simple text"; [英] Symfony2+Twig, variable in translation return "A message must be a simple text"

查看:12
本文介绍了Symfony2+Twig,翻译中的变量返回“A message must be a simple text";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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 %}

Why Symfony return the following exeption ?

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

500 Internal Server Error - Twig_Error_Syntax

解决方案

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,翻译中的变量返回“A message must be a simple text";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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