【问题标题】:What is the best practice to use ENV vars with translations i18n from yml将 ENV vars 与来自 yml 的翻译 i18n 一起使用的最佳做法是什么
【发布时间】:2018-03-04 17:41:53
【问题描述】:

我有一个很长的 yml 文本,它应该在中间的某个地方有一个链接。我希望能够更改链接(来自我的 env 文件),但在 yml 中解析 ENV['link'] 似乎不正确。想法?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 rubygems yaml rails-i18n


    【解决方案1】:

    你可以试试Passing variables to translations:

    # app/views/home/index.html.erb
    <%=t 'greet_username', user: "Bill", message: "Goodbye" %>
    
    # config/locales/en.yml
    en:
      greet_username: "%{message}, %{user}!"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      相关资源
      最近更新 更多