Generates language profiles for all language files

@param string $dirname Name of the directory where the translations files are located
@return void
12900
public function learn(string $dirname = '')
    {
        if (empty($dirname))
        {
            $dirname = __DIR__ . '/../../resources/*/*.txt';
        }
        else if (!is_dir($dirname) || !is_readable($dirname))
        {
            throw new \InvalidArgumentException('Provided directory could not be found or is not readable');
        }
        else
        {
            $dirname = rtrim($dirname, '/');
            $dirname .= '/*/*.txt';
        }

        /** @var \GlobIterator $txt */
        foreach (new \GlobIterator($dirname) as $txt)
        {
            $content = mb_strtolower(file_get_contents($txt->getPathname()));

            echo $txt->getBasename('.txt'), PHP_EOL;

            file_put_contents(
                substr_replace($txt->getPathname(), 'json', -3),
                json_encode(
                    [ $txt->getBasename('.txt') => $this->getNgrams($content) ],
                    JSON_UNESCAPED_UNICODE
                )
            );
        }
    }
102594
private function ensuredEraseDir($dirname)
    {
        try
        {
            $listing = $this->fs->listContents($dirname, false);

            foreach ($listing as $item)
            {
                if ($item['type'] === 'dir')
                {
                    $this->fs->deleteDir($item['path']);
                }
                else
                {
                    $this->fs->delete($item['path']);
                }
            }

            return;
        }
        catch (Error $ex)
        {}
        catch (Exception $ex)
        {}

        throw new WriteException("Directory $dirname could not be erased.", 0, $ex);
    }
1086558
public function installLanguage($languageName)
	{
		$this->amOnPage('administrator/index.php?option=com_installer&view=languages');
		$this->debug('I check for Notices and Warnings');
		$this->checkForPhpNoticesOrWarnings();
		$this->debug('Refreshing languages');
		$this->click(array('xpath' => "//div[@id='toolbar-refresh']/button"));
		$this->waitForElement(array('id' => 'j-main-container'), 30);
		$this->searchForItem($languageName);
		$this->waitForElement($this->searchResultLanguageName($languageName), 30);
		$this->click(array('id' => "cb0"));
		$this->click(array('xpath' => "//div[@id='toolbar-upload']/button"));
		$this->waitForText('was successful.', TIMEOUT, array('id' => 'system-message-container'));
		$this->see('No Matching Results', '.alert-no-items');
		$this->debug($languageName . ' successfully installed');
	}
613976
public function loadResourceDirectory($directoryName)
		{
			$resourceLocation = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."res".DIRECTORY_SEPARATOR.$directoryName;
			$results = array();
			
			foreach (scandir($resourceLocation) as $file) 
			{
    			//Only load file if it has a .lst extention (list)
				if((($temp = strlen($file) - strlen(".lst")) >= 0 && strpos($file, ".lst", $temp) !== FALSE))
				{
					$fileEntry = array();
					$fileKey = str_replace(".lst","",$file);
					$fileEntry[0] = $fileKey;
					$fileEntry[1] = $this->readResourceToArray($resourceLocation.DIRECTORY_SEPARATOR.$file);
					$results[] = $fileEntry;
				}
			}
			$this->resourceContent = $results;
		}
811491
public static function createDir(string $dirname, string $visibility = 'public')
    {
        $umask = umask(0);

        if (!is_dir($dirname) && !mkdir($dirname, Filesystem::$permissions['dir'][$visibility], true)) {
            return false;
        }

        umask($umask);

        return true;
    }
178413
protected function makeDir($fileName)
    {
        $dir = dirname($fileName);

        if (! file_exists($dir)) {
            mkdir($dir, 0775, true);
        }
    }
1093771
public function deleteDirectory($dirname)
    {
        $dirpath = $this->path() . '/' . $dirname;
        
        if (is_dir($dirpath)) {
            ToolboxºFileTools::emptyDir($dirpath);
        }
    }
302843
public function containsFolder( $dirName )
	{
		if( !$this->numFolders )
			return FALSE;
		foreach( $this->folders as $key => $information )
			if( $information['name'] == $dirName )
				return TRUE;
	}
