Skip to content

Commit

Permalink
Merge pull request #44174 from jguecaimburu/add_lowdash_support_to_pa…
Browse files Browse the repository at this point in the history
…th_parser_locale_regex

Add support to locales with lowdash in Resolver::PathParser
  • Loading branch information
jhawthorn committed Feb 17, 2022
2 parents 86fd8d0 + bd0753b commit 139ef8a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions actionpack/test/controller/localized_templates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ def test_localized_template_has_correct_header_with_no_format_in_template_name
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
1 change: 1 addition & 0 deletions actionpack/test/fixtures/localized/hello_world.de_AT.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Guten Morgen
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PathParser # :nodoc:
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{
Expand Down
10 changes: 10 additions & 0 deletions actionview/test/template/resolver_shared_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,14 @@ def test_returns_no_results_with_dot

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

0 comments on commit 139ef8a

Please sign in to comment.