jared zek
jared zek

Reputation: 99

HTML tags in translation Laravel

I'm trying to translate a string that contains HTML tags, but Laravel blade returns me in plain text.

{{ _i('The <b>%s</b> referral program is a great way to spread the word of this great service and to earn even more money with your short links! Refer friends and receive %s of their earnings for life!', 'gano.com', '20%') }}

result:

The <b>gano.com</b> referral program is a great way to spread the word of this great service and to earn even more money with your short links! Refer friends and receive 20% of their earnings for life!

I'm using the following Laravel package.

https://github.com/Belphemur/laravel-gettext

Upvotes: 1

Views: 3221

Answers (2)

kapitan
kapitan

Reputation: 2222

you can render the html tags like so:

{!! 'this text will be <b>bold</b>.' !!}

Output: this text will be bold.

Laravel uses {{ }} to escape tags in order to prevent XSS attacks.

But in any case you need to render the html tags inside the variable, you can use {!! !!}

Upvotes: 2

Rohit Mittal
Rohit Mittal

Reputation: 2104

You can try below two options for this:

{!! _i('The <b>%s</b> referral program is a great way to spread the word of this great service and to earn even more money with your short links! Refer friends and receive %s of their earnings for life!', 'gano.com', '20%') !!}

{!!html_entity_decode(_i('The <b>%s</b> referral program is a great way to spread the word of this great service and to earn even more money with your short links! Refer friends and receive %s of their earnings for life!', 'gano.com', '20%'))!!}

Both should work fine for you.

Upvotes: 2

Related Questions