diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 60dea1993b24d..c4ad350bc4fc9 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -17,9 +17,11 @@ class PathParser # :nodoc: ParsedPath = Struct.new(:path, :details) def build_path_regex - handlers = Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|") - formats = Template::Types.symbols.map { |x| Regexp.escape(x) }.join("|") - locales = "[a-z]{2}(?:[-_][A-Z]{2})?" + handlers = Regexp.union(Template::Handlers.extensions.map(&:to_s)) + formats = Regexp.union(Template::Types.symbols.map(&:to_s)) + available_locales = I18n.available_locales.map(&:to_s) + regular_locales = [/[a-z]{2}(?:[-_][A-Z]{2})?/] + locales = Regexp.union(available_locales + regular_locales) variants = "[^.]*" %r{ diff --git a/actionview/test/template/resolver_shared_tests.rb b/actionview/test/template/resolver_shared_tests.rb index e7f17fbf45737..db9d4b9072244 100644 --- a/actionview/test/template/resolver_shared_tests.rb +++ b/actionview/test/template/resolver_shared_tests.rb @@ -242,4 +242,16 @@ def test_finds_template_with_lowdash_format assert_equal "Texto simple!", es_ar[0].source end + + def test_finds_template_with_arbitrarily_formatted_locale + I18n.backend.store_translations(:en_customer1, { hello: "hello" }) + with_file "test/hello_world.en_customer1.text.erb", "Good day, world." + + templates = context.find_all("hello_world", "test", false, [], locale: [:en_customer1]) + + assert_equal 1, templates.size + assert_equal "Good day, world.", templates[0].source + ensure + I18n.reload! + end end