Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Include I18n fallbacks in :locale lookup context

  • Loading branch information...
commit cecbf5dd4d814f0bbd6a7c77a7c550c90a75cf47 1 parent feaa6e2
@jbarreneche jbarreneche authored
View
5 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.
View
8 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 }
View
9 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
Please sign in to comment.
Something went wrong with that request. Please try again.