O'Reilly logo

Mastering Yii by Charles R. Portwood II

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Module translations

As separate entities, modules should contain their own message files separate from your application message files. The recommended way to use messages within modules is as follows:

  1. Within the init() method of your module, define a new translation section for your module:
    parent::init();Yii::$app->i18n->translations['modules/mymodule*'] = [
        'class' => 'yii\i18n\PhpMessageSource',
        'sourceLanguage' => 'en-US',
        'basePath' => '@app/modules/mymodule/messages'
    ];
  2. Create a static method wrapper for Yii::t():
    public static function t($category, $message, $params = [], $language = null)
    {
        return Yii::t('modules/mymodule/' . $category, $message, $params, $language);
    }
  3. Finally, create a separate message configuration file within the messages/ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required