Skip to content

Commit

Permalink
Merge pull request #9753 from jbarreneche/bug/render-locale-fallbacks
Browse files Browse the repository at this point in the history
i18n locale fallback for localized views
  • Loading branch information
carlosantoniodasilva committed Mar 18, 2013
2 parents 4e7292c + cecbf5d commit eb32b36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions 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.
Expand Down
8 changes: 7 additions & 1 deletion actionpack/lib/action_view/lookup_context.rb
Expand Up @@ -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 }

Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/controller/localized_templates_test.rb
Expand Up @@ -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

0 comments on commit eb32b36

Please sign in to comment.