Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sven Fuchs
committed
Jun 19, 2008
1 parent
2fe4d35
commit b09c6e7
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module ActionView | ||
module Helpers | ||
module I18nHelper | ||
def translate(*args) | ||
# inserts the locale or current request locale to the argument list if no locale | ||
# has been passed or the locale has been passed as part of the options hash | ||
options = args.extract_options! | ||
if args.size != 2 | ||
locale = options.delete :locale | ||
locale ||= request.locale if respond_to? :request | ||
args << locale if locale | ||
end | ||
args << options unless options.empty? | ||
I18n.translate *args | ||
end | ||
alias :t :translate | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'abstract_unit' | ||
require 'action_view/helpers/i18n_helper' | ||
|
||
class I18nHelperTests < Test::Unit::TestCase | ||
include ActionView::Helpers::I18nHelper | ||
|
||
attr_reader :request | ||
def setup | ||
@request = stub :locale => 'en-US' | ||
I18n.stubs(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' | ||
end | ||
|
||
def test_translate_given_a_locale_argument_it_does_not_check_request_for_locale | ||
request.expects(:locale).never | ||
assert_equal 'Foo Bar', translate(:'foo.bar', :locale => 'en-US') | ||
end | ||
|
||
def test_translate_given_a_locale_option_it_does_not_check_request_for_locale | ||
request.expects(:locale).never | ||
I18n.expects(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' | ||
assert_equal 'Foo Bar', translate(:'foo.bar', :locale => 'en-US') | ||
end | ||
|
||
def test_translate_given_no_locale_it_checks_request_for_locale | ||
request.expects(:locale).returns 'en-US' | ||
assert_equal 'Foo Bar', translate(:'foo.bar') | ||
end | ||
|
||
def test_translate_delegates_to_i18n_translate | ||
I18n.expects(:translate).with(:'foo.bar', 'en-US').returns 'Foo Bar' | ||
assert_equal 'Foo Bar', translate(:'foo.bar') | ||
end | ||
end |