Handling when the link label is the same as the link
professor opened this issue · comments
In a few cases, I'd like the label and the link to "be the same." Notice that the url (https://example.com
) and the email address ('support@example.com') is in both the ruby and the translation file. In my case these are dynamic values coming from the code.
If you'd like me to suggest a PR for the readme, let me know.
Example 1
It.it "example", link: "https://example.com"
en:
example:
'Go see %{link:https://example.com}.'
Example 2
It.it "example", email_link: "mailto:support@example.com"
en:
example:
'We are here to help. Email %{email_link:support@example.com}.'
The following solution works. I'm not sure if there is something better for Example 2.
Example 1 Solution
CORRECTION: this does not work.
It.it "example", link: "https://example.com"
en:
example:
'Go see %{link:link}.'
This does work:
raw I18n.t "example", link: link_to("https://example.com", "https://example.com")
en:
example:
'Go see %{link}.'
Example 2 Solution
CORRECTION: this does not work.
It.it "example", email_link: "mailto:support@example.com", email_address: 'support@example.com'
en:
example:
'We are here to help. Email %{email_link:email_address}.'
This does work:
I18n.t "example", email_link: mail_to("support@example.com")
en:
example:
'We are here to help. Email %{email_link}.'