Skip to content

Commit

Permalink
Added support to dashed locales in templates localization [rails#1888
Browse files Browse the repository at this point in the history
…state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
josevalim authored and josh committed Feb 7, 2009
1 parent 43c0938 commit 24f2e67
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template.rb
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/abstract_unit.rb
Expand Up @@ -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')
Expand Down
7 changes: 0 additions & 7 deletions actionpack/test/controller/rescue_test.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/fixtures/test/hello_world.pt-BR.html.erb
@@ -0,0 +1 @@
Ola mundo
9 changes: 9 additions & 0 deletions actionpack/test/template/render_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 24f2e67

Please sign in to comment.