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

Use custom translations in components #5165

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

javierm
Copy link
Member

@javierm javierm commented Aug 4, 2023

References

Objectives

  • Make sure custom translations are loaded when using the t method in a component

@javierm javierm added the Bug label Aug 4, 2023
@javierm javierm self-assigned this Aug 4, 2023
@javierm javierm added this to Reviewing in Consul Democracy Aug 4, 2023
@javierm javierm added the 2.0.1 label Aug 4, 2023
In the `i18n_translation` initializer, we're overwriting the `t` helper
so calling it uses custom translations if they're available.

However, ViewComponent doesn't use the `t` helper but implements its own
`t` method. So, when calling the `t` method in a component, we weren't
using our implementation of the `t` helper, and so we weren't loading
custom translations.

Using the `t` helper in components solves the issue.

There was a test where we were directly testing a method in a component,
and that method uses the `t` helper. This caused an error when running
the test:

ViewComponent::Base::ViewContextCalledBeforeRenderError:
`#helpers` can't be used during initialization, as it depends on the
view context that only exists once a ViewComponent is passed to the
Rails render pipeline.

Using `render_inline` in the test and testing the generated HTML, as
recommended in the ViewComponent documentation, solves the issue.
@javierm javierm force-pushed the custom_translations_in_components branch from e414538 to dc3a286 Compare August 5, 2023 13:31
Consul Democracy automation moved this from Reviewing to Testing Aug 9, 2023
@javierm javierm merged commit 89d0dc0 into master Aug 9, 2023
13 checks passed
Consul Democracy automation moved this from Testing to Release 2.0.1 Aug 9, 2023
@javierm javierm deleted the custom_translations_in_components branch August 9, 2023 11:34
@javierm javierm restored the custom_translations_in_components branch April 8, 2024 20:02
@javierm javierm deleted the custom_translations_in_components branch April 8, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Information Texts are not rendering in Layouts
2 participants