-
Notifications
You must be signed in to change notification settings - Fork 409
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
Relative translations don't work in initializer #1577
Comments
This is expected, although I agree would be great to have them working in the initializer as well. The reason it works as an instance method is that the method is most likely called after initialization and compilation of the component. Happy to review any proposal to make it work from the get go tho 🙌 |
I suppose some warning in the documentation would be nice. I'm not at all clear why this timing concern exists. Maybe an explanation about that? |
@jcoyne perhaps we could just add a warning for now? Like this test case:
|
@joelhawksley that would be really helpful |
@jcoyne cool. Would you be up for writing a PR? I can help clean up language if you get something started ❤️ |
No, because I don't understand the order problem were seeing. I don't understand what the compile step is or what that does. |
In order for translations to work in an initializer, ActionView requires @virtual_path to be set. To set it, we allocate the component, set @virtual_path, then call the component's initializer. This is either terrible, brilliant, or both. Closes #1577
This is similar to #74
If I have an initializer and I use the translation helper, then I get the error:
This happens even after calling
super
If I move the translation into an instance method, it works as expected.
Using view_component-2.75.0, rails-7.0.4, ruby 3.1.0
The text was updated successfully, but these errors were encountered: