Symfony2:翻译消息中的 HTML [英] Symfony2: HTML inside translation message

查看:26
本文介绍了Symfony2:翻译消息中的 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

messages.en.yml 中,我有

confirmed: Congrats %username%, your account is now activated.

但我想以粗体"用户名为例……我该怎么做?

But I want to 'bold' username to example ... how can I made this ?

confirmed: Congrats <span class='bold'>%username%</span>, your account is now activated.   

当然我可以在这个例子中使用两个句子

Of course I could use two sentence in this example like

first: Congrats
second: , your account ... 

在树枝内部使用 html 标签,但这看起来很脏.

and inside twig use the html tag but this seems very dirty.

推荐答案

更新 2

在这种情况下,我开始这样使用:

Update 2

In such cases, I started to use like this:

confirmed: Congrats %start_link%%username%%end_link%, your account is now activated

由于维护了关注点分离,因此强烈推荐这种方式.

Since separation of concerns is maintained, this way is strongly recommended.

在 YAML 中,我使用过这样的翻译没有任何问题:

In YAML, I have used translations like this without any problem:

trans.key: click <a href="%url%">here</a> to continue

<小时>

虽然翻译和设计应该分开,但在某些情况下,您必须在翻译文件中使用 html 标签,因为在 Facebook 和 Twitter 等大型项目中也可以看到.


Although translations and design should be kept separated there are always some situations that you must use html tags inside translation files as it is also seen in huge projects like Facebook and Twitter.

在这种情况下,您可以使用 XLIFF 格式,该格式被推荐交响乐.内部翻译文件:

In such situations, you can use XLIFF format which is being recommended by Symfony. Inside translation file:

<trans-unit id="1">
   <source>confirmed</source>
   <target>Congrats <![CDATA[<span class='bold'>%username%</span>]]> , your account is now activated.</target>
</trans-unit>

这篇关于Symfony2:翻译消息中的 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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