I18n 用于特定于模型的 Rails 提交按钮 [英] I18n for model-specific Rails submit button

查看:9
本文介绍了I18n 用于特定于模型的 Rails 提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've found that Rails allows for generic i18n of submit buttons via the following in config/locales/en.yml:

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

但是,我希望仅为一个特定模型更新 create 值.我希望文本读作上传 %{model}"或只是上传".如何仅对一个模型(例如:Photo 模型)进行此更改?

However, I'm looking to update the create value only for one specific model. I'd like the text to read as "Upload %{model}" or just "Upload". How can I make this change for just one model (e.g.: a Photo model)?

推荐答案

Those labels can be customized using I18n under the +helpers.submit+ key 
and using %{model} for translation interpolation:

  en:
    helpers:
      submit:
        create: "Create a %{model}"
        update: "Confirm changes to %{model}"

It also searches for a key specific to the given object:

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

来源@actionview/lib/action_view/helpers/form_helper.rb

这篇关于I18n 用于特定于模型的 Rails 提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