haml,link_to helper和同一个句子中的I18n [英] haml, link_to helper, and I18n in the same sentence

查看:111
本文介绍了haml,link_to helper和同一个句子中的I18n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要获得的标记:

Here is the markup I'm trying to get:

<p>View more <a href="/clinics/integratedclinic">clinic information</a> 
including physicians, locations, directions, documents, and more.</p>

我正在使用haml,yaml和Rails(天哪!).为了实现本地化,我必须有这个yaml:

I'm using haml, yaml, and Rails (oh my!). In order to do this with localization, I have to have this yaml:

en:
  view_more: View more
  link: clinic information
  details: including physicians, locations, directions, documents, and more.

然后将我的haml放在3行上:

And put my haml on 3 lines like:

%p
  = I18n.t('view_more')
  = link_to I18n.t('link'), clinic
  = I18n.t('details')

似乎必须有一个更好的方法.第一个问题是,这对于具有不同语法的语言将不起作用,其中由于语法上的单词顺序,链接可能会出现在句子的末尾.

It seems like there's got to be a better way. The first issue is that this wouldn't work for languages with different syntax, in which the link might occur at the end of the sentence because of grammatical word order.

没有办法将链接作为参数传递吗?但是然后我必须在yaml中进行插值,也许在其中添加标记?看起来也不太好.是否有一种优雅的方式来实现我所缺少的?

Isn't there a way to pass the link in as a parameter? But then I have to interpolate it in the yaml, and maybe put markup in there? That doesn't seem great, either. Is there an elegant way to do this that I'm missing?

推荐答案

最简单的方法是使用本地化视图.首先替换

The simplest way is using Localized Views. At first replace

%p
  = I18n.t('view_more')
  = link_to I18n.t('link'), clinic
  = I18n.t('details')

使用

= render partial: 'view_more', locals: { url: some_path }

随后,您可以使用

%p
  View more
  = link_to 'clinic information', url
  including physicians, locations, directions, documents, and more.

这篇关于haml,link_to helper和同一个句子中的I18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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