Skip to content

Relative translation keys inside blocks resolve to partial’s scope instead of caller’s scope #2413

@AckermannTM

Description

@AckermannTM

When using the t helper method inside a block passed to a partial, Rails resolves relative translation keys using the partial's path instead of the caller's path. This results in translations being looked up from the partial’s scope instead of the scope of the file where the block is defined.

Steps to reproduce

# test_component.html.erb
<%= render "shared/partial" do %>
  <%= t(".title") %>
<% end %>

Expected behavior

The translation key should resolve to:
en.test_component.title

Actual behavior

The translation key instead resolves to:
en.shared.partial.title

System configuration

Rails version:
8.0.2
Ruby version:
3.4.4
Gem version:
4.0.0

Note: This works correctly in version 3.23.2 but breaks in 4.0.0.

This is my first bug report. I’m happy to provide more details if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions