Rails i18n gem 从非英语语言环境的错误消息中排除属性名称

Rails i18n gem excludes attribute name from error messages for non-English locale

我正在开发的 Rails 应用程序使用日语语言环境。 为了对错误消息使用默认翻译,我安装了 rails-i18n gem,但我无法让它显示完整的错误消息。

# Locale configuration in application.rb
config.i18n.default_locale = :ja

在安装此 gem 之前,验证错误的错误消息告诉我翻译丢失,正如预期的那样。

*** ActiveRecord::RecordInvalid Exception: translation missing: ja.activerecord.errors.messages.record_invalid

然而,即使在安装 gem 之后,同一消息的日文翻译也不包含验证失败的属性。最后一个冒号后的空白 space 应该是属性名称。

*** ActiveRecord::RecordInvalid Exception: バリデーションに失敗しました: を入力してください

为了说明,这是将语言环境设置为 :en 时错误消息的样子。在日语中,好像缺少列名 First name,因此错误消息显示为 <No subject> can't be blank.

*** ActiveRecord::RecordInvalid Exception: Validation failed: First name can't be blank

我在这里错过了什么?我需要一些额外的配置吗? 提前感谢您的帮助。


注:我用的是rails6.0.0.

正如@demir 所怀疑的那样,这是因为修改了错误消息格式的配置。这导致错误消息中省略了 attribute 部分。

# Original format
format: "%{attribute} %{message}"

# Configured format
format: "%{message}"