🤔
Rails devise-i18n I18n::InvalidPluralizationData
Railsアプリを一人で開発中です。
Deviseでパスワードリセット機能を実装しました。
日本語化対応のジェム(devise-i18n)を追加しました。
パスワードリセット機能の動作確認を行なっていたところ、
このようなエラーが起きました。
I18n::InvalidPluralizationData: translation data {:other=>"ユーザー"} can not be used with :count => 1. key 'one' is missing.
i18n-1.14.5/lib/i18n/backend/base.rb:179:in `pluralize'
Caused by ActionView::MissingTemplate: Missing template devise/passwords/update, devise/update, application/update with {:locale=>[:ja], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder, :slim]}.
i18nを開きました。
bundle open i18n
# To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR
export EDITOR='code'
bundle open i18n
binding.pry
を置いて呼び出し箇所を確認。
def translate(locale, key, options = EMPTY_HASH)
raise I18n::ArgumentError if (key.is_a?(String) || key.is_a?(Symbol)) && key.empty?
raise InvalidLocale.new(locale) unless locale
return nil if key.nil? && !options.key?(:default)
binding.pry
# ....
end
puts caller
# i18n-1.14.5/lib/i18n/backend/base.rb:29:in `translate'
# i18n-1.14.5/lib/i18n.rb:392:in `block in translate_key'
# i18n-1.14.5/lib/i18n.rb:391:in `catch'
# i18n-1.14.5/lib/i18n.rb:391:in `translate_key'
# i18n-1.14.5/lib/i18n.rb:222:in `translate'
# activemodel-7.0.8.3/lib/active_model/naming.rb:209:in `human'
これを見てUser.model_name.human
を実行したら同様のエラーが起きた。
oneが足りないことでエラーが起きているようだ。
ja:
activerecord:
models:
user:
other: ユーザー
このようにすることでエラーが解消した。
ja:
activerecord:
models:
user:
one: ユーザー
other: ユーザー
このPRでも同じことが書いてあった。
最後にジェムへの変更を取り消す。
bundle pristine activemodel
bundle pristine i18n
Discussion