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

标签 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

我想用链接替换{条款和条件}{隐私政策}。但是,当我尝试在可翻译文件中执行此操作时,即 common/messages/en-Us/frontend/quicksignup 它会呈现为字符串。

下面是输出的屏幕截图。我怎样才能呈现链接?有什么想法吗?

enter image description here

最佳答案

我找到了解决方案。在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/

相关文章:

java - 玩! Framework 2.0.3,i18n 错误,预期为 `=',但发现为 `-'

css - 如何使用 sass 自动化多语言背景图像

vb.net - ATN 从 QBasic 到 VB.Net

javascript - phantomjs 无法正确显示 Angular 数据

php - yii2 中的 Css 和 bootstrap

c# - 国际化和 C# 方法属性?

java - 字符读取器/写入器 FileReader 和 FileWriter 无法读取/写入中文文件,但字节读取器/写入器工作正常

php - 翻译成规则不规则的语言

windows - 在 Windows 中获取鼠标光标下的单词

gridview - 如何更改 yii2 中所有 gridview 的标题颜色?