Yii2在翻译字符串中渲染html标签

时间:2015-04-12 18:04:21

标签: internationalization translation yii2 yii2-advanced-app

我在 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 ,它会呈现为字符串。

以下是输出的屏幕截图。我该如何呈现链接?有什么想法吗?

enter image description here

1 个答案:

答案 0 :(得分:2)

我找到解决方案。在label中使用ActiveField方法并设置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']) ?>

此解决方案只有一个减号。您必须设置标签两次:在模型和表单中。