Class lajax\translatemanager\Module

Inheritancelajax\translatemanager\Module » yii\base\Module
Available since version1.0

This is the main module class for the TranslateManager module.

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

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$allowedIPs array The list of IPs that are allowed to access this module. lajax\translatemanager\Module
$connection string The default db connection lajax\translatemanager\Module
$controllerNamespace lajax\translatemanager\Module
$defaultExportFormat string The default export format (yii\web\Response::FORMAT_JSON or yii\web\Response::FORMAT_XML). lajax\translatemanager\Module
$defaultExportStatus integer The minimum status for a language to be selected by default in the export list. lajax\translatemanager\Module
$defaultRoute lajax\translatemanager\Module
$ignoredCategories array List of the categories being ignored. lajax\translatemanager\Module
$ignoredItems array Directories/files being ignored. lajax\translatemanager\Module
$jsTranslators array List of the JavaScript function for translating messages. lajax\translatemanager\Module
$languageTable string The database table storing the languages. lajax\translatemanager\Module
$layout string Name of the used layout. lajax\translatemanager\Module
$patternArray string PHP Regular expression to match arrays containing language elements to translate. lajax\translatemanager\Module
$patternArrayRecursive string PHP Regular expression to detect langualge elements within arrays. lajax\translatemanager\Module
$patternArrayTranslator string PHP Regular expression to match arrays containing language elements to translate. lajax\translatemanager\Module
$patternJs string Regular expression to detect JavaScript lajax. lajax\translatemanager\Module
$patternPhp string Regular expression to match PHP Yii::t functions. lajax\translatemanager\Module
$patterns array List of file extensions that contain language elements. lajax\translatemanager\Module
$phpTranslators array List of the PHP function for translating messages. lajax\translatemanager\Module
$roles array The list of rights that are allowed to access this module. lajax\translatemanager\Module
$root string|array The root directory or directories of the scanning. lajax\translatemanager\Module
$scanRootParentDirectory bool Whether scan the defined root parent directory, or the folder itself. lajax\translatemanager\Module
$scanTimeLimit integer The max_execution_time used when scanning, when set to null the default max_execution_time will not be modified. lajax\translatemanager\Module
$searchEmptyCommand string The search string to find empty translations. lajax\translatemanager\Module
$subDir string Name of the subdirectory which contains the language elements. lajax\translatemanager\Module
$tables array Identifiers for the database tables containing language elements. lajax\translatemanager\Module
$tmpDir string Writeable directory used for keeping the generated javascript files. lajax\translatemanager\Module

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
SESSION_KEY_ENABLE_TRANSLATE 'frontendTranslation_EnableTranslate' Session key for storing front end translating privileges. lajax\translatemanager\Module

Property Details

$allowedIPs public property

The list of IPs that are allowed to access this module.

public array $allowedIPs = ['127.0.0.1''::1']
$connection public property

The default db connection

public string $connection 'db'
$controllerNamespace public property
public $controllerNamespace 'lajax\translatemanager\controllers'
$defaultExportFormat public property

The default export format (yii\web\Response::FORMAT_JSON or yii\web\Response::FORMAT_XML).

public string $defaultExportFormat = \yii\web\Response::FORMAT_JSON
$defaultExportStatus public property

The minimum status for a language to be selected by default in the export list.

$defaultRoute public property
public $defaultRoute 'language/list'
$ignoredCategories public property

List of the categories being ignored.

$ignoredItems public property

Directories/files being ignored.

public array $ignoredItems = ['.svn''.git''.gitignore''.gitkeep''.hgignore''.hgkeep''/messages''/BaseYii.php''runtime''bower''nikic']
$jsTranslators public property

List of the JavaScript function for translating messages.

public array $jsTranslators = ['lajax.t']
$languageTable public property

The database table storing the languages.

public string $languageTable '{{%language}}'
$layout public property

Name of the used layout. If you want to use the site default layout set value null.

public string $layout 'language'
$patternArray public property

PHP Regular expression to match arrays containing language elements to translate.

public string $patternArray "#\@translate[^\$]+\$(?P<text>.+?)[\]\)];#smui"
$patternArrayRecursive public property

PHP Regular expression to detect langualge elements within arrays.

public string $patternArrayRecursive '#(?P<category>)(\[|\(|>|,|)\s*(?P<text>\'.*?(?<!\\\\)\'|".*?(?<!\\\\)"?)\s*(,|$)#s'
$patternArrayTranslator public property

PHP Regular expression to match arrays containing language elements to translate.

public string $patternArrayTranslator '#\@translate[^\$]+(?P<translator>[\w\d\s_]+[^\(\[]+)#s'
$patternJs public property

Regular expression to detect JavaScript lajax.t functions.

public string $patternJs '#lajax\.t\s*\(\s*(?P<text>\'.*?(?<!\\\\)\'|".*?(?<!\\\\)"?)\s*[,\)]#s'
$patternPhp public property

Regular expression to match PHP Yii::t functions.

public string $patternPhp '#::t\s*\(\s*(?P<category>\'[\w\d\s_-]+?(?<!\\\\)\'|"[\w\d\s_-]+?(?<!\\\\)"?)\s*,\s*(?P<text>\'.*?(?<!\\\\)\'|".*?(?<!\\\\)"?)\s*[,\)]#s'
$patterns public property

List of file extensions that contain language elements. Only files with these extensions will be processed.

public array $patterns = ['*.php''*.js']
$phpTranslators public property

List of the PHP function for translating messages.

public array $phpTranslators = ['::t']
$roles public property

The list of rights that are allowed to access this module. If you modify, you also need to enable authManager. http://www.yiiframework.com/doc-2.0/guide-security-authorization.html

public array $roles = []
$root public property

The root directory or directories of the scanning. The path can be an alias or a full path.

It is possible to define one root directory as string. In this case the scanRootParentDirectory will be used when determining the actual directory to scan.

Multiple root directories can be declared in an array. In this case all items must point to the exact directory, as scanRootParentDirectory will be omitted.

public string|array $root '@app'
$scanRootParentDirectory public property

Whether scan the defined root parent directory, or the folder itself. This option is used only, when the root option contains a single directory as string (e.g. 'root' => '@app').

IMPORTANT: Changing this from true to false could cause loss of translated items, as optimize action removes the missing items.

If the configured root is @app:

  • true means for advanced apps, that the scan runs on the parent directory, which is the root for the entire project. This is the desired behavior.
  • true means for basic apps, that the scan runs also on the parent directory, which is outside of the project folder (as @app is equals to the project root). This is not desired behavior, it is preferred to change this option to false.
public bool $scanRootParentDirectory true
$scanTimeLimit public property

The max_execution_time used when scanning, when set to null the default max_execution_time will not be modified.

public integer $scanTimeLimit null
$searchEmptyCommand public property

The search string to find empty translations.

$subDir public property

Name of the subdirectory which contains the language elements.

public string $subDir '/translate/'
$tables public property

Identifiers for the database tables containing language elements.

public array $tables null
$tmpDir public property

Writeable directory used for keeping the generated javascript files.

public string $tmpDir '@runtime/'

Method Details

beforeAction() public method

public void beforeAction ( $action )
$action
checkAccess() public method

public boolean checkAccess ( )
return boolean

Whether the module can be accessed by the current user

getLanguageItemsDirPath() public method

public string getLanguageItemsDirPath ( )
return string

The full path of the directory containing the generated JavaScript files.