Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all available locales for template lookups #45169

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions actionview/lib/action_view/template/resolver.rb
Original file line number Diff line number Diff line change
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)
jhawthorn marked this conversation as resolved.
Show resolved Hide resolved
variants = "[^.]*"

%r{
Expand Down
12 changes: 12 additions & 0 deletions actionview/test/template/resolver_shared_tests.rb
Original file line number Diff line number Diff line change
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