From cecbf5dd4d814f0bbd6a7c77a7c550c90a75cf47 Mon Sep 17 00:00:00 2001 From: Juan Barreneche Date: Thu, 14 Mar 2013 18:02:20 -0300 Subject: [PATCH] Include I18n fallbacks in :locale lookup context --- actionpack/CHANGELOG.md | 5 +++++ actionpack/lib/action_view/lookup_context.rb | 8 +++++++- actionpack/test/controller/localized_templates_test.rb | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index b23d0668d37f..69096443fea9 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 4.0.0 (unreleased) ## +* Include I18n locale fallbacks in view lookup. + Fixes GH#3512. + + *Juan Barreneche* + * Integration and functional tests allow headers and rack env variables to be passed when performing requests. Fixes #6513. diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 4e4816d98324..d61cc0f304bb 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -43,7 +43,13 @@ def initialize_details(details) module Accessors #:nodoc: end - register_detail(:locale) { [I18n.locale, I18n.default_locale].uniq } + register_detail(:locale) do + locales = [I18n.locale] + locales.concat(I18n.fallbacks[I18n.locale]) if I18n.respond_to? :fallbacks + locales << I18n.default_locale + locales.uniq! + locales + end register_detail(:formats) { ActionView::Base.default_formats || [:html, :text, :js, :css, :xml, :json] } register_detail(:handlers){ Template::Handlers.extensions } diff --git a/actionpack/test/controller/localized_templates_test.rb b/actionpack/test/controller/localized_templates_test.rb index bac1d0297776..6b02eedaed57 100644 --- a/actionpack/test/controller/localized_templates_test.rb +++ b/actionpack/test/controller/localized_templates_test.rb @@ -25,4 +25,13 @@ def test_default_locale_template_is_used_when_locale_is_missing ensure I18n.locale = old_locale end + + def test_use_fallback_locales + I18n.locale = :"de-AT" + I18n.backend.class.send(:include, I18n::Backend::Fallbacks) + I18n.fallbacks[:"de-AT"] = [:de] + + get :hello_world + assert_equal "Gutten Tag", @response.body + end end