Differential D16823 Diff 40511 src/infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php
| Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | foreach ($futures as $full_path => $future) { | ||||
| } | } | ||||
| $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(); | ||||
| $args = $params->getChildren(); | |||||
| $args = array_slice($args, 1); | |||||
| $types = array(); | |||||
| foreach ($args as $child) { | |||||
| $type = null; | |||||
| switch ($child->getTypeName()) { | |||||
| case 'n_FUNCTION_CALL': | |||||
| $call = $child->getChildByIndex(0); | |||||
| if ($call->getTypeName() == 'n_SYMBOL_NAME') { | |||||
| switch ($call->getConcreteString()) { | |||||
| case 'phutil_count': | |||||
| $type = 'number'; | |||||
| break; | |||||
| case 'phutil_person': | |||||
| $type = 'person'; | |||||
| break; | |||||
| } | |||||
| } | |||||
| break; | |||||
| case 'n_NEW': | |||||
| $class = $child->getChildByIndex(0); | |||||
| if ($class->getTypeName() == 'n_CLASS_NAME') { | |||||
| switch ($class->getConcreteString()) { | |||||
| case 'PhutilNumber': | |||||
| $type = 'number'; | |||||
| break; | |||||
| } | |||||
| } | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| $types[] = $type; | |||||
| } | |||||
| $results[$hash][] = array( | $results[$hash][] = array( | ||||
| 'string' => $string_value, | 'string' => $string_value, | ||||
| 'file' => Filesystem::readablePath($full_path, $root_path), | 'file' => Filesystem::readablePath($full_path, $root_path), | ||||
| 'line' => $string_line, | 'line' => $string_line, | ||||
| 'types' => $types, | |||||
| ); | ); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $messages[] = pht( | $messages[] = pht( | ||||
| 'WARNING: Failed to evaluate pht() call on line %d in "%s": %s', | 'WARNING: Failed to evaluate pht() call on line %d in "%s": %s', | ||||
| $call->getLineNumber(), | $call->getLineNumber(), | ||||
| $full_path, | $full_path, | ||||
| $ex->getMessage()); | $ex->getMessage()); | ||||
| } | } | ||||
| Show All 12 Lines | private function extractFiles($root_path, array $files) { | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| private function writeStrings($root, array $strings) { | private function writeStrings($root, array $strings) { | ||||
| $map = array(); | $map = array(); | ||||
| foreach ($strings as $hash => $string_list) { | foreach ($strings as $hash => $string_list) { | ||||
| foreach ($string_list as $string_info) { | foreach ($string_list as $string_info) { | ||||
| $map[$string_info['string']]['uses'][] = array( | $string = $string_info['string']; | ||||
| $map[$string]['uses'][] = array( | |||||
| 'file' => $string_info['file'], | 'file' => $string_info['file'], | ||||
| 'line' => $string_info['line'], | 'line' => $string_info['line'], | ||||
| ); | ); | ||||
| if (!isset($map[$string]['types'])) { | |||||
| $map[$string]['types'] = $string_info['types']; | |||||
| } else if ($map[$string]['types'] !== $string_info['types']) { | |||||
| echo tsprintf( | |||||
| "**<bg:yellow> %s </bg>** %s\n", | |||||
| pht('WARNING'), | |||||
| pht( | |||||
| 'Inferred types for string "%s" vary across callsites.', | |||||
| $string_info['string'])); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| ksort($map); | ksort($map); | ||||
| $json = id(new PhutilJSON())->encodeFormatted($map); | $json = id(new PhutilJSON())->encodeFormatted($map); | ||||
| $this->writeCache($root, 'i18n_strings.json', $json); | $this->writeCache($root, 'i18n_strings.json', $json); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines | |||||