Permalink
Browse files

Fixed that default locale templates should be used if the current loc…

…ale template is missing [DHH]
  • Loading branch information...
1 parent cfb31ed commit 0653a6d30e1a2746c6fbab768a989e2b3750cb32 @dhh dhh committed Apr 9, 2010
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*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 much of DateHelper wouldn't return html_safe? strings [DHH]
View
8 actionpack/lib/action_view/paths.rb
@@ -47,15 +47,23 @@ def find_template(original_template_path, format = nil, html_fallback = true)
each do |load_path|
if format && (template = load_path["#{template_path}.#{I18n.locale}.#{format}"])
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}"])
return template
elsif template = load_path["#{template_path}.#{I18n.locale}"]
return template
+ elsif template = load_path["#{template_path}.#{I18n.default_locale}"]
+ return template
elsif template = load_path[template_path]
return template
# Try to find html version if the format is javascript
elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"]
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"]
return template
end
View
22 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
View
1 actionpack/test/fixtures/localized/hello_world.de.html
@@ -0,0 +1 @@
+Gutten Tag
View
1 actionpack/test/fixtures/localized/hello_world.en.html
@@ -0,0 +1 @@
+Hello World

0 comments on commit 0653a6d

Please sign in to comment.