Get yii\base\ErrorException after installing yii2-translate-manager

Hey, for the http://www.yiiframework.com/extension/yii2-translate-manager#add-comment extension I have no idea where to place the following code snippet.

Front end translation


'bootstrap' => ['translatemanager'],

'component' => [

    'translatemanager' => [

        'class' => 'lajax\translatemanager\Component'

    ]

]

Could anybody help me out!?

I’ve placed the basic template with the yii2 translate manager extension on my webserver.

As you can see: palmomedia.de/yii3/basic/web/ the page is running well but the translation frontend isn’t working.

As you can see here: palmomedia.de/yii3/basic/web/index.php?r=translatemanager%2Flanguage%2Flist

Server ftp is:

Servername: palmomedia.de

Username: yii3

Password: yii123

Has anybody time to check my configuration?

Thanks a lot!

Hi!

For the translatemanager to work the config settings need to be defined in common/config/main.php (in case of yii2-advanced version). The visibility of the module can be set through user privileges (roles, allowedIPs). Unauthorised access can be prevented this way.

example:

common/config/main.php:




return [

    // ...

    'language' => 'en-US',

    'components' => [

        'i18n' => [

            'translations' => [

                '*' => [

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

                    'db' => 'db',

                    'sourceLanguage' => 'xx-XX', // Developer language

                    'sourceMessageTable' => 'language_source',

                    'messageTable' => 'language_translate',

                    'cachingDuration' => 86400,

                    'enableCaching' => true,

                ],

            ],

        ],

        'translatemanager' => [

            'class' => 'lajax\translatemanager\Component',

        ]

    ],

    'modules' => [

        'translatemanager' => [

            'class' => 'lajax\translatemanager\Module',

            'root' => '@app', // The root directory of the project scan.

            'layout' => 'language', // Name of the used layout. If using own layout use ‘null’.

            'allowedIPs' => ['127.0.0.1'], // IP addresses from which the translation interface is accessible.

            'roles' => ['@'], // For setting access levels to the translating interface.

            'tmpDir' => '@runtime', // Writable directory for the client-side temporary language files. 

            // IMPORTANT: must be identical for all applications (the AssetsManager serves the JavaScript files containing language elements from this directory).

            'ignoredCategories' => ['yii'], // these categories won’t be included in the language database.

            'ignoredItems' => ['config'], // these files will not be processed.

            'tables' => [                   // Properties of individual tables

                [

                    'connection' => 'db', // connection identifier

                    'table' => 'language', // table name

                    'columns' => ['name', 'name_ascii']  //names of multilingual fields

                ]

            ]

        ],

    ],

    //...

];



frontend/config/main.php




return [

    // ...

    'bootstrap' => ['translatemanager'],

    // ...

];



Best regards,

lajax

Hello, thanks so far. But I just running the basic Template theme without frontend and backend dirs.

I have chnaged the config/web.php as you documented but the error is still the same as you can see here:


1. in HttpException.php at line 48

