Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update string as plural once it is more than 1

I have the following span, I want to use the method pluralize, till there is items equal to 1, I want to display 1 item, at the moment it is by default 0 items, If something gets added it says 1 items

<span id="cartitems">
<%=@size%>
items
</span>
like image 225
Suraj Avatar asked Dec 06 '22 21:12

Suraj


1 Answers

Please use Rails I18n and write something like:

I18n.t('items', count: @size)

and then in your config/locales/en.yml file:

en:
  items:
    zero: "no items"
    one: "one item"
    other: "%{count} items"
like image 88
coorasse Avatar answered Dec 15 '22 00:12

coorasse