From 24f2e676f700b8a387c6f4c27acf172658cd7863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 6 Feb 2009 23:23:50 -0600 Subject: [PATCH] Added support to dashed locales in templates localization [#1888 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_view/template.rb | 2 +- actionpack/test/abstract_unit.rb | 1 + actionpack/test/controller/rescue_test.rb | 7 ------- actionpack/test/fixtures/test/hello_world.pt-BR.html.erb | 1 + actionpack/test/template/render_test.rb | 9 +++++++++ 5 files changed, 12 insertions(+), 8 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 553158b82a..a0ae33caf0 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -236,7 +236,7 @@ def split(file) 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 c3717a60b8..07bd7ba71d 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -34,6 +34,7 @@ # 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 d7c9499157..5709f37e05 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -198,13 +198,6 @@ def test_rescue_action_in_public_otherwise end def test_rescue_action_in_public_with_localized_error_file - # Reload and register danish language for testing - I18n.reload! - I18n.backend.store_translations 'da', {} - - # Ensure original are still the same since we are reindexing view paths - assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort - # Change locale old_locale = I18n.locale I18n.locale = :da 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 0000000000..773b3c8c6e --- /dev/null +++ b/actionpack/test/fixtures/test/hello_world.pt-BR.html.erb @@ -0,0 +1 @@ +Ola mundo \ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 2caf4e8fe4..5586434cb6 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -10,6 +10,7 @@ def setup_view(paths) # 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 @@ -35,6 +36,14 @@ def test_render_file_with_localization I18n.locale = old_locale end + def test_render_file_with_dashed_locale + old_locale = I18n.locale + I18n.locale = :"pt-BR" + assert_equal "Ola mundo", @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