Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

symfony - Symfony2: HTML inside translation message

In messages.en.yml, I have

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 ... 

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


Update

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

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

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.

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...