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

Translating validation message in model raises error #37

Open
leemour opened this issue Dec 12, 2017 · 0 comments
Open

Translating validation message in model raises error #37

leemour opened this issue Dec 12, 2017 · 0 comments

Comments

@leemour
Copy link

leemour commented Dec 12, 2017

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:

validates :permission_sets, length: { minimum: 1, too_short: Spree.t(:atleast_one_permission_set_is_required) }, on: :update

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.

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

1 participant