5

Can someone please provide an example on how to use plural forms in a Yaml translation file for Rails i18n API. Basically this is about moving from a gettext based app to Rails.

Plural forms for a18n in Rails is documented here http://guides.rubyonrails.org/i18n.html#pluralization but with limited detail.

Say for example I have this sample from a gettext .po file that uses plural forms:

msgid "found %d fatal error"
msgid_plural "found %d fatal errors"
msgstr[0] "s'ha trobat %d error fatal"
msgstr[1] "s'han trobat %d errors fatals"

How would that look in a .yml file for the Rails i18n API. I understand that Rails i18n uses unique id keys rather than the messages themselves for translation keys - so lets say the key for the above plural messages is found_x_fatal_error.

The other thing is the plural forms selection formula, where does it go in the .yml file and how does it look - say for example we have this selection formula from a gettext .po file header:

Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;

How would it look in the YAML file.

Basel Shishani
  • 7,735
  • 6
  • 50
  • 67
  • I think this thread might help you: http://stackoverflow.com/questions/6166064/i18n-pluralization – Frost Nov 02 '11 at 10:34

1 Answers1

15

You can configure more options:

error_msg:
  zero: none
  one: 1 error
  other: %{count} errors

t('error_msg', :count => 15)
=> 15 errors

Depending on the version of I18n it will be {{count}} or %{count} in the yml file. More explanation can be found here:

http://guides.rubyonrails.org/i18n.html#pluralization

Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
santuxus
  • 3,662
  • 1
  • 29
  • 35