I’m trying to create multiple languages for my module. Right now i’m working on the default language (English). this is what i have so far
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\blabla\controllers';
public function init()
{
parent::init();
$this->registerTranslations();
}
public function registerTranslations()
{
Yii::$app->i18n->translations['modules/blabla/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-GB',
'basePath' => '@app/modules/blabla/messages',
'fileMap' => [
'app' => 'app.php',
],
'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
];
}
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t('modules/blabla/messages/'. $category, $message, $params, $language);
}
}
my language file is in
frontend/modules/blabla/messages/en-GB/app.php
and in my app.php
i have
return [
'Price'=>'Product Price'
];
and in my model i have this
public function attributeLabels()
{
return [
'price'=> Module::t('app', 'Price'),
];
}
in my main.php
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
'sourceLanguage' => 'en-GB',
// 'fileMap' => [
// 'app' => 'app.php',
// ],
'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
],
],
],
but Product Price
it is not showing in my view, only Price
. what am i missing here? thanks