[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorInternationalizationManagementExtractWorkflow 4 extends PhabricatorInternationalizationManagementWorkflow { 5 6 public function didConstruct() { 7 $this 8 ->setName('extract') 9 ->setSynopsis(pht('Extract translatable strings.')) 10 ->setArguments( 11 array( 12 array( 13 'name' => 'paths', 14 'wildcard' => true, 15 ), 16 )); 17 } 18 19 public function execute(PhutilArgumentParser $args) { 20 $console = PhutilConsole::getConsole(); 21 $paths = $args->getArg('paths'); 22 23 $futures = array(); 24 foreach ($paths as $path) { 25 $root = Filesystem::resolvePath($path); 26 $path_files = id(new FileFinder($root)) 27 ->withType('f') 28 ->withSuffix('php') 29 ->find(); 30 31 foreach ($path_files as $file) { 32 $full_path = $root.DIRECTORY_SEPARATOR.$file; 33 $data = Filesystem::readFile($full_path); 34 $futures[$full_path] = xhpast_get_parser_future($data); 35 } 36 } 37 38 $console->writeOut( 39 "%s\n", 40 pht('Found %s file(s)...', new PhutilNumber(count($futures)))); 41 42 $results = array(); 43 44 $bar = id(new PhutilConsoleProgressBar()) 45 ->setTotal(count($futures)); 46 foreach (Futures($futures)->limit(8) as $full_path => $future) { 47 $bar->update(1); 48 49 $tree = XHPASTTree::newFromDataAndResolvedExecFuture( 50 Filesystem::readFile($full_path), 51 $future->resolve()); 52 53 $root = $tree->getRootNode(); 54 $calls = $root->selectDescendantsOfType('n_FUNCTION_CALL'); 55 foreach ($calls as $call) { 56 $name = $call->getChildByIndex(0)->getConcreteString(); 57 if ($name == 'pht') { 58 $params = $call->getChildByIndex(1, 'n_CALL_PARAMETER_LIST'); 59 $string_node = $params->getChildByIndex(0); 60 $string_line = $string_node->getLineNumber(); 61 try { 62 $string_value = $string_node->evalStatic(); 63 64 $results[$string_value][] = array( 65 'file' => Filesystem::readablePath($full_path), 66 'line' => $string_line, 67 ); 68 } catch (Exception $ex) { 69 // TODO: Deal with this junks. 70 } 71 } 72 } 73 74 $tree->dispose(); 75 } 76 $bar->done(); 77 78 ksort($results); 79 80 $out = array(); 81 $out[] = '<?php'; 82 $out[] = '// @nolint'; 83 $out[] = 'return array('; 84 foreach ($results as $string => $locations) { 85 foreach ($locations as $location) { 86 $out[] = ' // '.$location['file'].':'.$location['line']; 87 } 88 $out[] = " '".addcslashes($string, "\0..\37\\'\177..\377")."' => null,"; 89 $out[] = null; 90 } 91 $out[] = ');'; 92 $out[] = null; 93 94 echo implode("\n", $out); 95 96 return 0; 97 } 98 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |