haml,link_to helper和I18n在同一个句子中

这是我想要获得的标记:

View more clinic information including physicians, locations, directions, documents, and more.

我正在使用haml,yaml和Rails(哦,我的!)。 为了通过本地化做到这一点,我必须有这个yaml:

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

把我的haml放在3行上,如:

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

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

有没有办法将链接作为参数传递? 但是我必须在yaml中插入它,并且可能在那里放置标记? 这似乎也不是很好。 有一种优雅的方式可以做到这一点,我错过了吗?

最简单的方法是使用本地化视图 。 起初更换

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

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

随后您可以使用创建文件_view_more.en.html.haml

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

你在类似的问题上找到了更多的想法。 我最喜欢的是只使用两个翻译。

在您的语言环境中:

  view_more_details_html: "View more %{link} including physicians, locations, directions, documents, and more." link: "clinic information" 

只有一个观点:

 %p = I18n.t('view_more_details_html', link: link_to(I18n.t('link'), clinic))