Merge pull request #45169 from oneiros/allow_all_available_locales_for_template_lookup

Allow all available locales for template lookups
This commit is contained in:
John Hawthorn 2022-05-30 11:49:40 -07:00 committed by GitHub
commit a5b2b6155c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

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

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