Skip to content

Commit

Permalink
Fix a bug where I18n fallbacks modules where not included in the prop…
Browse files Browse the repository at this point in the history
…er backend if it was set through config.i18n.backend.
  • Loading branch information
josevalim committed May 23, 2010
1 parent f3abc8a commit 8d5939c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions activesupport/lib/active_support/railtie.rb
Expand Up @@ -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

Expand Down
17 changes: 10 additions & 7 deletions railties/test/railties/i18n_railtie_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -42,14 +36,23 @@ 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

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

Expand Down

0 comments on commit 8d5939c

Please sign in to comment.