简体   繁体   English

树枝消息翻译

[英]Twig message translation

I have been learning php and symfony for the last 2 days, working through a video tutorial as I need to learn to use php and symfony etc as the front end to a spring app written in java. 在过去的两天里,我一直在学习php和symfony,并通过一个视频教程进行学习,因为我需要学习使用php和symfony等作为用Java编写的spring应用程序的前端。

I am at the section on invalid logins and there is something I just cant get my head around, I dont know if its the syntax or what but it really isnt clear what is happening here: 我在关于无效登录的部分,有一些我只是无法理解的东西,我不知道它的语法是什么还是什么,但实际上不清楚这里发生了什么:

{% if error %}
        <div>{{error.messageKey|trans(error.messageData, 'security') }}</div>
    {% endif %}

I understand the error object is available implicitly as the framework puts it there but what is happening? 我了解到错误对象在框架中被隐式地提供,但是发生了什么? It looks like the messageKey value is being piped into the trans function but what is that function doing? 看起来messageKey值正在传递到trans函数中,但是该函数在做什么?

If I just print out error.messageKey without the trans functions its the same, is the pipe symbol an OR and not a pipe in this instance? 如果我只打印出error.messageKey而没有trans函数,则管道符号是OR而不是此实例中的管道吗?

The pipe symbol is a twig 'filter'. 管道符号是一个细枝“过滤器”。 It tell symfony and twig that the text at his left need to be translated. 它告诉symfony和细枝,他左边的文本需要翻译。

Read more about it here http://symfony.com/doc/current/book/translation.html 在此处详细了解它http://symfony.com/doc/current/book/translation.html

From the comment : 从评论:

It looks like sometimes that exception Authentication could contain a placeholder array of values which are then used to transpose the error.messageKey which is the actual message string but in the example I am following the array of placeholders is actually empty and the string does not contain and %var% placeholders anyway so I always get the standard "Invalid credentials." 看起来有时异常身份验证可能包含一个值的占位符数组,然后用于转置error.messageKey,它是实际的消息字符串,但在示例中,我关注的是占位符数组实际上为空,并且该字符串不包含和%var%占位符,所以我总是得到标准的“无效凭据”。 <div>{{ 'Invalid %vara% %name%' |trans({'%name%': 'Steve', '%vara%':'login'}, "app") }}</div> – berimbolo <div>{{ 'Invalid %vara% %name%' |trans({'%name%': 'Steve', '%vara%':'login'}, "app") }}</div> –贝里姆博洛

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM