diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 69a954a807449..4852d703282f3 100644 --- a/actionpack/CHANGELOG +++ b/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] diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index a0a2f96886158..9c1a2bdb9255a 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/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 diff --git a/actionpack/test/controller/localized_templates_test.rb b/actionpack/test/controller/localized_templates_test.rb new file mode 100644 index 0000000000000..41ff2f3809fb1 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/actionpack/test/fixtures/localized/hello_world.de.html b/actionpack/test/fixtures/localized/hello_world.de.html new file mode 100644 index 0000000000000..4727d7a7e08b8 --- /dev/null +++ b/actionpack/test/fixtures/localized/hello_world.de.html @@ -0,0 +1 @@ +Gutten Tag \ No newline at end of file diff --git a/actionpack/test/fixtures/localized/hello_world.en.html b/actionpack/test/fixtures/localized/hello_world.en.html new file mode 100644 index 0000000000000..5e1c309dae7f4 --- /dev/null +++ b/actionpack/test/fixtures/localized/hello_world.en.html @@ -0,0 +1 @@ +Hello World \ No newline at end of file