0

I'm using Rails 5.2.1, and trying to override the names of some ActiveRecord models and fields.

I know that Rails is picking up the English locale file because when I add the following to locales/en.yml, my form labels are updated to the correct values:

en:
  activerecord:
    models:
      seller_address: "Address"
    attributes:
      seller_address:
        name: "Name"
        street1: "Street Line 1"
        postal_code: "Postal Code"

But when I call @seller_address.errors.full_messages I'm still seeing the old field and model values. For example, this:

Seller addresses name can't be blank

Seller addresses street1 can't be blank

Seller addresses postal code can't be blank

should be this:

Addresses Name can't be blank

Addresses Street Line 1 can't be blank

Addresses Postal Code can't be blank

What can I do to tell Rails to use my locale overrides for ActiveRecord validation error messages?

yakattack
  • 159
  • 2
  • 4

1 Answers1

0

You need to define i18n errors like this in your errors.en.yml file.

en:
  activerecord:
      attributes:
      errors:
        full_messages:
          format: "%{attribute} %{message}"         # You can change your error format here.
        models:
        seller_address:
          attributes:
            name:
              blank: 'Addresses Name can't be blank.'
            street1:
              blank: 'Addresses Street Line 1 can't be blank.'
Anurag Aryan
  • 611
  • 6
  • 16
  • Updating my locale file to this produced the following error message: "Seller addresses street1 Addresses Street Line 1 can't be blank." I'm starting to think you can't use .full_messages with locale file based i18n. – yakattack Jan 23 '18 at 21:09
  • @yakattack If you just want the message you can change the full_messages format to have just the `%{message}`. – Anurag Aryan Jan 23 '18 at 21:14