我想 i18n 一个文本,看起来像这样:
- 已经注册了?-登陆!
请注意,文本上有一个链接。在这个例子中,它指向谷歌-在现实中,它将指向我的应用程序的 log_in_path
。
我找到了两种方法,但没有一种看起来是“正确的”。
我知道的第一个方法就是把这个放在我的 en.yml
上:
log_in_message: "Already signed up? <a href='{{url}}'>Log in!</a>"
在我看来:
<p> <%= t('log_in_message', :url => login_path) %> </p>
这是 工程,但是在 en.yml
上有 <a href=...</a>
的部分看起来不是很干净。
我知道的另一种选择是使用 局部景观局部景观局部景观局部景观-login.en.html.erb
和 login.es.html.erb
。
这种感觉也不对,因为唯一不同的行就是前面提到的那一行; 视图的其余部分(大约30行)将对所有视图重复。不会很干。
我想我可以使用“本地化的部分”,但这似乎太累赘; 我认为我更喜欢第一个选项有这么多微小的视图文件。
因此,我的问题是: 有没有一种“适当”的方式来实现这一点?