mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Extract variable type information from pht() calls
Summary: Ref T5267. When extrating data from `pht()` calls, also extract the argument types and export them into the map so they can be used by consumers. We recognize plurals (`phutil_count()`, `new PhutilNumber`) and genders (`phutil_person()`). We'll need to annotate the codebase for those, since they're currently runtime-only. Test Plan: Rebuilt extraction maps, got data like this (note "number" type annotation). ``` "Scaling pool \"%s\" up to %s daemon(s).": { "uses": [ { "file": "/daemon/PhutilDaemonOverseer.php", "line": 378 } ], "types": [ null, "number" ] }, ``` Reviewers: chad Reviewed By: chad Maniphest Tasks: T5267 Differential Revision: https://secure.phabricator.com/D16823
This commit is contained in:
parent
3f5109b668
commit
9803674525
2 changed files with 54 additions and 2 deletions
|
@ -572,7 +572,7 @@ final class PhabricatorUser
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getSex() {
|
||||
public function getGender() {
|
||||
return $this->getUserSetting(PhabricatorPronounSetting::SETTINGKEY);
|
||||
}
|
||||
|
||||
|
|
|
@ -175,10 +175,49 @@ final class PhabricatorInternationalizationManagementExtractWorkflow
|
|||
try {
|
||||
$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(
|
||||
'string' => $string_value,
|
||||
'file' => Filesystem::readablePath($full_path, $root_path),
|
||||
'line' => $string_line,
|
||||
'types' => $types,
|
||||
);
|
||||
} catch (Exception $ex) {
|
||||
$messages[] = pht(
|
||||
|
@ -207,10 +246,23 @@ final class PhabricatorInternationalizationManagementExtractWorkflow
|
|||
$map = array();
|
||||
foreach ($strings as $hash => $string_list) {
|
||||
foreach ($string_list as $string_info) {
|
||||
$map[$string_info['string']]['uses'][] = array(
|
||||
$string = $string_info['string'];
|
||||
|
||||
$map[$string]['uses'][] = array(
|
||||
'file' => $string_info['file'],
|
||||
'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']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue