Skip to content

Commit

Permalink
Fixed that default locale templates should be used if the current loc…
Browse files Browse the repository at this point in the history
…ale template is missing [DHH]
  • Loading branch information
dhh committed Apr 9, 2010
1 parent cfb31ed commit 0653a6d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Edge* *Edge*


* Fixed that default locale templates should be used if the current locale template is missing [DHH]

* Fixed that PrototypeHelper#update_page should return html_safe [DHH] * Fixed that PrototypeHelper#update_page should return html_safe [DHH]


* Fixed that much of DateHelper wouldn't return html_safe? strings [DHH] * Fixed that much of DateHelper wouldn't return html_safe? strings [DHH]
Expand Down
8 changes: 8 additions & 0 deletions actionpack/lib/action_view/paths.rb
Expand Up @@ -47,15 +47,23 @@ def find_template(original_template_path, format = nil, html_fallback = true)
each do |load_path| each do |load_path|
if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"]) if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"])
return template return template
# Try the default locale version if the current locale doesn't have one
# (i.e. you haven't translated this view to German yet, but you have the English version on hand)
elsif format && (template = load_path["#{template_path}.#{I18n.default_locale}.#{format}"])
return template
elsif format && (template = load_path["#{template_path}.#{format}"]) elsif format && (template = load_path["#{template_path}.#{format}"])
return template return template
elsif template = load_path["#{template_path}.#{I18n.locale}"] elsif template = load_path["#{template_path}.#{I18n.locale}"]
return template return template
elsif template = load_path["#{template_path}.#{I18n.default_locale}"]
return template
elsif template = load_path[template_path] elsif template = load_path[template_path]
return template return template
# Try to find html version if the format is javascript # Try to find html version if the format is javascript
elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"] elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
return template return template
elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.default_locale}.html"]
return template
elsif format == :js && html_fallback && template = load_path["#{template_path}.html"] elsif format == :js && html_fallback && template = load_path["#{template_path}.html"]
return template return template
end end
Expand Down
22 changes: 22 additions & 0 deletions actionpack/test/controller/localized_templates_test.rb
@@ -0,0 +1,22 @@
require 'abstract_unit'

class LocalizedController < ActionController::Base
def hello_world
end
end

class LocalizedTemplatesTest < ActionController::TestCase
tests LocalizedController

def test_localized_template_is_used
I18n.locale = :de
get :hello_world
assert_equal "Gutten Tag", @response.body
end

def test_default_locale_template_is_used_when_locale_is_missing
I18n.locale = :dk
get :hello_world
assert_equal "Hello World", @response.body
end
end
1 change: 1 addition & 0 deletions actionpack/test/fixtures/localized/hello_world.de.html
@@ -0,0 +1 @@
Gutten Tag
1 change: 1 addition & 0 deletions actionpack/test/fixtures/localized/hello_world.en.html
@@ -0,0 +1 @@
Hello World

0 comments on commit 0653a6d

Please sign in to comment.