【问题标题】:Passing argument to all Rails translations without modifying all translation calls将参数传递给所有 Rails 翻译而不修改所有翻译调用
【发布时间】:2012-09-19 12:07:39
【问题描述】:

将参数传递给单个翻译很容易(来自指南):

# app/views/home/index.html.erb
<%=t 'greet_username', :user => "Bill", :message => "Goodbye" %>

# config/locales/en.yml
en:
  greet_username: "%{message}, %{user}!"

[edit] 是否可以将参数传递给所有翻译而不需要修改所有翻译调用?所以我可以在所有翻译中使用 %{my_variable} 但参数只会传递一次,就像全局翻译参数一样

【问题讨论】:

    标签: ruby-on-rails ruby internationalization


    【解决方案1】:
    # app/views/home/index.html.erb
    <%=t 'greet_username', :my_variable=> "Bill Goodbye" %>
    
    # config/locales/en.yml
    en:
      greet_username: "%{my_variable} !"
    

    【讨论】:

      猜你喜欢
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      相关资源
      最近更新 更多