T
T
TM_ID2014-08-02 22:02:23
Ruby on Rails
TM_ID, 2014-08-02 22:02:23

How to configure pluralization in Rails I18n?

View: Locale:
<%= t('validate_errors.error', count: 1) %>

validate_errors:
    error:
      one: "Форма содержит %{count} ошибку"
      few: "Форма содержит %{count} ошибки"
      many: "Форма содержит %{count} ошибок"
      other: "Форма содержит %{count} ошибок"

Should this work with the standard (boxed) I18n gem?
Now only "one" and "other" works.
Is there really no pluralization for different languages ​​in rails?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
J
Jeiwan, 2014-08-03
@TM_ID

Here is the answer: stackoverflow.com/questions/6166064/i18n-pluralization
You need to set the pluralization rule for the Russian language and everything will work:

2.1.2 :001 > I18n.locale = :ru
 => :ru 
2.1.2 :002 > I18n.t 'validate_errors.error', count: 1
 => "Форма содержит 1 ошибку" 
2.1.2 :003 > I18n.t 'validate_errors.error', count: 2
 => "Форма содержит 2 ошибки" 
2.1.2 :004 > I18n.t 'validate_errors.error', count: 3
 => "Форма содержит 3 ошибки" 
2.1.2 :005 > I18n.t 'validate_errors.error', count: 4
 => "Форма содержит 4 ошибки" 
2.1.2 :006 > I18n.t 'validate_errors.error', count: 5
 => "Форма содержит 5 ошибок" 
2.1.2 :007 > I18n.t 'validate_errors.error', count: 10
 => "Форма содержит 10 ошибок" 
2.1.2 :008 > I18n.t 'validate_errors.error', count: 22
 => "Форма содержит 22 ошибки" 
2.1.2 :009 > I18n.t 'validate_errors.error', count: 21
 => "Форма содержит 21 ошибку"

V
Viktor Vsk, 2014-08-02
@viktorvsk

Can you imagine how few developers there are in the world? And how many of them are involved in the web? And how much - in rubles? And how many - rails? And how many of them are interested in the comprehensive implementation of their projects? And how many of them care about Russian (not to mention "different")?
There is a gem Russian
about plurals, for example, here it is googled first: rubyclub.com.ua/messages/show/18928-%D1%81%D0%BA%D...

K
Kirill Platonov, 2014-08-02
@kirillplatonov

There is native support for pluralization in different languages. guides.rubyonrails.org/i18n.html#pluralization
Try experimenting with the rails version and running the documentation example for yourself.

C
Cthulhu, 2014-11-17
@Cthulhu

Corrected the formula in the original answer: stackoverflow.com/a/26979816/228067

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question