forked from ruby-i18n/i18n
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible for gems to change the behaviour/signature of I18n. …
…This is useful for other translation engines that do not want to use the key based syntax (tr8n). Also makes it a lot easier to put a cache in front of I18n.
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
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
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,41 @@ | ||
require 'test_helper' | ||
|
||
class I18nOverrideTest < Test::Unit::TestCase | ||
module OverrideInverse | ||
|
||
def translate(*args) | ||
super(*args).reverse | ||
end | ||
alias :t :translate | ||
|
||
end | ||
|
||
module OverrideSignature | ||
|
||
def translate(*args) | ||
args.first | ||
end | ||
alias :t :translate | ||
|
||
end | ||
|
||
def setup | ||
I18n.backend = I18n::Backend::Simple.new | ||
I18n.extend OverrideInverse | ||
super | ||
end | ||
|
||
test "make sure modules can overwrite I18n methods" do | ||
I18n.backend.store_translations('en', :foo => 'bar') | ||
|
||
assert_equal 'rab', I18n.translate(:foo, :locale => 'en') | ||
assert_equal 'rab', I18n.t(:foo, :locale => 'en') | ||
assert_equal 'rab', I18n.translate!(:foo, :locale => 'en') | ||
assert_equal 'rab', I18n.t!(:foo, :locale => 'en') | ||
end | ||
|
||
test "make sure modules can overwrite I18n signature" do | ||
assert I18n.translate("Hello", "Welcome message on home page", :tokenize => true) # tr8n example | ||
end | ||
|
||
end |