39

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

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)?

jbatista
  • 964
  • 2
  • 11
  • 26
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218

2 Answers2

57
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

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82
10

If you use the i18n-debug gem, the rails server will print translations look-up attempts to the console, like:

[i18n-debug] en.helpers.submit.post.create => nil
Jason
  • 9,408
  • 5
  • 36
  • 36
  • 6
    The rails-18n-debug gem this answer links to is nice, but deprecated and the author now recommends to use the alternative gem at https://github.com/fphilipe/i18n-debug – DannyB Aug 13 '15 at 16:43