Yii i18n messages configuration for generating translations

@param string $dir the directory path where translation files will exist
@param string $cat the message category

@return void
979056
public function initI18N($dir = '', $cat = '')
    {
        if (empty($cat) && empty($this->_msgCat)) {
            return;
        }

        if (empty($cat)) {
            $cat = $this->_msgCat;
        }

        if (empty($dir)) {
            $reflector = new \ReflectionClass(get_class($this));
            $dir = dirname($reflector->getFileName());
        }

        Yii::setAlias("@{$cat}", $dir);
        $config = [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => "@{$cat}/messages",
            'forceTranslation' => true
        ];

        $globalConfig = ArrayHelper::getValue(Yii::$app->i18n->translations, "{$cat}*", []);
        if (!empty($globalConfig)) {
            $config = array_merge($config, is_array($globalConfig) ? $globalConfig : (array) $globalConfig);
        }

        if (!empty($this->i18n) && is_array($this->i18n)) {
            $config = array_merge($config, $this->i18n);
        }

        Yii::$app->i18n->translations["{$cat}*"] = $config;
    }
79879
public function registerTranslations() {
		$i18n = \Yii::$app->i18n;
		if($this->messageCategory && !isset($i18n->translations[$this->messageCategory])) {
			$i18n->translations[$this->messageCategory] = [
				'class' => 'yii\i18n\PhpMessageSource',
				'basePath' => $this->basePath . DIRECTORY_SEPARATOR . 'messages',
				'sourceLanguage' => \Yii::$app->sourceLanguage,
			];
		}
	}
646580
private function rmdir($dir)
    {
        // remove all files
        $files = scandir($dir);
        foreach ($files as $file) {
            if ($file == '.' || $file == '..') {
                continue;
            }

            $path = $dir . '/' . $file;
            if (is_dir($path)) {
                $this->rmdir($path);
            } elseif (is_file($path)) {
                unlink($path);
            }
        }

        rmdir($dir);
    }
1337944
public function writeSupportDirectories(Package $package, $directory)
	{
		foreach (array('config', 'controllers', 'lang', 'migrations', 'views') as $support)
		{
			$this->writeSupportDirectory($package, $support, $directory);
		}
	}
866052
private void updateOmissionCategories(String[] cat) {
        short itens = this.omissionsCategoriesDropbox.getItemCount();
        if(itens > 0) {
            this.omissionsCategoriesDropbox.removeItems((short)0, itens);
        }
        this.omissionsCategoriesDropbox.addItem(I18nLabelsLoader.ADDON_OMISSION_CATEGORY_CUSTOM, (short)0);
        this.omissionsCategoriesDropbox.addItem(I18nLabelsLoader.ADDON_OMISSION_CATEGORY_UNKNOWN, (short)1);
        this.omissionsCategoriesDropbox.addItems(cat, (short)2);

    }
841753
protected function ensureDirectoryExists($dir)
    {
        if (! file_exists($dir) && ! @mkdir($dir, 0777, true) && ! is_dir($dir)) {
            throw new InvalidConfigurationException(sprintf('Directory "%s" cannot be created!', $dir), 1451862775);
        }
    }
355203
public function rmdirr($dir)
    {
        if ($handle = opendir("$dir")) {
            while ($item = readdir($handle)) {
                if (($item != ".") && ($item != "..")) {
                    if (is_dir("$dir/$item")) {
                        $this->rmdirr("$dir/$item");
                    } else {
                        unlink("$dir/$item");
                    }
                }
            }
            closedir($handle);
            rmdir($dir);
        }
    }
978800
protected function generateIndexView($dir)
    {
        $this->renderFile('crud/views/index.html.twig.twig', $dir.'/index.html.twig', array(
            'bundle' => $this->bundle->getName(),
            'entity' => $this->entity,
            'entities_name' => strtolower(Inflector::pluralize($this->entity)),
            'fields' => $this->metadata->fieldMappings,
            'actions' => $this->actions,
            'record_actions' => $this->getRecordActions(),
            'route_prefix' => $this->routePrefix,
            'route_name_prefix' => $this->routeNamePrefix,
            'dir' => $dir,
        ));
    }
