Differential D15983 Diff 38478 src/infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php
Show All 29 Lines | foreach ($paths as $path) { | ||||
foreach ($path_files as $file) { | foreach ($path_files as $file) { | ||||
$full_path = $root.DIRECTORY_SEPARATOR.$file; | $full_path = $root.DIRECTORY_SEPARATOR.$file; | ||||
$data = Filesystem::readFile($full_path); | $data = Filesystem::readFile($full_path); | ||||
$futures[$full_path] = PhutilXHPASTBinary::getParserFuture($data); | $futures[$full_path] = PhutilXHPASTBinary::getParserFuture($data); | ||||
} | } | ||||
} | } | ||||
$console->writeOut( | $console->writeErr( | ||||
"%s\n", | "%s\n", | ||||
pht('Found %s file(s)...', phutil_count($futures))); | pht('Found %s file(s)...', phutil_count($futures))); | ||||
$results = array(); | $results = array(); | ||||
$bar = id(new PhutilConsoleProgressBar()) | $bar = id(new PhutilConsoleProgressBar()) | ||||
->setTotal(count($futures)); | ->setTotal(count($futures)); | ||||
$messages = array(); | |||||
$futures = id(new FutureIterator($futures)) | $futures = id(new FutureIterator($futures)) | ||||
->limit(8); | ->limit(8); | ||||
foreach ($futures as $full_path => $future) { | foreach ($futures as $full_path => $future) { | ||||
$bar->update(1); | $bar->update(1); | ||||
try { | |||||
$tree = XHPASTTree::newFromDataAndResolvedExecFuture( | $tree = XHPASTTree::newFromDataAndResolvedExecFuture( | ||||
Filesystem::readFile($full_path), | Filesystem::readFile($full_path), | ||||
$future->resolve()); | $future->resolve()); | ||||
} catch (Exception $ex) { | |||||
$messages[] = pht( | |||||
'WARNING: Failed to extract strings from file "%s": %s', | |||||
$full_path, | |||||
$ex->getMessage()); | |||||
continue; | |||||
} | |||||
$root = $tree->getRootNode(); | $root = $tree->getRootNode(); | ||||
$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL'); | $calls = $root->selectDescendantsOfType('n_FUNCTION_CALL'); | ||||
foreach ($calls as $call) { | foreach ($calls as $call) { | ||||
$name = $call->getChildByIndex(0)->getConcreteString(); | $name = $call->getChildByIndex(0)->getConcreteString(); | ||||
if ($name == 'pht') { | if ($name == 'pht') { | ||||
$params = $call->getChildByIndex(1, 'n_CALL_PARAMETER_LIST'); | $params = $call->getChildByIndex(1, 'n_CALL_PARAMETER_LIST'); | ||||
$string_node = $params->getChildByIndex(0); | $string_node = $params->getChildByIndex(0); | ||||
$string_line = $string_node->getLineNumber(); | $string_line = $string_node->getLineNumber(); | ||||
try { | try { | ||||
$string_value = $string_node->evalStatic(); | $string_value = $string_node->evalStatic(); | ||||
$results[$string_value][] = array( | $results[$string_value][] = array( | ||||
'file' => Filesystem::readablePath($full_path), | 'file' => Filesystem::readablePath($full_path), | ||||
'line' => $string_line, | 'line' => $string_line, | ||||
); | ); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
// TODO: Deal with this junks. | $messages[] = pht( | ||||
'WARNING: Failed to evaluate pht() call on line %d in "%s": %s', | |||||
$call->getLineNumber(), | |||||
$full_path, | |||||
$ex->getMessage()); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
$tree->dispose(); | $tree->dispose(); | ||||
} | } | ||||
$bar->done(); | $bar->done(); | ||||
foreach ($messages as $message) { | |||||
$console->writeErr("%s\n", $message); | |||||
} | |||||
ksort($results); | ksort($results); | ||||
$out = array(); | $out = array(); | ||||
$out[] = '<?php'; | $out[] = '<?php'; | ||||
$out[] = '// @no'.'lint'; | $out[] = '// @no'.'lint'; | ||||
$out[] = 'return array('; | $out[] = 'return array('; | ||||
foreach ($results as $string => $locations) { | foreach ($results as $string => $locations) { | ||||
foreach ($locations as $location) { | foreach ($locations as $location) { | ||||
Show All 14 Lines |