From c4988ed6e1609aa393040a624e131080490f1629 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Jos=C3=A9=20Valim?= Date: Fri, 6 Feb 2009 10:07:00 +0100 Subject: [PATCH] Added support to dashed locales in templates localization. --- actionpack/lib/action_view/template.rb | 2 +- actionpack/test/abstract_unit.rb | 1 + actionpack/test/controller/rescue_test.rb | 1 + .../test/fixtures/test/hello_world.pt-BR.html.erb | 1 + actionpack/test/template/render_test.rb | 9 +++++++++ 5 files changed, 13 insertions(+), 1 deletions(-) create mode 100644 actionpack/test/fixtures/test/hello_world.pt-BR.html.erb diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 553158b..a0ae33c 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -236,7 +236,7 @@ module ActionView #:nodoc: format = nil extension = nil - if m = extensions.match(/^(\w+)?\.?(\w+)?\.?(\w+)?\.?/) + if m = extensions.match(/^([\w-]+)?\.?(\w+)?\.?(\w+)?\.?/) if valid_locale?(m[1]) && m[2] && valid_extension?(m[3]) # All three locale = m[1] format = m[2] diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index c3717a6..07bd7ba 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -34,6 +34,7 @@ ActionController::Base.session_store = nil # Register danish language for testing I18n.backend.store_translations 'da', {} +I18n.backend.store_translations 'pt-BR', {} ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index d7c9499..23e19b1 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -201,6 +201,7 @@ class RescueControllerTest < ActionController::TestCase # Reload and register danish language for testing I18n.reload! I18n.backend.store_translations 'da', {} + I18n.backend.store_translations 'pt-BR', {} # Ensure original are still the same since we are reindexing view paths assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort diff --git a/actionpack/test/fixtures/test/hello_world.pt-BR.html.erb b/actionpack/test/fixtures/test/hello_world.pt-BR.html.erb new file mode 100644 index 0000000..509cc6c --- /dev/null +++ b/actionpack/test/fixtures/test/hello_world.pt-BR.html.erb @@ -0,0 +1 @@ +Ola mundo diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c7405d4..f25658e 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -9,6 +9,7 @@ module RenderTestCases # Reload and register danish language for testing I18n.reload! I18n.backend.store_translations 'da', {} + I18n.backend.store_translations 'pt-BR', {} # Ensure original are still the same since we are reindexing view paths assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort @@ -34,6 +35,14 @@ module RenderTestCases I18n.locale = old_locale end + def test_render_file_with_dashed_locale + old_locale = I18n.locale + I18n.locale = :"pt-BR" + assert_equal "Ola mundo\n", @view.render(:file => "test/hello_world") + ensure + I18n.locale = old_locale + end + def test_render_file_at_top_level assert_equal 'Elastica', @view.render(:file => '/shared') end -- 1.5.4.3