vinsol-spree-contrib / spree_admin_roles_and_access

Admin Roles And Access for Spree
BSD 3-Clause "New" or "Revised" License
43 stars 101 forks source link

Translating validation message in model raises error #37

Open leemour opened 6 years ago

leemour commented 6 years ago

I have config.action_view.raise_on_missing_translations = true Whenever I load rails server/console after this gem is installed, I get this error translation missing: ru.spree.atleast_one_permission_set_is_required (I18n::MissingTranslationData) Stacktrace:

/home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/i18n-0.9.1/lib/i18n.rb:319:in `handle_exception': translation missing: ru.spree.atleast_one_permission_set_is_required (I18n::MissingTranslationData)
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/i18n-0.9.1/lib/i18n.rb:169:in `translate'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/actionview-5.1.4/lib/action_view/helpers/translation_helper.rb:90:in `translate'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/spree_core-3.4.1/lib/spree/i18n.rb:18:in `translate'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/bundler/gems/spree_admin_roles_and_access-600d8d90fee1/app/models/spree/role_decorator.rb:11:in `block in <main>'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/bundler/gems/spree_admin_roles_and_access-600d8d90fee1/app/models/spree/role_decorator.rb:1:in `class_eval'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/bundler/gems/spree_admin_roles_and_access-600d8d90fee1/app/models/spree/role_decorator.rb:1:in `<main>'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `load'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bootsnap-1.1.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `load'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `block in load'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
    from /home/leemour/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load'

The problem is here: https://github.com/vinsol-spree-contrib/spree_admin_roles_and_access/blob/1464808e48e1da6ed24c45672ad0a8c89654a658/app/models/spree/role_decorator.rb#L11 I have this translated in my .yml file so shouldn't cause any errors. If I set config.action_view.raise_on_missing_translations = false (the default) I don't get an error. I got it fixed by replacing Spree.t(:atleast_one_permission_set_is_required) with I18n.t('spree.atleast_one_permission_set_is_required') So I guess the problem is with Spree not loading translations in models. Anyway, this change makes this gem work.