ruby-on-railsinternationalizationrails-i18n

Rails I18n, interpolation when we ask to receive a hash object


I have an issue with the interpolation of value in my strings, i ask for the related_links strings and i receive a hash with the title and the url.

this is my .yml

     user:
      subject: "New project created: %{title}"
      related_links:
        - title: Project Created
          url: 'projects/%{id}'

When i ask for I18n.t("user.releated_links", id: xx) I get

{title: "Project Created", url: "projects/%{id}"}

DO any of you know how i can pass my parameters to related_links and it can interpolate the strings in the hash ?


Solution

  • I think you meant to use I18n.t("user.releated_links.url", id: xx).

    You are missing the last key.

    As a side note: Are you sure you want to generate URL from the localization files? Assuming those are links within your application, why don't you better use the rails helpers?