I18n用于特定于模型的Rails提交按钮

时间:2012-11-25 00:31:41

标签: ruby-on-rails internationalization

我发现Rails通过config/locales/en.yml中的以下内容允许提交按钮的通用i18n:

en:
  helpers:
    submit:
      create: "Create %{model}"
      submit: "Save %{model}"
      update: "Update %{model}"

但是,我希望仅针对一个特定模型更新create值。我希望文本显示为“上传%{model}”或只是“上传”。如何仅对一个模型进行此更改(例如:a Photo模型)?

2 个答案:

答案 0 :(得分:42)

source code开始,看起来你应该可以这样做:

en:
  helpers:
    submit:
      post:
        create: "Upload %{model}"

其中post是模型的名称。 inline docs也提到你可以这样做。

答案 1 :(得分:9)

如果您使用i18n-debug gem,则rails服务器将打印对控制台的翻译查找尝试,例如:

[i18n-debug] en.helpers.submit.post.create => nil