diff --git a/actionpack/test/controller/localized_templates_test.rb b/actionpack/test/controller/localized_templates_test.rb index 5c5cef66d56..d4cd82368e5 100644 --- a/actionpack/test/controller/localized_templates_test.rb +++ b/actionpack/test/controller/localized_templates_test.rb @@ -45,4 +45,11 @@ class LocalizedTemplatesTest < ActionController::TestCase assert_equal "Ciao Mondo", @response.body assert_equal "text/html", @response.media_type end + + def test_use_locale_with_lowdash + I18n.locale = :"de_AT" + + get :hello_world + assert_equal "Guten Morgen", @response.body + end end diff --git a/actionpack/test/fixtures/localized/hello_world.de_AT.html b/actionpack/test/fixtures/localized/hello_world.de_AT.html new file mode 100644 index 00000000000..3b6e1802611 --- /dev/null +++ b/actionpack/test/fixtures/localized/hello_world.de_AT.html @@ -0,0 +1 @@ +Guten Morgen \ No newline at end of file diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index b86a365a6b4..60dea1993b2 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -19,7 +19,7 @@ module ActionView 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})?" + locales = "[a-z]{2}(?:[-_][A-Z]{2})?" variants = "[^.]*" %r{ diff --git a/actionview/test/template/resolver_shared_tests.rb b/actionview/test/template/resolver_shared_tests.rb index 37452defd27..e7f17fbf457 100644 --- a/actionview/test/template/resolver_shared_tests.rb +++ b/actionview/test/template/resolver_shared_tests.rb @@ -232,4 +232,14 @@ module ResolverSharedTests assert_empty context.find_all("hello_world.html", "test", false, [], {}) end + + def test_finds_template_with_lowdash_format + with_file "test/hello_world.es_AR.text.erb", "Texto simple!" + + es_ar = context.find_all("hello_world", "test", false, [], locale: [:es_AR]) + + assert_equal 1, es_ar.size + + assert_equal "Texto simple!", es_ar[0].source + end end