You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing translations there are times when you may want to inline some HTML, such as for bolding some text or placing a link in the middle of a sentence, currently, you can achieve this by doing something along the lines of:
{!!__('Something <b>bold</b>, and a <a href=":href">link</a>', ['href'=>'https://laravel.com']) !!}
But this isn't very nice or readable to a translator, FormatJS already has a solution to this with Tag Replacements, these look like normal HTML tags but they don't support attributes, they can be added with callables:
{!!__('Something <b>bold</b> and a <link>link</link>', ['link'=>fn ($children) =>"<a href="https://laravel.com">$children</a>" ]) !!}
The above uses a shorthand callable and removes the complexity away from the translator (as in the person, not the class), this also means that if you want to modify that anchor tag with a class then you don't have to go through each translation to add it.
However, this still requires the use of an unescaped tag in the blade which allows the use of <b> without it being explicitly defined, it would be nicer if the tag replacements were output as a HTMLString that can be inlined with normal escape braces while still escaping the raw string, though this isn't much of a concern as you should be validating your translations before deploying them it is more of a developer nicety.
I've been doing this in my apps by overriding the makeReplacements method in the Translator with the following (this is basic and still needs the unescaped blade syntax):
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When writing translations there are times when you may want to inline some HTML, such as for bolding some text or placing a link in the middle of a sentence, currently, you can achieve this by doing something along the lines of:
But this isn't very nice or readable to a translator, FormatJS already has a solution to this with Tag Replacements, these look like normal HTML tags but they don't support attributes, they can be added with callables:
The above uses a shorthand callable and removes the complexity away from the translator (as in the person, not the class), this also means that if you want to modify that anchor tag with a class then you don't have to go through each translation to add it.
However, this still requires the use of an unescaped tag in the blade which allows the use of
<b>
without it being explicitly defined, it would be nicer if the tag replacements were output as aHTMLString
that can be inlined with normal escape braces while still escaping the raw string, though this isn't much of a concern as you should be validating your translations before deploying them it is more of a developer nicety.I've been doing this in my apps by overriding the
makeReplacements
method in theTranslator
with the following (this is basic and still needs the unescaped blade syntax):I'm happy to create a pull request if this feature is something people would like.
Beta Was this translation helpful? Give feedback.
All reactions