Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `map' for "translation missing: en-US.i18n.plural.keys":String #106

Closed
JeremiahChurch opened this issue May 21, 2020 · 4 comments

Comments

@JeremiahChurch
Copy link

fairly standard rails 6 app.

stock standard i18n_active_record.rb initializer with the only addition being Missing

require 'i18n/backend/active_record'

Translation = I18n::Backend::ActiveRecord::Translation

if Translation.table_exists?
  I18n.backend = I18n::Backend::ActiveRecord.new

  I18n::Backend::ActiveRecord.include I18n::Backend::Memoize
  I18n::Backend::Simple.include I18n::Backend::Memoize
  I18n::Backend::Simple.include I18n::Backend::Pluralization

  I18n::Backend::Chain.send(:include, I18n::Backend::ActiveRecord::Missing)

  I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
end

I get the exception on line 45 of active_record/missing.rb

keys = count ? I18n.t('i18n.plural.keys', :locale => locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key]

count is 1

a one line change to the failing line of count && count > 1 fixes my issue. I'm happy to do a PR for that but wanted to see if others are having a similar issue or if I have a config problem somewhere.

@timfjord
Copy link
Collaborator

timfjord commented May 22, 2020

@JeremiahChurch in order to use this extension you need to add something like this

en:
  i18n:
    plural:
      keys: [:zero, :one, :other]

see https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record/missing.rb#L16-L28
this way t calls with count parameter will be correctly persisted.

It doesn't really matter what is the value of count we only care about its presence.

@JeremiahChurch
Copy link
Author

JeremiahChurch commented May 22, 2020

@timfjord Thank you so much for setting me straight!

I received psych errors trying to use the array of keys the example way but reformatting it to the other format has everything working.

en:
  i18n:
    plural:
      keys:
        - :zero
        - :one
        - :other

Might I suggest a small doc tweak to that file to make it clear that keys is required for the Missing module to work correctly?

@timfjord
Copy link
Collaborator

Sure, feel free to open a PR with the tweak.

@westonganger westonganger mentioned this issue Oct 19, 2021
@timfjord timfjord mentioned this issue Oct 25, 2021
3 tasks
@timfjord
Copy link
Collaborator

This is now mentioned in the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants