Merge pull request #44174 from jguecaimburu/add_lowdash_support_to_path_parser_locale_regex

Add support to locales with lowdash in Resolver::PathParser
This commit is contained in:
John Hawthorn 2022-02-17 08:27:34 -08:00 committed by GitHub
commit 139ef8a0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1 @@
Guten Morgen

View File

@ -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{

View File

@ -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