Yii2 在翻译字符串中渲染 html 标签
Yii2 render html tag inside translation string
我在 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 它被呈现为字符串。
下面是输出的屏幕截图。如何呈现链接?有什么想法吗?
我找到了解决办法。在 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']) ?>
这个解决方案有一个减号。您必须设置标签两次:在模型中和在表单中。
我在 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 它被呈现为字符串。
下面是输出的屏幕截图。如何呈现链接?有什么想法吗?
我找到了解决办法。在 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']) ?>
这个解决方案有一个减号。您必须设置标签两次:在模型中和在表单中。