我在 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
我想用链接替换{条款和条件}
和{隐私政策}
。但是,当我尝试在可翻译文件中执行此操作时,即 common/messages/en-Us/frontend/quicksignup 它会呈现为字符串。
下面是输出的屏幕截图。我怎样才能呈现链接?有什么想法吗?
最佳答案
我找到了解决方案。在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']) ?>
这个解决方案有一个缺点。您必须设置标签两次:在模型中和在表单中。
关于internationalization - Yii2在翻译字符串中渲染html标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29592707/