【问题标题】:I18n for flash messages with parameters in RailsI18n 用于 Rails 中带有参数的 Flash 消息
【发布时间】:2013-09-20 07:52:54
【问题描述】:

如何向我的参数化和国际化错误消息添加参数?说,在我的控制器中有:

flash[:error] = t(:error)[:my_error_message] 

在 en.yml 中:

error:
  my_error_message: "This is the problem XXX already."      

【问题讨论】:

    标签: ruby-on-rails error-handling notifications notice rails-i18n


    【解决方案1】:

    为了您的快讯,

    flash[:error] = t('my_error_message', :problem => 'Big Problem')
    

    在您的 en.yml 中:

    error:
      my_error_message: "This is the problem %{problem} already."      
    

    【讨论】:

      【解决方案2】:
      t('error.my_error_message')
      

      或:

      t(:my_error_message, scope: :error)
      

      【讨论】:

        猜你喜欢
        • 2013-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-27
        相关资源
        最近更新 更多