Answer the question
In order to leave comments, you need to log in
Why do not you get with the internationalization of the module?
this is how I connect it in the module
namespace sirgalas\menu;
class Module extends \yii\base\Module
{
public function registerTranslations()
{
Yii::$app->i18n->translations['modules/users/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'ru-Ru',
'basePath' => 'sirgalas/menu/messages',
];
}
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t($category, $message, $params, $language);
}
'translit','Menu setup');
= Module::t('Menu setup'
Answer the question
In order to leave comments, you need to log in
Good evening.
Here is an example for you, substitute your module name
namespace app\modules\main;
//use Yii;
use yii\base\BootstrapInterface;
class MainBootstrap implements BootstrapInterface
{
public function bootstrap($app)
{
$app->i18n->translations['modules/main/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'forceTranslation' => true,
'basePath' => '@app/modules/main/messages',
'fileMap' => [
'modules/main/module' => 'module.php'
]
];
}
}
namespace app\modules\main;
use Yii;
/**
* main module definition class
*/
class MainModule extends \yii\base\Module
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'app\modules\main\controllers';
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t('modules/main/' . $category, $message, $params, $language);
}
}
'app\modules\main\MainBootstrap',
in my case I had to do this
public function registerTranslations()
{
Yii::$app->i18n->translations['translit'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@vendor/sirgalas/yii2-wordperss-menu/messages',
];
}
Module::t('translit','Menu create')
translit
Yii::$app->i18n->translations['translit']
Module::t('translit','Menu create')
vendor
@vendor/sirgalas/yii2-wordperss-menu/messages
You declared the registerTranslations() function, but you had to call it somewhere?
For example in module init
public function init()
{
parent::init();
$this->registerTranslations();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question