Is there a way to do something like this:
en:
welcome:
hello there, #{current_user.first_name}! It's nice to see you again.
That obviously won't work, and apparently "#{" is invalid characters in yaml, because that string shows up as just "hello there, " when I pull it out.
The best I could do was something like:
en:
welcome:
hello there, (name)! It's nice to see you again.
....
t(:welcome).gsub("(name)", current_user.first_name)
But I am not crazy about that... There must be a better way to do this sort of thing.
Replace your en.yml like this
en:
welcome:
"hello there, %{name}! It's nice to see you again."
and your view like this
<%=t(:welcome, :name=> current_user.first_name) %>
Basically it is passed as a named argument. You can find more at Rails Guides 18n Interpolation
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