Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails haml、link_to helper和I18n在同一句中_Ruby On Rails_Internationalization_Haml_Yaml - Fatal编程技术网

Ruby on rails haml、link_to helper和I18n在同一句中

Ruby on rails haml、link_to helper和I18n在同一句中,ruby-on-rails,internationalization,haml,yaml,Ruby On Rails,Internationalization,Haml,Yaml,以下是我试图获取的标记: <p>View more <a href="/clinics/integratedclinic">clinic information</a> including physicians, locations, directions, documents, and more.</p> 把我的haml放在3行上,比如: %p = I18n.t('view_more') = link_to I18n.t('link'

以下是我试图获取的标记:

<p>View more <a href="/clinics/integratedclinic">clinic information</a> 
including physicians, locations, directions, documents, and more.</p>
把我的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')

随后,您可以使用创建文件
\u view\u 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))

那很酷。我不知道本地化视图。如果没有其他人提供任何恒星的东西,我会回过头来标记这个正确。这里的问题是,如果你必须改变链接,你可以在两个地方改变它。别以为有什么办法。我已经更新了答案的代码,所以你不必再更改URL两次。这是一个2年半的问题,但谢谢你的回答!事实上,我比我接受的那本书更喜欢它。@nickcoxdotme答案不仅是给你的,也是给所有其他读者的。我在谷歌上找到了第二个问题。
  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))