提交 8d5939c0 编写于 作者: J José Valim

Fix a bug where I18n fallbacks modules where not included in the proper...

Fix a bug where I18n fallbacks modules where not included in the proper backend if it was set through config.i18n.backend.
上级 f3abc8ac
......@@ -48,19 +48,20 @@ class Railtie < Rails::Railtie
# 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 @@ def setup
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 @@ def assert_no_fallbacks
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 @@ def assert_no_fallbacks
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册