Skip to content

Commit

Permalink
Merge pull request #45169 from oneiros/allow_all_available_locales_fo…
Browse files Browse the repository at this point in the history
…r_template_lookup

Allow all available locales for template lookups
  • Loading branch information
jhawthorn committed May 30, 2022
2 parents 3afc136 + 12c1289 commit a5b2b61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions actionview/lib/action_view/template/resolver.rb
Expand Up @@ -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{
Expand Down
12 changes: 12 additions & 0 deletions actionview/test/template/resolver_shared_tests.rb
Expand Up @@ -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

0 comments on commit a5b2b61

Please sign in to comment.