0
0

More than 3 years have passed since last update.

【エラー備忘録】translation data {:title=>"タイトル", :◯◯=>"△△"} can not be used with :count => 1. key 'other' is missing.

Last updated at Posted at 2020-04-15

エラーの内容

image.png (39.6 kB)

I18n::InvalidPluralizationData in ReviewsController#create
translation data {:title=>"タイトル", :body=>"本文"} can not be used with :count => 1. key 'other' is missing.

と表示される。

やりたかったこと

rails-i18nを用いて、reviewモデル内の下記の属性を日本語表示させようとした。

  • title
  • body

手順

  1. gem "rails-i18n"bundle install
  2. application.rbにconfig.i18n.default_locale = :jaを設定
  3. ja.yamlを作成

原因

ja.yamlの記述に問題があった。

誤った書き方

ja.yaml
ja:
  activerecord:
    models:
      review:
        title: タイトル
        body: 本文

models:の次の項目のmodel名reviewに続けて属性名を記述していた。

正しい書き方

ja.yaml
ja:
  activerecord:
    models:
      review:
    attributes:
      review:
        title: タイトル
        body: 本文

リロードを行うと、正しく日本語で表示された。(バリデーションを日本語で表示できた)

image.png (33.0 kB)

参考

[初学者]Railsのi18nによる日本語化対応

0
0
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
0
0