我的yii2扩展程序如何使用此扩展程序的邮件?
在我作为belove使用的模块上,但在作为扩展程序执行后,它不起作用
public function init()
{
parent::init();
$this->registerTranslations();
}
public function registerTranslations()
{
Yii::$app->i18n->translations['vendor/abdualiym/yii2-contacts/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en',
'basePath' => '@vendor/abdualiym/contacts/messages',
'fileMap' => [
'vendor/abdualiym/yii2-contacts' => 'contact.php',
],
];
}
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t('vendor/abdualiym/yii2-contacts/' . $category, $message, $params, $language);
}
```
答案 0 :(得分:0)
要在扩展程序中拥有自己的消息,我确实遵循:
'contact' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@vendor/abdualiym/yii2-contacts/messages',
'sourceLanguage' => 'en',
'fileMap' => [
'contact' => 'contact.php',
],
],
然后我用
Yii::t('contact', 'Text')