37

Rails では、次の手順で送信ボタンの一般的な i18n が許可されていることがわかりましたconfig/locales/en.yml

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

createただし、特定の 1 つのモデルのみの値を更新しようとしています。テキストを「Upload %{model}」または単に「Upload」と読みたいです。1 つのモデル (例: モデル) だけにこの変更を加えるにはどうすればよいPhotoですか?

4

2 に答える 2

54
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

于 2012-11-25T01:03:13.613 に答える
9

i18n-debug gemを使用すると、Rails サーバーは次のような翻訳ルックアップ試行をコンソールに出力します。

[i18n-debug] en.helpers.submit.post.create => nil
于 2014-09-16T14:58:34.127 に答える