diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 38c662010..218793afe 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 6 ## main +* 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. + + *Oussama Hilal* + * Add Consultport to list of companies using ViewComponent. *Sebastian Nepote* diff --git a/test/sandbox/app/components/relative_translation_partial_block_component.html.erb b/test/sandbox/app/components/relative_translation_partial_block_component.html.erb new file mode 100644 index 000000000..e862ab350 --- /dev/null +++ b/test/sandbox/app/components/relative_translation_partial_block_component.html.erb @@ -0,0 +1,3 @@ +<%= render "shared/partial" do %> + <%= t(".title") %> +<% end %> diff --git a/test/sandbox/app/components/relative_translation_partial_block_component.rb b/test/sandbox/app/components/relative_translation_partial_block_component.rb new file mode 100644 index 000000000..c8a627c0a --- /dev/null +++ b/test/sandbox/app/components/relative_translation_partial_block_component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class RelativeTranslationPartialBlockComponent < ViewComponent::Base +end diff --git a/test/sandbox/app/components/relative_translation_partial_parent_component.html.erb b/test/sandbox/app/components/relative_translation_partial_parent_component.html.erb new file mode 100644 index 000000000..e862ab350 --- /dev/null +++ b/test/sandbox/app/components/relative_translation_partial_parent_component.html.erb @@ -0,0 +1,3 @@ +<%= render "shared/partial" do %> + <%= t(".title") %> +<% end %> diff --git a/test/sandbox/app/components/relative_translation_partial_parent_component.rb b/test/sandbox/app/components/relative_translation_partial_parent_component.rb new file mode 100644 index 000000000..f8caad8a1 --- /dev/null +++ b/test/sandbox/app/components/relative_translation_partial_parent_component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class RelativeTranslationPartialParentComponent < ViewComponent::Base +end diff --git a/test/sandbox/app/views/shared/_partial.html.erb b/test/sandbox/app/views/shared/_partial.html.erb new file mode 100644 index 000000000..37f0bddbd --- /dev/null +++ b/test/sandbox/app/views/shared/_partial.html.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/test/sandbox/config/locales/en.yml b/test/sandbox/config/locales/en.yml index 7a4c5f897..de3fc45d9 100644 --- a/test/sandbox/config/locales/en.yml +++ b/test/sandbox/config/locales/en.yml @@ -24,3 +24,7 @@ en: my_component: message: "OH NO! (you shouldn't see me)" + + shared: + partial: + title: Partial Title diff --git a/test/sandbox/test/components/relative_translation_partial_component_test.rb b/test/sandbox/test/components/relative_translation_partial_component_test.rb new file mode 100644 index 000000000..0054b6b89 --- /dev/null +++ b/test/sandbox/test/components/relative_translation_partial_component_test.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "test_helper" + +class RelativeTranslationPartialBlockComponentTest < ViewComponent::TestCase + def test_relative_translation_in_partial_block + render_inline(RelativeTranslationPartialBlockComponent.new) + + assert_text "Partial Title" + end +end