How to pass arguments to I18n.translate

I18n.translate can translate error.messages as follows:

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

But there are error messages containing arguments such as:

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 to I18n.translate?

+4
source share
2 answers

You can pass parameters after the key

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

This will allow you to add as many arguments as you want.

I18n.translate('error.messages.greater_than_or_equal_to {arg1}').replace('{arg1}', count)
0
source

Source: https://habr.com/ru/post/1653907/


All Articles