39404142434445464748495051525354555657     * Constructor.

     * @param integer $status HTTP status code, such as 404, 500, etc.

     * @param string $message error message

     * @param integer $code error code

     * @param \Exception $previous The previous exception used for the exception chaining.

     */

    public function __construct($status, $message = null, $code = 0, \Exception $previous = null)

    {

        $this->statusCode = $status;

        parent::__construct($message, $code, $previous);

    }

 

    /**

     * @return string the user-friendly name of this exception

     */

    public function getName()

    {

        if (isset(Response::$httpStatuses[$this->statusCode])) {

            return Response::$httpStatuses[$this->statusCode];

2. yii\base\ErrorHandler::handleFatalError()

My web.php


$params = require(__DIR__ . '/params.php');


$config = [

    'id' => 'basic',

    'basePath' => dirname(__DIR__),

    //'bootstrap' => ['log'],

    'language' => 'en-US',

    'components' => [

        'i18n' => [

            'translations' => [

                '*' => [

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

                    'db' => 'db',

                    'sourceLanguage' => 'en-US', // Developer language

                    'sourceMessageTable' => 'language_source',

                    'messageTable' => 'language_translate',

                    'cachingDuration' => 86400,

                    'enableCaching' => true,

                ],

            ],


        ],

        'translatemanager' => [

            'class' => 'lajax\translatemanager\Component',

        ],


        'request' => [

            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation

            'cookieValidationKey' => 'sadasd76as87d6as87d6as7',

        ],

        'cache' => [

            'class' => 'yii\caching\FileCache',

        ],

        'user' => [

            'identityClass' => 'app\models\User',

            'enableAutoLogin' => true,

        ],

        'errorHandler' => [

            'errorAction' => 'site/error',

        ],

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            // send all mails to a file by default. You have to set

            // 'useFileTransport' to false and configure a transport

            // for the mailer to send real emails.

            'useFileTransport' => true,

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'db' => require(__DIR__ . '/db.php'),

    ],

    'params' => $params,

    'modules' => [

        'translatemanager' => [

            'class' => 'lajax\translatemanager\Module',

            'root' => '@app',               // The root directory of the project scan.

            'layout' => 'language',         // Name of the used layout. If using own layout use ‘null’.

            'allowedIPs' => ['127.0.0.1'],   // IP addresses from which the translation interface is accessible.

            'roles' => ['@'],                // For setting access levels to the translating interface.

            'tmpDir' => '@runtime',         // Writable directory for the client-side temporary language files. 

                                            // IMPORTANT: must be identical for all applications (the AssetsManager serves the JavaScript files containing language elements from this directory).

            'ignoredCategories' => ['yii'], // these categories won’t be included in the language database.

            'ignoredItems' => ['config'],   // these files will not be processed.

            'tables' => [                   // Properties of individual tables

                [

                    'connection' => 'db',   // connection identifier

                    'table' => 'language',  // table name

                    'columns' => ['name', 'name_ascii']  //names of multilingual fields

                ]

            ]

        ],

    ],

];


if (YII_ENV_DEV) {

    // configuration adjustments for 'dev' environment

    $config['bootstrap'][] = 'debug';

    $config['modules']['debug'] = 'yii\debug\Module';


    $config['bootstrap'][] = 'gii';

    $config['modules']['gii'] = 'yii\gii\Module';

}


return $config;



The yii2-base application is not supported due to some unresolved dependencies. It will still work however with the following configuration settings:




$params = require(__DIR__ . '/params.php');


$config = [

    'id' => 'basic',

    'basePath' => dirname(__DIR__),

    'bootstrap' => ['log', 'translatemanager'],

    'language' => 'en-US',

    'components' => [

        'i18n' => [

            'translations' => [

                '*' => [

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

                    'db' => 'db',

                    'sourceLanguage' => 'en-US', // Developer language

                    'sourceMessageTable' => 'language_source',

                    'messageTable' => 'language_translate',

                    'cachingDuration' => 86400,

                    'enableCaching' => true,

                ],

            ],


        ],

        'translatemanager' => [

            'class' => 'lajax\translatemanager\Component',

        ],


        'urlManager' => [

            'enablePrettyUrl' => true,

            'showScriptName' => false,

//        'rules' => [

//        // your rules go here

//        ],

        // ...

        ],

        'request' => [

            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation

            'cookieValidationKey' => 'sadasd76as87d6as87d6as7',

        ],

        'cache' => [

            'class' => 'yii\caching\FileCache',

        ],

        'user' => [

            'identityClass' => 'app\models\User',

            'enableAutoLogin' => true,

        ],

        'errorHandler' => [

            'errorAction' => 'site/error',

        ],

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            // send all mails to a file by default. You have to set

            // 'useFileTransport' to false and configure a transport

            // for the mailer to send real emails.

            'useFileTransport' => true,

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                ],

            ],

        ],

        'db' => require(__DIR__ . '/db.php'),

    ],

    'params' => $params,

    'modules' => [

        'translatemanager' => [

            'class' => 'lajax\translatemanager\Module',

            'root' => '@webroot',           // The root directory of the project scan.

            'layout' => null,               // Name of the used layout. If using own layout use ‘null’.

            'allowedIPs' => ['127.0.0.1'],   // IP addresses from which the translation interface is accessible.

//            'roles' => ['@'],                // For setting access levels to the translating interface.

            'tmpDir' => '@runtime',         // Writable directory for the client-side temporary language files. 

                                            // IMPORTANT: must be identical for all applications (the AssetsManager serves the JavaScript files containing language elements from this directory).

            'ignoredCategories' => ['yii'], // these categories won’t be included in the language database.

            'ignoredItems' => ['config'],   // these files will not be processed.

            'tables' => [                   // Properties of individual tables

                [

                    'connection' => 'db',   // connection identifier

                    'table' => 'language',  // table name

                    'columns' => ['name', 'name_ascii']  //names of multilingual fields

                ]

            ]

        ],

    ],

];


if (YII_ENV_DEV) {

    // configuration adjustments for 'dev' environment

    $config['bootstrap'][] = 'debug';

    $config['modules']['debug'] = 'yii\debug\Module';


    $config['bootstrap'][] = 'gii';

    $config['modules']['gii'] = 'yii\gii\Module';

}


return $config;



Because of the url ovverriding you will have to create a .htaccess file in the web directory.

web/.htaccess




RewriteEngine on


# If a directory or a file exists, use the request directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward the request to index.php

RewriteRule . index.php



I turned off the module’s layout so you can turn on the meu in the site’s own layout.

views/layouts/main.php




echo Nav::widget([

    'options' => ['class' => 'navbar-nav navbar-right'],

    'items' => [

        ['label' => 'Home', 'url' => ['/site/index']],

        ['label' => 'About', 'url' => ['/site/about']],

        ['label' => 'Contact', 'url' => ['/site/contact']],


        ['label' => Yii::t('language', 'Language'), 'items' => [    // watch your privileges <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />

            ['label' => Yii::t('language', 'Languages'), 'url' => ['/translatemanager/language/list']],

            ['label' => Yii::t('language', 'Scan'), 'url' => ['/translatemanager/language/scan']],

            ['label' => Yii::t('language', 'Optimize'), 'url' => ['/translatemanager/language/optimizer']],

        ]],


        Yii::$app->user->isGuest ?

            ['label' => 'Login', 'url' => ['/site/login']] :

            ['label' => 'Logout (' . Yii::$app->user->identity->username . ')',

                'url' => ['/site/logout'],

                'linkOptions' => ['data-method' => 'post']],

    ],

]);



The dependencies of the yii2-base application will also be resolved soon.

Best regards,

lajax

Thanks for the reply, but it’s still the same error. I changed everything you mentioned, any more ideas!? :)

http://palmomedia.de/yii3/basic/web/translatemanager/language/list

Thanks a lot @lajax

It was my fault, my server configuration wasn’t completed.

I has to have Intl extension installed!

Intl extension Warning Internationalization support PHP Intl extension 1.0.2 or higher is required when you want to use advanced parameters formatting in Yii::t(), non-latin languages with Inflector::slug(), IDN-feature of EmailValidator or UrlValidator or the yii\i18n\Formatter class.

Topic is ready to close!