You're doing it wrong, you should be letting the I18N system (i.e. the t
method) deal with the pluralization on its own. Proper plural handling is horribly complicated, don't try to do it yourself with string manipulation. You're using the t
method but it can do a lot more for you.
From the I18N Guide:
The
:count
interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined by CLDR:I18n.backend.store_translations :en, :inbox => { :one => '1 message', :other => '%{count} messages' } I18n.translate :inbox, :count => 2 # => '2 messages'
So assuming you have your message database properly set up, then you would do something like this:
t(:views, :count => question.views_count)
And your English translation file would have something like this:
views:
one: "1 view"
other: "%{count} views"