S
S
Sergey Beloventsev2017-05-30 18:18:10
Yii
Sergey Beloventsev, 2017-05-30 18:18:10

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);
    }

the file is located in the massages/ru-RU/ folder of the module directory in the module I connect its name translit.php
in the view I connect so I get why?
<?= Module::t('translit','Menu setup'); ?>'Menu setup'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2017-05-30
@slo_nik

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);
    }

}

In the configuration, enable the module, in the bootstrap section
'app\modules\main\MainBootstrap',

S
Sergey Beloventsev, 2017-05-31
@Sergalas

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',
            ];
        }

, and then call everything through, that is, it had to match here and here and do not forget to specify the address complete withModule::t('translit','Menu create')translitYii::$app->i18n->translations['translit']Module::t('translit','Menu create')vendor@vendor/sirgalas/yii2-wordperss-menu/messages

M
Maxim Timofeev, 2017-06-01
@webinar

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 question

Ask a Question

731 491 924 answers to any question