@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+54 -2
+1 -1
src/applications/people/storage/PhabricatorUser.php
··· 572 572 return $this; 573 573 } 574 574 575 - public function getSex() { 575 + public function getGender() { 576 576 return $this->getUserSetting(PhabricatorPronounSetting::SETTINGKEY); 577 577 } 578 578
+53 -1
src/infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php
··· 175 175 try { 176 176 $string_value = $string_node->evalStatic(); 177 177 178 + $args = $params->getChildren(); 179 + $args = array_slice($args, 1); 180 + 181 + $types = array(); 182 + foreach ($args as $child) { 183 + $type = null; 184 + 185 + switch ($child->getTypeName()) { 186 + case 'n_FUNCTION_CALL': 187 + $call = $child->getChildByIndex(0); 188 + if ($call->getTypeName() == 'n_SYMBOL_NAME') { 189 + switch ($call->getConcreteString()) { 190 + case 'phutil_count': 191 + $type = 'number'; 192 + break; 193 + case 'phutil_person': 194 + $type = 'person'; 195 + break; 196 + } 197 + } 198 + break; 199 + case 'n_NEW': 200 + $class = $child->getChildByIndex(0); 201 + if ($class->getTypeName() == 'n_CLASS_NAME') { 202 + switch ($class->getConcreteString()) { 203 + case 'PhutilNumber': 204 + $type = 'number'; 205 + break; 206 + } 207 + } 208 + break; 209 + default: 210 + break; 211 + } 212 + 213 + $types[] = $type; 214 + } 215 + 178 216 $results[$hash][] = array( 179 217 'string' => $string_value, 180 218 'file' => Filesystem::readablePath($full_path, $root_path), 181 219 'line' => $string_line, 220 + 'types' => $types, 182 221 ); 183 222 } catch (Exception $ex) { 184 223 $messages[] = pht( ··· 207 246 $map = array(); 208 247 foreach ($strings as $hash => $string_list) { 209 248 foreach ($string_list as $string_info) { 210 - $map[$string_info['string']]['uses'][] = array( 249 + $string = $string_info['string']; 250 + 251 + $map[$string]['uses'][] = array( 211 252 'file' => $string_info['file'], 212 253 'line' => $string_info['line'], 213 254 ); 255 + 256 + if (!isset($map[$string]['types'])) { 257 + $map[$string]['types'] = $string_info['types']; 258 + } else if ($map[$string]['types'] !== $string_info['types']) { 259 + echo tsprintf( 260 + "**<bg:yellow> %s </bg>** %s\n", 261 + pht('WARNING'), 262 + pht( 263 + 'Inferred types for string "%s" vary across callsites.', 264 + $string_info['string'])); 265 + } 214 266 } 215 267 } 216 268