711503
public function chdir($dir)
    {
        return ($this->isConnected() === true) ? ftp_chdir($this->getConnection(), $dir) : false;
    }
1101805
protected function doChangeDir($dir)
    {
        $connection = $this->connection;

        return $this->retry(function () use ($connection, $dir) {
            $res = @ftp_chdir($connection, $dir);

            if (false === $res) {
                throw new \RuntimeException("Changing directory failed: ".$dir);
            }
        });
    }
504963
protected function _makeDirectory( $directory )
    {
        try
        {
            if ( !is_dir( $directory ) && !is_file( $directory ) && !is_link( $directory ) )
            {
                mkdir( $directory, 0755, true );
            }
        }
        catch ( \Exception $e )
        {
            $this->error( $e->getMessage() );
            die;
        }
    }
1036375
public function generateTo($directory){
        $translations = array();
        
        foreach($this->extensions as $extension){
            $jsFilePath = $this->basePath . '/' . $extension . '/locales/' . $this->langCode . '/messages_po.js';
            if(file_exists($jsFilePath)){
                $translate = json_decode(file_get_contents($jsFilePath),false);
                if($translate != null){
                    $translations = array_merge($translations, (array)$translate);
                }
            }
        }
        //the bundle contains as well some translations
        $content = array(
            'serial' =>  $this->getSerial(),
            'date'   => time(),
            'translations' =>   $translations
        );
        
        if (!empty($this->taoVersion)) {
            $content['version'] = $this->taoVersion;
        }
        
        if(is_dir($directory)){
            if(!is_dir($directory. '/' . $this->langCode)){
                mkdir($directory. '/' . $this->langCode);
            }
            $file = $directory. '/' . $this->langCode . '/messages.json';
            if(@file_put_contents($file, json_encode($content))){
                return $file;
            } 
        }
        return false; 
    }
90093
public function archiveDir($dir, $destination)
    {
        $tar = $this->getTarExecutable();
        $dir = $this->fixTarPath($dir);
        $destination = $this->fixTarPath($destination);
        $this->shell->execute([$tar, '-czp', '-C' . $dir, '-f' . $destination, '.'], null, true);
    }
1172542
protected function getI18nDirectoryText($directory, $isValid)
    {
        if ($this->translator !== null) {
            if ($isValid) {
                $sentence = 'The directory %directory% is writable';
            } else {
                $sentence = 'The directory %directory% is not writable';
            }

            $translatedText = $this->translator->trans(
                $sentence,
                array(
                    '%directory%' => $directory
                )
            );
        } else {
            $translatedText = sprintf('The directory %s should be writable', $directory);
        }

        return $translatedText;
    }
728262
public static function configure($lang, $directory)
    {
        if (static::$instance === null) {
            static::$instance = new self($lang, $directory);
        }

        return static::$instance;
    }
922588
public function setDir($dir)
    {
        if (in_array($dir, Direction::asArray(), true) === true) {
            $this->dir = $dir;
        } else {
            $msg = "The 'dir' argument must be a value from the Direction enumeration.";
            throw new InvalidArgumentException($msg);
        }
    }
796866
public function copyLanguage($dir, $target)
	{
		// Equals administrator/language or language
		$path  = $this->getSourceFolder() . "/" . $dir;
		$files = array();

		$hdl = opendir($path);

		while ($entry = readdir($hdl))
		{
			$p = $path . "/" . $entry;

			// Which languages do we have
			// Ignore hidden files
			if (substr($entry, 0, 1) != '.')
			{
				// Language folders
				if (!is_file($p))
				{
					// Make folder at destination
					$this->_mkdir($target . "/" . $dir . "/" . $entry);

					$fileHdl = opendir($p);

					while ($file = readdir($fileHdl))
					{
						// Only copy language files for this extension (and sys files..)
						if (substr($file, 0, 1) != '.' && strpos($file, $this->ext . "."))
						{
							$files[] = array($entry => $file);

							// Copy file
							$this->_copy($p . "/" . $file, $target . "/" . $dir . "/" . $entry . "/" . $file);
						}
					}

					closedir($fileHdl);
				}
			}
		}

		closedir($hdl);

		return $files;
	}