mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fix a bug where I18n fallbacks modules where not included in the proper backend if it was set through config.i18n.backend.
This commit is contained in:
@@ -48,19 +48,20 @@ module I18n
|
||||
# Set the i18n configuration from config.i18n but special-case for
|
||||
# the load_path which should be appended to what's already set instead of overwritten.
|
||||
config.after_initialize do |app|
|
||||
fallbacks = app.config.i18n.delete(:fallbacks)
|
||||
|
||||
app.config.i18n.each do |setting, value|
|
||||
case setting
|
||||
when :railties_load_path
|
||||
app.config.i18n.load_path.unshift(*value)
|
||||
when :load_path
|
||||
I18n.load_path += value
|
||||
when :fallbacks
|
||||
init_fallbacks(value) if value && validate_fallbacks(value)
|
||||
else
|
||||
I18n.send("#{setting}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks)
|
||||
I18n.reload!
|
||||
end
|
||||
|
||||
|
||||
@@ -9,12 +9,6 @@ module RailtiesTest
|
||||
boot_rails
|
||||
FileUtils.rm_rf("#{app_path}/config/environments")
|
||||
require "rails/all"
|
||||
@old_path = I18n.load_path
|
||||
end
|
||||
|
||||
def teardown
|
||||
I18n.load_path = @old_path || []
|
||||
I18n.backend = nil
|
||||
end
|
||||
|
||||
def load_app
|
||||
@@ -42,7 +36,7 @@ module RailtiesTest
|
||||
end
|
||||
|
||||
test "not using config.i18n.fallbacks does not initialize I18n.fallbacks" do
|
||||
I18n.backend = Class.new { include I18n::Backend::Base }.new # can't uninclude modules, so use a tmp backend class
|
||||
I18n.backend = Class.new { include I18n::Backend::Base }.new
|
||||
load_app
|
||||
assert_no_fallbacks
|
||||
end
|
||||
@@ -50,6 +44,15 @@ module RailtiesTest
|
||||
test "config.i18n.fallbacks = true initializes I18n.fallbacks with default settings" do
|
||||
I18n::Railtie.config.i18n.fallbacks = true
|
||||
load_app
|
||||
assert I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks)
|
||||
assert_fallbacks :de => [:de, :en]
|
||||
end
|
||||
|
||||
test "config.i18n.fallbacks = true initializes I18n.fallbacks with default settings even when backend changes" do
|
||||
I18n::Railtie.config.i18n.fallbacks = true
|
||||
I18n::Railtie.config.i18n.backend = Class.new { include I18n::Backend::Base }.new
|
||||
load_app
|
||||
assert I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks)
|
||||
assert_fallbacks :de => [:de, :en]
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user