Search code examples
ruby-on-railsrails-i18n

How to pass arguments in I18n.translate


I18n.translate can translate error.messages like this:

I18n.translate('error.messages.taken')
-> has already been taken

But there are some error messages that contains arguments like:

I18n.translate('error.messages.greater_than_or_equal_to')
-> must be greater than or equal to %{count}"

Is it possible to pass the argument ‘count’ in the I18n.translate?


Solution

  • You can pass the params after the key

    I18n.translate('error.messages.greater_than_or_equal_to', count: 2)