1338537
public function list_languages()
    {
        static $sa_languages = array();

        if (!count($sa_languages)) {
            @include(RCUBE_LOCALIZATION_DIR . 'index.inc');

            if ($dh = @opendir(RCUBE_LOCALIZATION_DIR)) {
                while (($name = readdir($dh)) !== false) {
                    if ($name[0] == '.' || !is_dir(RCUBE_LOCALIZATION_DIR . $name)) {
                        continue;
                    }

                    if ($label = $rcube_languages[$name]) {
                        $sa_languages[$name] = $label;
                    }
                }
                closedir($dh);
            }
        }

        return $sa_languages;
    }
284668
public static function parseLanguageFiles($dir = null)
	{
		$languages = array();

		// Search main language directory for subdirectories
		foreach (glob($dir . '/*', GLOB_NOSORT | GLOB_ONLYDIR) as $directory)
		{
			// But only directories with lang code format
			if (preg_match('#/[a-z]{2,3}-[A-Z]{2}$#', $directory))
			{
				$dirPathParts = pathinfo($directory);
				$file         = $directory . '/' . $dirPathParts['filename'] . '.xml';

				if (!is_file($file))
				{
					continue;
				}

				try
				{
					// Get installed language metadata from xml file and merge it with lang array
					if ($metadata = self::parseXMLLanguageFile($file))
					{
						$languages = array_replace($languages, array($dirPathParts['filename'] => $metadata));
					}
				}
				catch (\RuntimeException $e)
				{
				}
			}
		}

		return $languages;
	}
601675
protected function checkIfFileNameIsSafe(string $fileName)
    {
        $allowedFileNames = $this->getLanguageFiles(true);

        if (!in_array($fileName, $allowedFileNames)) {
            return false;
        }

        return true;
    }
70279
private function loadDirectories($dirPath)
    {
        $locales = new LocaleCollection;

        foreach ($this->filesystem->directories($dirPath) as $path) {
            $excluded = in_array($key = basename($path), $this->excludedFolders);

            if ( ! $excluded) {
                $locales->addOne(
                    new Locale($key, $path, $this->loadLocaleFiles($path))
                );
            }
        }

        return $locales;
    }
281170
public function deleteDir($dirname)
    {
        $result = $this->client->deleteObject([
            'Bucket' => $this->getBucket(),
            'Key'    => $dirname.'/',
        ]);

        return (bool) $result;
    }
1052459
private function getTranslations($directory, $language)
    {
        $contentJson = '';

        $directoryJson = ($language == 'en') ? '/en/' : '/../json/';

        $fileJson = $directory.$directoryJson.$language.'.json';

        if (file_exists($fileJson)) {
            $contentJson = json_decode(file_get_contents($fileJson), true);
        }

        return [
            'json'       => $contentJson,
            'auth'       => include($directory.'/'.$language.'/auth.php'),
            'pagination' => include($directory.'/'.$language.'/pagination.php'),
            'passwords'  => include($directory.'/'.$language.'/passwords.php'),
            'validation' => include($directory.'/'.$language.'/validation.php'),
        ];
    }
258434
public function ensureDirectory($dirname)
	{
		if (!empty($dirname) && !$this->exists($dirname))
		{
			$this->makeDirectory($dirname);
		}
	}
1000720
protected function doCreateDir($dirname)
	{
		if ($this->hasDirectory($dirname)) {
			return true;
		}

		if ($this->hasFile($dirname)) {
			return false;
		}

		// Make sure all the sub-directories exist.
		if (!$this->doCreateDir(Util::dirname($dirname))) {
			return false;
		}

		$this->storage[$dirname]['type'] = 'dir';

		return true;
	}
1280965
protected function createDirectory($dirPath)
    {
        // $fullPath = $this->app->config()['paths']['root']->expand($dirPath);
        
        if (!is_dir($dirPath)) {
            $this->output->writeln(sprintf(
                "<info>create  <cyan>%s</cyan></info>",
                $this->prettyPath($dirPath)
            ));
            mkdir($dirPath, 0775, true);
        }
    }