【问题标题】:Yii2 render html tag inside translation stringYii2 在翻译字符串中渲染 html 标签
【发布时间】:2015-04-12 18:04:20
【问题描述】:

我在 common/messages/en-Us/frontend/quicksignup 中有一个可翻译的字符串:

return [
    'AcceptTermsAndConditionLabel' => 'I confirm that I am more than 13 years old and accept the {terms and condition}, and {privacy policy} of this website',
];

我的 QuickSignupForm 模型如下所示:

public function attributeLabels()
{
     return [
        'AcceptTermsAndCondition'   => Yii::t('frontend/quicksignup','AcceptTermsAndConditionLabel'),

     ];
}

它呈现以下内容:

I confirm that I am more than 13 years old and accept the {terms and condition}, and {privacy policy} of this website

我想用链接替换{terms and condition}{privacy policy}。但是当我尝试在我的可翻译文件中执行此操作时,即 common/messages/en-Us/frontend/quicksignup 它会呈现为字符串。

下面是输出的截图。如何呈现链接?有什么想法吗?

【问题讨论】:

    标签: internationalization translation yii2 yii2-advanced-app


    【解决方案1】:

    我找到了解决方案。在ActiveField 中使用label 方法并设置format=>raw 选项。像这样的代码:

    <?= $form->field($model, 'rememberMe')->checkbox()->label(Yii::t('app', 'I confirm that I am more than 13 years old and accept the {terms and condition}, and {privacy policy} of this website', ['privacy policy'=>
            Html::a('111', '/asd/')]), ['format' => 'raw']) ?>
    

    这个解决方案有一个减号。您必须设置两次标签:在模型中和在形式中。

    【讨论】:

    • 工作就像魅力 :) 非常感谢你拯救了我的一天!
    猜你喜欢
    • 2017-03-21
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 2011-07-26
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多