I have the following text in my en.yml
update_message: "The user updated device's name to <b>%{name}</b>"
and I have the following json object
{ "user": { "id": 1, "name: "Wagner Junior" } }
The service dynamically resolve the interpolation in the same way as always:
t('update_message', json_object)
but it didn't work.
I want to replace the %{name} in the update_message with the name attribute in my json object, kinda user/name, user.name, user>name, etc. I can't use json_object['name'] because I will have other messages that will receive the json object.
I've tried to use different ways to do this interpolation no success.
Rails is expecting a flat hash for the interpolation values, not a nested one, so you can try this:
t('update_message', name: json_object["user"]["name"])If you have multiple and possibly unknown depth levels, you might want to flatten your hash to receive something like
{"user_id" => 1, "user_name" => "Wagner Junior"}you can work with.Regarding
you didn't specify what these other JSON objects are, how they look like, and how they relate to the other messages. Here's a general idea: