Skip to content

Conversation

AckermannTM
Copy link

What are you trying to accomplish?

Relative translations in a block use the path of the block, instead of the caller. See #2413

What approach did you choose and why?

Created an issue to describe the problem and was asked to create a failing test PR.
It took me some time to put the PR together 😅

Anything you want to highlight for special attention from reviewers?

I just hope I did everything correctly

@myabc
Copy link
Contributor

myabc commented Sep 1, 2025

Hi @AckermannTM thanks for creating the bug reproduction! If I try running your test and inserting a binding.irb within the render block, I see that calling t/translate calls the ActionView implementation. Outside of the render block, it calls the ViewComponent implementation. This is actually what I would I would expect to see.

bundle exec appraisal rails-8.0 rake test TEST=test/sandbox/test/components/relative_translation_partial_component_test.rb

<%= render "shared/partial" do %>
  <%= t(".title") %>
  <% binding.irb %>
<% end %>
> method(:translate).source_location
=> ["/Users/alexbcoles/.gem/ruby/3.4.5/gems/actionview-8.0.2/lib/action_view/helpers/translation_helper.rb", 73]

vs

<%= render "shared/partial" do %>
  <%= t(".title") %>
<% end %>
<% binding.irb %>
> method(:translate).source_location
=> ["/Users/alexbcoles/git-repos/view_component/lib/view_component/translatable.rb", 93]

@AckermannTM
Copy link
Author

Hey @myabc, thanks for looking into this! That explanation makes sense. Inside a render block it is ActionView handling translations, and outside it falls back to the ViewComponent implementation. So this is not a ViewComponent issue but the expected ActionView behavior when rendering a partial inside a component.

I thought it might be a ViewComponent issue since it worked in version 3.23.2, but now it is clear that this is expected behavior.

Looks like it’s time to replace all partials with components in my project 😄

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

Successfully merging this pull request may close these issues.

2 participants