ruby-i18n/i18n

[BUG] config.i18n.fallbacks not respected on Rails 7

yheuhtozr opened this issue · 3 comments

What I tried to do

class Application < Rails::Application
  config.load_defaults 7.0
  config.i18n.fallbacks = { "en-AU": %i[en-GB en-US en] }
end

What I expected to happen

$ rails c
Loading development environment (Rails 7.0.4)          
irb(main):001:0> I18n.fallbacks
=> {:"en-AU"=>[:"en-GB", :"en-US", :en]}

What actually happened

$ rails c
Loading development environment (Rails 7.0.4)          
irb(main):001:0> I18n.fallbacks
=> {:en=>[:en]}

Versions of i18n, rails, and anything else you think is necessary

  • Ruby: 3.0.2
  • Rails: 7.0.4
  • i18n: 1.12.0
  • OS: Ubuntu 21.04 (WSL2)

Workaround

def map(*args, &block)
if args.count == 1 && !block_given?
mappings = args.first
mappings.each do |from, to|
from, to = from.to_sym, Array(to)
to.each do |_to|
@map[from] ||= []
@map[from] << _to.to_sym
end
end
else
@map.map(*args, &block)
end
end

It seems to work as expected1 if you add one line between the line 76-77 as follows:

        if args.count == 1 && !block_given?
          mappings = args.first
          mappings.each do |from, to|
            from, to = from.to_sym, Array(to)
            to.each do |_to|
              @map[from] ||= []
              @map[from] << _to.to_sym
            end
          end
          self.replace(@map) # <- insert this!
        else
          @map.map(*args, &block)
        end

Footnotes

  1. not exactly, it'll be like {:"en-AU"=>[:"en-GB", :"en-US", :en], :en=>[:en]}

radar commented

Notably, this happens in Rails 6.1 and Rails 6.0 as well.

I got the same issue, do you know how to solve it?

It only happened with Rails 7