I'm trying to translate https://github.com/lifo/docrails/blob/master/activerecord/lib/active_record/associations.rb
In my controller file I have:
@book = Book.find(params[:id])
begin
@book.destroy
rescue ActiveRecord::DeleteRestrictionError => e
flash[:error]= e.message # <<< Translate this message ?
end
This is the translation file I use : https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/th.rb
How do I write code for translate "#{e.message}"
?
You can use this in your en.yml
file
activerecord:
book:
error: 'book error: %{e}'
and u can chane ur rescue block with this
flash[:error] = t("book.error") % {:e => e.message}
this works in ma case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With