valk
valk

Reputation: 9894

I18n for flash messages with parameters in Rails

How can I add parameters to my parametrized and internationalized error message? Say, in my controller there's:

flash[:error] = t(:error)[:my_error_message] 

And in en.yml:

error:
  my_error_message: "This is the problem XXX already."      

Upvotes: 5

Views: 3898

Answers (2)

Rajesh Kolappakam
Rajesh Kolappakam

Reputation: 2125

For your flash message,

flash[:error] = t('my_error_message', :problem => 'Big Problem')

In your en.yml:

error:
  my_error_message: "This is the problem %{problem} already."      

Upvotes: 9

Oleg Haidul
Oleg Haidul

Reputation: 3732

t('error.my_error_message')

or:

t(:my_error_message, scope: :error)

Upvotes: 0

Related Questions