Skip to content

Internationalize all model error messages #7793

@david-yz-liu

Description

@david-yz-liu

While built-in model validations are internationalized, several of our custom model validations use English string literals, e.g.

def associated_user_is_an_admin
unless self.user.nil? || self.user.admin_user?
errors.add(:base, 'only admin users can be assigned the admin role')
end
end
end

We should internationalize all of these strings. We can follow the same structure as the built-in error message scopes, e.g.

en:
  activerecord
    errors:
      models:
        admin_role:
          associated_user_is_an_admin: "Only admin users..."

and then in the model,

  def associated_user_is_an_admin
    unless self.user.nil? || self.user.admin_user?
      errors.add(:base, :associated_user_is_an_admin)
    end
  end

See also Errors#add.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions