X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FConsole%2FExtract.php;h=1f84d442b5031d69f929c9d00a428eadb157f9d6;hb=d4a5a8051ad34a7be72238967afb3e6b140afdc8;hp=7fac598fe9b2d1dfd2b124c1642f3d68bfc3a161;hpb=d716a3326f4e7846e19ec2454054f6d20a71507a;p=friendica.git diff --git a/src/Console/Extract.php b/src/Console/Extract.php index 7fac598fe9..1f84d442b5 100644 --- a/src/Console/Extract.php +++ b/src/Console/Extract.php @@ -1,14 +1,34 @@ . + * + */ namespace Friendica\Console; +use \RecursiveDirectoryIterator; +use \RecursiveIteratorIterator; + /** * Extracts translation strings from the Friendica project's files to be exported * to Transifex for translation. * * Outputs a PHP file with language strings used by Friendica - * - * @author Hypolite Petovan */ class Extract extends \Asika\SimpleConsole\Console { @@ -32,7 +52,7 @@ HELP; return $help; } - protected function doExecute() + protected function doExecute(): int { if ($this->getOption('v')) { $this->out('Class: ' . __CLASS__); @@ -55,9 +75,8 @@ HELP; $arr = []; $files = array_merge( - ['index.php', 'boot.php'], + ['index.php'], glob('mod/*'), - glob('include/*'), glob('addon/*/*'), $this->globRecursive('src') ); @@ -65,8 +84,8 @@ HELP; foreach ($files as $file) { $str = file_get_contents($file); - $pat = '|L10n::t\(([^\)]*+)[\)]|'; - $patt = '|L10n::tt\(([^\)]*+)[\)]|'; + $pat = '|->t\(([^\)]*+)[\)]|'; + $patt = '|->tt\(([^\)]*+)[\)]|'; $matches = []; $matchestt = []; @@ -103,10 +122,10 @@ HELP; $arr[] = $matchtkns[0]; - $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n"; + $s .= '$a->strings[' . $matchtkns[0] . "] = [\n"; $s .= "\t0 => " . $matchtkns[0] . ",\n"; $s .= "\t1 => " . $matchtkns[1] . ",\n"; - $s .= ");\n"; + $s .= "];\n"; } } } @@ -124,9 +143,17 @@ HELP; return 0; } - private function globRecursive($path) { - $dir_iterator = new \RecursiveDirectoryIterator($path); - $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST); + /** + * Returns an array with found files and directories including their paths. + * + * @param string $path Base path to scan + * + * @return array A flat array with found files and directories + */ + private function globRecursive(string $path): array + { + $dir_iterator = new RecursiveDirectoryIterator($path); + $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); $return = []; foreach ($iterator as $file) {