[Solved] Multiple Files Translation Depending of the type of client

Hello, the situation:


'i18n' => [

            'translations' => [

                'app*' => [

                    'class' => 'yii\i18n\PhpMessageSource',

                    'basePath' => '@common/messages',

                    'fileMap' => [

                        'app' => 'app.php',

                        'app/custom' => function() {return Configuracoes::getI18NCustom();}

                    ],

                ],

            ],

        ],

This is the configuration of translation on file config.php

The file of config "app/custom", may vary from client to client. Why? Depending on the type of client they will see a message, otherwise you can see another … and so on.

The problem:

No accept functions.

If i call Configuracoes::getI18NCustom()

‘app/custom’ => Configuracoes::getI18NCustom()

The function getI18NCustom contains:

$tipoCliente = \common\modules\configuracao\models\Configuracao::find([‘grupo’ => ‘informacaoCliente’, ‘chave’ => ‘tipo_cliente’])->one();

this line returns an error:

Fatal error: Call to a member function getDb() on a non-object.

How i solve this? Any ideas?

Best Regards,

Rafael

Solved.

I removed i18n from config.php and add it on init () of modules:


 public function init()

    {

        parent::init();

        Configuracao::registerTranslations();

    }


public static function registerTranslations()

    {

        \Yii::$app->i18n->translations['app*'] = [

            'class' => 'yii\i18n\PhpMessageSource',

            'basePath' => '@common/messages',

            'fileMap' => [

                'app' => 'app.php',

                'app/custom' => self::getI18NCustom()

            ],

        ];

    }