【问题标题】:How to use paths with locale inside YAML localization files?如何在 YAML 本地化文件中使用带有语言环境的路径?
【发布时间】:2023-04-09 01:06:02
【问题描述】:

在我的 Ruby on Rails 应用程序的本地化文件中,我有许多这样的路径:

en:
  hello_html: "Feel free to <a href=\"/contact\">contact us</a> at any time."

问题在于 this 指向 mydomain.com/contact 而不是 mydomain.com/en/contactmydomain.com/fr/contact

如何在手动传递语言环境(例如使用插值)的情况下做到这一点?

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails ruby yaml


    【解决方案1】:

    您以错误的方式使用翻译系统。你应该这样使用它:

    # en.yml
      hello_html: "Feel free to %{contact_link} at any time."
    
    # view
    <%= t('hello_html', contact_link: link_to("Contact", contact_path(locale: current_locale)) %>
    

    更加嵌套!

    <% contact_str = t('menus.contact') %>
    <% contact_link = link_to contact_str, contact_path %>
    <%= t('hello_html', contact_link: contact_link) %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多