<commit_before><?php
/**
 * I18N class file.
 * @copyright (c) 2014, Bariew
 * @license http://www.opensource.org/licenses/bsd-license.php
 */

namespace bariew\i18nModule\components;

use bariew\i18nModule\models\SourceMessage;
use Yii;
use bariew\i18nModule\models\MessageLanguage;
use bariew\i18nModule\widgets\LangSelect;
use yii\i18n\I18N as CommonI18N;
use yii\web\Application;

/**
 * Extended yii I18N component for translations.
 * Sets language (from url get param).
 * Gets source paths for translate message sources collecting.
 * Gets language selection dropdown widget.
 *
 * @author <NAME> <<EMAIL>>
 */
class I18N extends CommonI18N
{
    public $default;
    public $configPath = '@app/config/i18n.php';

    public $_sourcePaths = [];

    public function init()
    {
        parent::init();
        if (!Yii::$app instanceof Application) {
            return false;
        }
        if (!Yii::$app->db->isActive || !Yii::$app->db->getTableSchema(SourceMessage::tableName())) {
            return false;
        }
        $urlConfig = [
            'class' => I18NUrlManager::className(),
            'enablePrettyUrl'       => true,
            'showScriptName'        => false,
            'enableStrictParsing'   => true,
        ];
        foreach(['baseUrl', 'cache', 'hostInfo','routeParam', 'ruleConfig', 'suffix', 'rules'] as $param)  {
            $urlConfig[$param] = \Yii::$app->urlManager->$param;
        }
        \Yii::configure(\Yii::$app, ['components' => ['urlManager' => $urlConfig]]);
        \Yii::$app->urlManager->addRules([
            '<lang:\w{2}>/<_a>'=>'site/<_a>',
            '<lang:\w{2}>/<_c>/<_a>'=>'<_c>/<_a>',
            '<lang:\w{2}>/<_m>/<_c>/<_a>' => '<_m>/<_c>/<_a>',
            '<lang:\w{2}>\W{0,1}' => 'site/index',
        ], false);

        $this->setLanguage();
    }

    public function getLanguages()
    {
        return $this->getConfig()['languages'];
    }

    public function getConfig()
    {
        return require Yii::getAlias($this->configPath);
    }

    public function setLanguage()
    {
        $this->default = \Yii::$app->language;
        if ($lang = \Yii::$app->request->get('lang')) {
            \Yii::$app->language = $lang;
        }
    }

    public function getSourcePaths()
    {
        if ($this->_sourcePaths) {
            return $this->_sourcePaths;
        }
        $result = [
            \Yii::getAlias('@app/modules', false),
            \Yii::getAlias('@app/controllers', false),
            \Yii::getAlias('@app/models', false),
            \Yii::getAlias('@app/widgets', false),
            \Yii::getAlias('@app/components', false),
        ];<commit_msg>removed component init<commit_after><?php
/**
 * I18N class file.
 * @copyright (c) 2014, Bariew
 * @license http://www.opensource.org/licenses/bsd-license.php
 */

namespace bariew\i18nModule\components;

use bariew\i18nModule\models\SourceMessage;
use Yii;
use bariew\i18nModule\models\MessageLanguage;
use bariew\i18nModule\widgets\LangSelect;
use yii\i18n\I18N as CommonI18N;
use yii\web\Application;

/**
 * Extended yii I18N component for translations.
 * Sets language (from url get param).
 * Gets source paths for translate message sources collecting.
 * Gets language selection dropdown widget.
 *
 * @author <NAME> <<EMAIL>>
 */
class I18N extends CommonI18N
{
    public $default;
    public $configPath = '@app/config/i18n.php';

    public $_sourcePaths = [];

    public function getLanguages()
    {
        return $this->getConfig()['languages'];
    }

    public function getConfig()
    {
        return require Yii::getAlias($this->configPath);
    }

    public function setLanguage()
    {
        $this->default = \Yii::$app->language;
        if ($lang = \Yii::$app->request->get('lang')) {
            \Yii::$app->language = $lang;
        }
    }

    public function getSourcePaths()
    {
        if ($this->_sourcePaths) {
            return $this->_sourcePaths;
        }
        $result = [
            \Yii::getAlias('@app/modules', false),
            \Yii::getAlias('@app/controllers', false),
            \Yii::getAlias('@app/models', false),
            \Yii::getAlias('@app/widgets', false),
            \Yii::getAlias('@app/components', false),
        ];
{'fraction_non_alphanumeric': 0.16873973245716967, 'fraction_numerical': 0.015019948368927482, 'mean_word_length': 2.5020542317173375, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1832053', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1343, 'n_words': 257}