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

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

不过,我希望只更新一个特定型号的create值.我想把文字改为"上传%{model}"或"上传".如何仅对一个型号(例如:Photo型号)进行此更改?

推荐答案

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}"

Source @ actionview/lib/action_view/helpers/form_helper.rb

Ruby-on-rails相关问答推荐

DELETE_IF和REJECT的意外行为!方法

为Rails服务器推荐的交付类型

在Ruby on Rails中获取堆栈级别太深错误(&Q)

在Rails中,如何将帮助器方法添加到属性/列?

如何将 ActionController::RoutingError 分类为 Sentry 中的错误

Rails 7,Hotwire 动态表单,更新值不起作用

线程如何在 Web 应用程序中工作?

Ruby on rails 查询不知道怎么写

Rails ActiveRecord 中的更新插入

Heroku 应用程序上的远程 mysql 数据库

如何在 IRB/Rails 控制台中 suppress 返回值的输出?

键入rails 控制台无法启动?

带有 simple_form 的按钮内的 HTML 代码

如何在 YAML 中声明带有单引号和双引号的字符串?

Rails 模型:您将如何创建一组预定义的属性?

可以在 Rails/ActiveRecord 中使用 NULL 指定唯一索引吗?

ruby 方法名称中的变量

设计:为什么我的注销链接不起作用?

简单的 rails rake 任务拒绝运行并出现错误不知道如何构建任务,为什么?

如何删除特殊字符?