I am implementing a view count feature for particular web pages in Ruby on Rails. I use haml lists to achieve my end. (The JavaScript library takes the list and render it as dropdowns.)
Here is the code snippet:
%li.action
= link_to t(question.views_count.to_s + ' views')
My problem here is that the V in views is capitalized in the output and view is pluralized even for 0 and 1 number of views. Is there any way I can deal with these issues?
You’re doing it wrong, you should be letting the I18N system (i.e. the
tmethod) 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 thetmethod but it can do a lot more for you.From the I18N Guide:
So assuming you have your message database properly set up, then you would do something like this:
And your English translation file would have something like this: