Initialisation example: Simple example: ~~~ 'modules' => [ 'translatemanager' => [ 'class' => 'lajax\translatemanager\Module', ], ], ~~~ Complex example: ~~~ '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). 'phpTranslators' => ['::t'], // list of the php function for translating messages. 'jsTranslators' => ['lajax.t'], // list of the js function for translating messages. 'patterns' => ['*.js', '*.php'],// list of file extensions that contain language elements. 'ignoredCategories' => ['yii'], // these categories won’t be included in the language database. 'ignoredItems' => ['config'], // these files will not be processed. 'languageTable' => 'language', // Name of the database table storing the languages. 'scanTimeLimit' => null, // increase to prevent "Maximum execution time" errors, if null the default max_execution_time will be used 'searchEmptyCommand' => '!', // the search string to enter in the 'Translation' search field to find not yet translated items, set to null to disable this feature 'defaultExportStatus' => 1, // the default selection of languages to export, set to 0 to select all languages by default 'defaultExportFormat' => 'json',// the default format for export, can be 'json' or 'xml' 'tables' => [ // Properties of individual tables [ 'connection' => 'db', // connection identifier 'table' => '{{%language}}', // table name 'columns' => ['name', 'name_ascii'], //names of multilingual fields 'category' => 'database-table-name', // the category is the database table name ] ] ], ], ~~~ IMPORTANT: If you want to modify the value of roles (in other words to start using user roles) you need to enable authManager in the common config. Using of authManager: http://www.yiiframework.com/doc-2.0/guide-security-authorization.html examples: PhpManager: ~~~ 'components' => [ 'authManager' => [ 'class' => 'yii\rbac\PhpManager', ], ], ~~~ DbManager: ~~~ 'components' => [ 'authManager' => [ 'class' => 'yii\rbac\DbManager', ], ], ~~~
Since: 1.0
Author: Lajos Molnár (lajax.m@gmail.com)
Inheritance: extends yii\base\Module
 /**
  * @param \lajax\translatemanager\Module $module
  * @param string $language_id Language of the file to be generated.
  */
 public function __construct($module, $language_id)
 {
     $this->_languageId = $language_id;
     $this->_basePath = Yii::getAlias($module->tmpDir);
     if (!is_dir($this->_basePath)) {
         throw new InvalidConfigException("The directory does not exist: {$this->_basePath}");
     } elseif (!is_writable($this->_basePath)) {
         throw new InvalidConfigException("The directory is not writable by the Web process: {$this->_basePath}");
     }
     $this->_basePath = $module->getLanguageItemsDirPath();
     if (!is_dir($this->_basePath)) {
         mkdir($this->_basePath);
     }
     if (!is_writable($this->_basePath)) {
         throw new InvalidConfigException("The directory is not writable by the Web process: {$this->_basePath}");
     }
 }
 /**
  * Show export form or generate export file on post
  * @return string
  */
 public function run()
 {
     /** @var Module $module */
     $module = Module::getInstance();
     $model = new ExportForm(['format' => $module->defaultExportFormat]);
     if ($model->load(Yii::$app->request->post())) {
         $fileName = Yii::t('language', 'translations') . '.' . $model->format;
         Yii::$app->response->format = $model->format;
         Yii::$app->response->formatters = [Response::FORMAT_XML => ['class' => XmlResponseFormatter::className(), 'rootTag' => 'translations'], Response::FORMAT_JSON => ['class' => JsonResponseFormatter::className()]];
         Yii::$app->response->setDownloadHeaders($fileName);
         return $model->getExportData();
     } else {
         if (empty($model->languages)) {
             $model->exportLanguages = $model->getDefaultExportLanguages($module->defaultExportStatus);
         }
         return $this->controller->render('export', ['model' => $model]);
     }
 }
 /**
  * @param array $params Search conditions.
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     Yii::$app->session->setFlash('TM-language__id', $params['language_id']);
     $query = LanguageSource::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'category', 'message', 'translation' => ['asc' => ['translation' => SORT_ASC], 'desc' => ['translation' => SORT_DESC], 'label' => Yii::t('language', 'Translation')]]]);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith('languageTranslateByLanguage');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category' => $this->category]);
     $query->andFilterWhere(['like', 'message', $this->message]);
     $query->joinWith(['languageTranslateByLanguage' => function ($query) {
         if ($this->translation) {
             $searchEmptyCommand = Module::getInstance()->searchEmptyCommand;
             if ($searchEmptyCommand && $this->translation == $searchEmptyCommand) {
                 $query->andWhere(['or', ['translation' => null], ['translation' => '']]);
             } else {
                 $query->andWhere(['like', 'translation', $this->translation]);
             }
         }
     }]);
     return $dataProvider;
 }