gpt4 book ai didi

ruby-on-rails - haml、link_to helper 和 I18n 在同一个句子中

转载 作者:行者123 更新时间:2023-12-02 21:28:11 26 4
gpt4 key购买 nike

这是我想要获取的标记:

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

我正在使用 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 中,也许还可以将标记放在那里?这看起来也不太好。有没有一种优雅的方法可以做到这一点,而我却缺少这种方法?

最佳答案

最简单的方法是使用Localized Views 。首先替换

%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.

关于ruby-on-rails - haml、link_to helper 和 I18n 在同一个句子中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23001268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com