How to pass arguments in I18n.translate

Leo picture Leo · Sep 7, 2016 · Viewed 13.1k times · Source

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?

Answer

Deepak Mahakale picture Deepak Mahakale · Sep 7, 2016

You can pass the params after the key

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