palkan / view_component-contrib

A collection of extension and developer tools for ViewComponent
MIT License
369 stars 22 forks source link

Breaking sidecar translations. #29

Closed andrzejsliwa closed 1 year ago

andrzejsliwa commented 1 year ago

What did you do?

I just added sidecar translations, because for my use case they are perfect.

What did you expect to happen?

to run without errors

What actually happened?

NoMethodError: undefined method `to_sym' for ["example"]:Array

view_component (2.80.0) lib/view_component/translatable.rb:44:in `map' view_component (2.80.0) lib/view_component/translatable.rb:44:in `initialize' view_component (2.80.0) lib/view_component/translatable.rb:32:in `new' view_component (2.80.0) lib/view_component/translatable.rb:32:in `build_i18n_backend' view_component (2.80.0) lib/view_component/compiler.rb:79:in `compile' view_component (2.80.0) lib/view_component/base.rb:518:in `compile' view_component (2.80.0) lib/view_component/base.rb:95:in `render_in' view_component (2.80.0) lib/view_component/instrumentation.rb:19:in `block in render_in' activesupport (7.0.4) lib/active_support/notifications.rb:206:in `block in instrument' activesupport (7.0.4) lib/active_support/notifications/instrumenter.rb:24:in `instrument' activesupport (7.0.4) lib/active_support/notifications.rb:206:in `instrument' view_component (2.80.0) lib/view_component/instrumentation.rb:12:in `render_in' actionview (7.0.4) lib/action_view/helpers/rendering_helper.rb:42:in `render'

Additional context

it's happening because by default, your base class in including TranslationHelper, which is messing with @i18n_scope

My workaround is to stop using you base class and manually just include WrappedHelper to ApplicationViewComponent, once switching to ViewComponent::Base from ViewComponentContrib::Base.

I would suggest to make it optional, as its breaking build in functionality of sidecar translations.

Environment

Ruby Version:

3.2

Framework Version (Rails, whatever):

7.0.4

View Component Contrib Version:

0.1.1

palkan commented 1 year ago

Thanks for reporting!

Looking at it.

palkan commented 1 year ago

Fixed and released in 0.1.2.