Skip to content

Commit 139ef8a

Browse files
authored
Merge pull request rails#44174 from jguecaimburu/add_lowdash_support_to_path_parser_locale_regex
Add support to locales with lowdash in Resolver::PathParser
2 parents 86fd8d0 + bd0753b commit 139ef8a

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

actionpack/test/controller/localized_templates_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ def test_localized_template_has_correct_header_with_no_format_in_template_name
4545
assert_equal "Ciao Mondo", @response.body
4646
assert_equal "text/html", @response.media_type
4747
end
48+
49+
def test_use_locale_with_lowdash
50+
I18n.locale = :"de_AT"
51+
52+
get :hello_world
53+
assert_equal "Guten Morgen", @response.body
54+
end
4855
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Guten Morgen

actionview/lib/action_view/template/resolver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PathParser # :nodoc:
1919
def build_path_regex
2020
handlers = Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|")
2121
formats = Template::Types.symbols.map { |x| Regexp.escape(x) }.join("|")
22-
locales = "[a-z]{2}(?:-[A-Z]{2})?"
22+
locales = "[a-z]{2}(?:[-_][A-Z]{2})?"
2323
variants = "[^.]*"
2424

2525
%r{

actionview/test/template/resolver_shared_tests.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,14 @@ def test_returns_no_results_with_dot
232232

233233
assert_empty context.find_all("hello_world.html", "test", false, [], {})
234234
end
235+
236+
def test_finds_template_with_lowdash_format
237+
with_file "test/hello_world.es_AR.text.erb", "Texto simple!"
238+
239+
es_ar = context.find_all("hello_world", "test", false, [], locale: [:es_AR])
240+
241+
assert_equal 1, es_ar.size
242+
243+
assert_equal "Texto simple!", es_ar[0].source
244+
end
235245
end

0 commit comments

Comments
 (0)