Rails 3,i18n:将html标签插入文本 [英] Rails 3, i18n: Interpolating html tags into text
本文介绍了Rails 3,i18n:将html标签插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题正是此问题中描述的问题.唯一的区别是:我使用的是Rails 3(完全是3.0.4),它使用的是%{...}
语法,而不是旧的{{...}}
.
My problem is exactly the one described in this question. Only difference: I'm using Rails 3 (3.0.4 exactly), which uses the %{...}
syntax rather than the old {{...}}
.
问题:Rails 3转义了%{...}
内部的所有标签,因此我无法在其中进行插补,例如链接.
Problem: Rails 3 escapes all tags inside %{...}
so I cannot interpolate, say, links in there.
有什么办法可以克服这个问题?
Is there any way to overcome this?
推荐答案
我终于弄清楚了,您必须使用_html
作为任何yaml-key的后缀,而您不想使用html进行转义:>
I finally figured it out, you have to use _html
as a suffix for any yaml-keys, that you do not want html-escaped:
paragraph_html: "This is some text with a %{link}"
paragraph_linktext: "really cool link"
然后
link = link_to t( paragraph_linktext ), "http://www.example.com"
<%= t( paragraph_html, :link => link ) %>
然后瞧,您到处都有i18n链接.
and voila, there you have your i18n-ized link.
这篇关于Rails 3,i18n:将html标签插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文