LoginSignup
1
1

More than 3 years have passed since last update.

【Rails】error prohibited this user from being saved:のエラーメッセージがi18nで日本語化されない

Posted at

日本語化されない

下記のURLをもとにエラーメッセージを作成。
https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/ja.yml
template:
body: 次の項目を確認してください
header:
one: "%{modelにエラーが発生しました"
other: "%{model}に%{count}個のエラーが発生しました

しかしerror prohibited this user from being saved:のエラーメッセージだけが日本語化されない。

3fa1148b8a5369418ce366ab9e0515a3.png

結論

エラーメッセージ部分を下記のように変更する。
<%= t("errors.template.header", model: User.model_name.human, count: user.errors.count) %>

解決方法

最初、下記のようにエラーメッセージを書いていた。
<%= pluralize(user.errors.count,"error") %> prohibited this user from being saved:

下記のURL参照し書き直してみる。
http://artisan.hatenablog.com/entry/20110126/1296005216
<%=t "activerecord.errors.template.header.other", :model => Order.model_name.human, :count => @account.errors.count %>
otherという表示になる。

下記のURLを参照し、<%= t("errors.template.header", model: User.model_name.human, count: user.errors.count) %>と変更してみると適用できた。新しいバージョンで変更された?
https://qiita.com/yshr04hrk/items/cb7b81c104321f660661
「t("activerecord.models.user")と同じ
User.model_name.human #=> "ユーザ"」

https://github.com/svenfuchs/rails-i18n/issues/118
@kuroda I agree with @jrochkind, dynamic_form gem does not work for me.
Instead, this worked for me:
<%= t('errors.template.header', :model => Model.model_name.human, :count => model.errors.count) %>」

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1