Permalink
Browse files

Handle pluralization (Fixes #2)

  • Loading branch information...
1 parent 932d364 commit 4ff148ad38e9232990f9e0d24e8897b4f2c09b93 @iGEL committed Dec 14, 2011
Showing with 22 additions and 1 deletion.
  1. +3 −0 lib/it.rb
  2. +1 −1 lib/it/helper.rb
  3. +18 −0 spec/it/helper_spec.rb
View
@@ -43,6 +43,9 @@ def self.tag(tag_name, options = {})
private
def self.process(string, options)
+ # Handle pluralization
+ string = I18n.backend.send(:pluralize, options["locale"] || I18n.locale, string, options["count"]) if string.is_a?(Hash) && options["count"]
+
# We want the escaped String, not an ActiveSupport::SafeBuffer
translation = String.new(ERB::Util.h(string))
View
@@ -40,7 +40,7 @@ module Helper
#
def it(identifier, options = {})
options.stringify_keys!
- It.process(t(identifier, :locale => options.delete("locale")), options)
+ It.process(t(identifier, :locale => options["locale"]), options)
end
end
end
@@ -115,4 +115,22 @@
it 'should support the locale option' do
@view.it('test1', :locale => "de", :link => It.link("http://www.rubyonrails.org")).should == 'Ich enthalte einen <a href="http://www.rubyonrails.org">Link zu Rails</a> in der Mitte.'
end
+
+ context "With a pluralized translation" do
+ before do
+ I18n.backend.store_translations(:en, :test10 => {:zero => "You have zero messages.", :one => "You have %{link:one message}.", :other => "You have %{link:%{count} messages}."})
+ end
+
+ it 'should work with count = 0' do
+ @view.it("test10", :count => 0, :link => "/messages").should == 'You have zero messages.'
+ end
+
+ it 'should work with count = 1' do
+ @view.it("test10", :count => 1, :link => "/messages").should == 'You have <a href="/messages">one message</a>.'
+ end
+
+ it 'should work with count > 1' do
+ @view.it("test10", :count => 2, :link => "/messages").should == 'You have <a href="/messages">2 messages</a>.'
+ end
+ end
end

0 comments on commit 4ff148a

Please sign in to comment.