【问题标题】:HTML tags in translation Laravel翻译 Laravel 中的 HTML 标签
【发布时间】:2019-07-16 02:42:29
【问题描述】:

我正在尝试翻译一个包含 HTML 标记的字符串,但 Laravel Blade 以纯文本形式返回给我。

{{ _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%') }}

结果:

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!

我正在使用以下 Laravel 包。

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

【问题讨论】:

    标签: php laravel laravel-5 laravel-blade gettext


    【解决方案1】:

    您可以尝试以下两个选项:

    {!! _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%'))!!}
    

    两者都应该适合你。

    【讨论】:

      【解决方案2】:

      你可以像这样渲染 html 标签:

      {!! 'this text will be &lt;b&gt;bold&lt;/b&gt;.' !!}

      输出:此文本将是粗体

      Laravel 使用{{ }} 转义标签以防止 XSS 攻击。

      但是无论如何你需要在变量内部渲染html标签,你可以使用{!! !!}

      【讨论】:

        猜你喜欢
        • 2013-04-08
        • 1970-01-01
        • 2015-11-11
        • 1970-01-01
        • 2015-12-08
        • 1970-01-01
        • 2017-02-11
        • 1970-01-01
        相关资源
        最近更新 更多