From 3e7f683533f3ee393a3899b632be480d3884d727 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 24 Jan 2018 16:53:57 -0500 Subject: [PATCH] Fix util/extract.php - Captures way more L10n::t(t) instances - Add recursive search into `src/` folder - Fix string capture with new sprintf-free syntax --- util/extract.php | 119 +++++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 41 deletions(-) mode change 100644 => 100755 util/extract.php diff --git a/util/extract.php b/util/extract.php old mode 100644 new mode 100755 index 13151bc96f..18fbb9df00 --- a/util/extract.php +++ b/util/extract.php @@ -1,63 +1,100 @@ +#!/usr/bin/env php strings[' . $match . '] = ' . $match . ';' . "\n"; } } - if(count($matchestt)){ - foreach($matchestt[1] as $match) { - $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|",$match); - if (count($matchtkns)==3 && !in_array($matchtkns,$arr)){ - $arr[] = $matchtkns; + } + if (count($matchestt)) { + 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 = 'strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n"; } -'; +echo $s; + +function glob_recursive($path) { + $dir_iterator = new RecursiveDirectoryIterator($path); + $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); - foreach($arr as $a) { - if (is_array($a)){ - if(substr($a[1],0,1) == '$') - continue; - $s .= '$a->strings[' . $a[0] . "] = array(\n"; - $s .= "\t0 => ". $a[0]. ",\n"; - $s .= "\t1 => ". $a[1]. ",\n"; - $s .= ");\n"; - } else { - if(substr($a,0,1) == '$') - continue; - $s .= '$a->strings[' . $a . '] = '. $a . ';' . "\n"; + $return = []; + foreach ($iterator as $file) { + if ($file->getBasename() != '.' && $file->getBasename() != '..') { + $return[] = $file->getPathname(); } } - $zones = timezone_identifiers_list(); - foreach($zones as $zone) - $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n"; - - echo $s; \ No newline at end of file + return $return; +} -- 2.39.5