X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FConsole%2FExtract.php;h=e7c751f94264159a47ce96cb4943978cafa9c94e;hb=3aa77685fcccff9739384136b4894de43200fa8c;hp=e6cab0654a72c23f8a95e0f80e27657ae9119b04;hpb=4d8d5ca6a58af9aa98cd7f6ca38da5176c621f0d;p=friendica.git diff --git a/src/Core/Console/Extract.php b/src/Core/Console/Extract.php index e6cab0654a..e7c751f942 100644 --- a/src/Core/Console/Extract.php +++ b/src/Core/Console/Extract.php @@ -1,140 +1,140 @@ - - */ -class Extract extends \Asika\SimpleConsole\Console -{ - protected $helpOptions = ['h', 'help', '?']; - - protected function getHelp() - { - $help = <<getOption('v')) { - $this->out('Class: ' . __CLASS__); - $this->out('Arguments: ' . var_export($this->args, true)); - $this->out('Options: ' . var_export($this->options, true)); - } - - if (count($this->args) > 0) { - throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); - } - - $s = 'globRecursive('src') - ); - - foreach ($files as $file) { - $str = file_get_contents($file); - - $pat = '|L10n::t\(([^\)]*+)[\)]|'; - $patt = '|L10n::tt\(([^\)]*+)[\)]|'; - - $matches = []; - $matchestt = []; - - preg_match_all($pat, $str, $matches); - preg_match_all($patt, $str, $matchestt); - - if (count($matches) || count($matchestt)) { - $s .= '// ' . $file . PHP_EOL; - } - - if (!empty($matches[1])) { - foreach ($matches[1] as $long_match) { - $match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match); - $match = $match_arr[0]; - if (!in_array($match, $arr)) { - if (substr($match, 0, 1) == '$') { - continue; - } - - $arr[] = $match; - - $s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n"; - } - } - } - if (!empty($matchestt[1])) { - foreach ($matchestt[1] as $match) { - $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match); - if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) { - if (substr($matchtkns[1], 0, 1) == '$') { - continue; - } - - $arr[] = $matchtkns[0]; - - $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n"; - $s .= "\t0 => " . $matchtkns[0] . ",\n"; - $s .= "\t1 => " . $matchtkns[1] . ",\n"; - $s .= ");\n"; - } - } - } - } - - $s .= '// Timezones' . PHP_EOL; - - $zones = timezone_identifiers_list(); - foreach ($zones as $zone) { - $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n"; - } - - $this->out($s); - - return 0; - } - - private function globRecursive($path) { - $dir_iterator = new \RecursiveDirectoryIterator($path); - $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST); - - $return = []; - foreach ($iterator as $file) { - if ($file->getBasename() != '.' && $file->getBasename() != '..') { - $return[] = $file->getPathname(); - } - } - - return $return; - } -} + + */ +class Extract extends \Asika\SimpleConsole\Console +{ + protected $helpOptions = ['h', 'help', '?']; + + protected function getHelp() + { + $help = <<getOption('v')) { + $this->out('Class: ' . __CLASS__); + $this->out('Arguments: ' . var_export($this->args, true)); + $this->out('Options: ' . var_export($this->options, true)); + } + + if (count($this->args) > 0) { + throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); + } + + $s = 'globRecursive('src') + ); + + foreach ($files as $file) { + $str = file_get_contents($file); + + $pat = '|L10n::t\(([^\)]*+)[\)]|'; + $patt = '|L10n::tt\(([^\)]*+)[\)]|'; + + $matches = []; + $matchestt = []; + + preg_match_all($pat, $str, $matches); + preg_match_all($patt, $str, $matchestt); + + if (count($matches) || count($matchestt)) { + $s .= '// ' . $file . PHP_EOL; + } + + if (!empty($matches[1])) { + foreach ($matches[1] as $long_match) { + $match_arr = preg_split('/(?<=[\'"])\s*,/', $long_match); + $match = $match_arr[0]; + if (!in_array($match, $arr)) { + if (substr($match, 0, 1) == '$') { + continue; + } + + $arr[] = $match; + + $s .= '$a->strings[' . $match . '] = ' . $match . ';' . "\n"; + } + } + } + if (!empty($matchestt[1])) { + foreach ($matchestt[1] as $match) { + $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|", $match); + if (count($matchtkns) == 3 && !in_array($matchtkns[0], $arr)) { + if (substr($matchtkns[1], 0, 1) == '$') { + continue; + } + + $arr[] = $matchtkns[0]; + + $s .= '$a->strings[' . $matchtkns[0] . "] = array(\n"; + $s .= "\t0 => " . $matchtkns[0] . ",\n"; + $s .= "\t1 => " . $matchtkns[1] . ",\n"; + $s .= ");\n"; + } + } + } + } + + $s .= '// Timezones' . PHP_EOL; + + $zones = timezone_identifiers_list(); + foreach ($zones as $zone) { + $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n"; + } + + $this->out($s); + + return 0; + } + + private function globRecursive($path) { + $dir_iterator = new \RecursiveDirectoryIterator($path); + $iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST); + + $return = []; + foreach ($iterator as $file) { + if ($file->getBasename() != '.' && $file->getBasename() != '..') { + $return[] = $file->getPathname(); + } + } + + return $return; + } +}