Skip to content

Commit 9095351

Browse files
authored
Merge pull request #2432 from AckermannTM/relative-translation-keys-inside-blocks-resolve-to-partials-scope-instead-of-callers-scope
Relative translation keys inside blocks resolve to partials scope instead of callers scope
2 parents ecc66e8 + 1a6992d commit 9095351

8 files changed

+34
-0
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 6
1010

1111
## main
1212

13+
* Add test to document the current behavior for resolving relative translation keys within partial blocks. When rendering a partial, relative translation keys are resolved relative to the partial's own path rather than the caller’s path. This test ensures that this behavior remains consistent.
14+
15+
*Oussama Hilal*
16+
1317
* Allow I18n calls in `render?`.
1418

1519
*23tux*
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%= render "shared/partial" do %>
2+
<%= t(".title") %>
3+
<% end %>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
class RelativeTranslationPartialBlockComponent < ViewComponent::Base
4+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%= render "shared/partial" do %>
2+
<%= t(".title") %>
3+
<% end %>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
class RelativeTranslationPartialParentComponent < ViewComponent::Base
4+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= yield %>

test/sandbox/config/locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ en:
2525
my_component:
2626
message: "OH NO! (you shouldn't see me)"
2727

28+
shared:
29+
partial:
30+
title: Partial Title
31+
2832
rendering_test:
2933
i18n_test_component:
3034
message: "I can be called in render?"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class RelativeTranslationPartialBlockComponentTest < ViewComponent::TestCase
6+
def test_relative_translation_in_partial_block
7+
render_inline(RelativeTranslationPartialBlockComponent.new)
8+
9+
assert_text "Partial Title"
10+
end
11+
end

0 commit comments

Comments
 (0)