0
我有以下我yii2-basic-appconfig/params.php
:Yii2翻譯配置不起作用/ PARAMS
<?php
$siteName = Yii::t('app','Site Name'); //previously, this value had been placed directly in the array just a try to make it available to the translation
return [
'adminEmail' => '[email protected]',
'siteName' => $siteName,
'textToPrint' => null,
'meta-description' => $siteName,
];
消息Site Name
是已經在@app/messages/ar/app.php
翻譯和翻譯的網站上正常工作。
然而,當我嘗試使用元標籤描述主要佈局如下所示:
<meta name="description" content="<?= Yii::$app->params['meta-description'] ?>" />
所以,在任何視圖,如果我有一個值設置爲Yii::$app->params['meta-description']
它應該在打印出佈局,而當沒有任何提供的值時,它應該打印在config/params.php
中定義的初始值。
問題是,初始值打印時沒有翻譯。這是問題可以通過如下面的主要佈局轉換的字符串來解決:
<meta name="description" content="<?= Yii::t('app',Yii::$app->params['meta-description']) ?>" />
由於上述解決方案,我有兩個問題:
- 爲什麼串並沒有在翻譯
config/params.php
? - 大量使用
Yii::t()
與很多未翻譯的字符串(在我的情況下,當我決定在視圖中覆蓋值Yii::$app->params['meta-description']
)時,是否有任何性能問題?
1:換句話說,'params.php'文件將比翻譯功能更早激活。 :) –