function _potx_find_constraint_messages in Translation template extractor 8
Same name and namespace in other branches
- 6.3 potx.inc \_potx_find_constraint_messages()
- 7.3 potx.inc \_potx_find_constraint_messages()
- 7.2 potx.inc \_potx_find_constraint_messages()
Detect validation constraint messages. Drupal 8+.
This sequences is searched for: T_POTX_CONSTRAINT = T_CONSTANT_ENCAPSED_STRING.
note: T_POTX_CONSTRAINT is marked for T_VARIABLE tokens inside .php files with the "Constraint" suffix, where the token is "$message", or ends with "Message"
Parameters
string $file_name: Name of file parsed.
string $save_callback: Callback function used to save strings.
1 call to _potx_find_constraint_messages()
- _potx_parse_php_file in ./
potx.inc - Parse a PHP file for translatables.
File
- ./
potx.inc, line 3128 - Extraction API used by the web and command line interface.
Code
function _potx_find_constraint_messages($file_name, $save_callback) {
global $_potx_tokens, $_potx_lookup;
if (!isset($_potx_lookup['T_POTX_CONSTRAINT'])) {
return;
}
foreach ($_potx_lookup['T_POTX_CONSTRAINT'] as $key => $ti) {
if ($_potx_tokens[$ti + 1] == '=' && $_potx_tokens[$ti + 2][0] == T_CONSTANT_ENCAPSED_STRING) {
$str = $_potx_tokens[$ti + 2][1];
// Find plural versions if available.
if (strpos($str, '|') !== FALSE) {
$quo = substr($str, 0, 1);
$break = strpos($str, '|');
$singular = substr($str, 0, $break) . $quo;
$plural = $quo . substr($str, $break + 1);
$save_callback(_potx_format_quoted_string($singular) . "\0" . _potx_format_quoted_string($plural), POTX_CONTEXT_NONE, $file_name, $_potx_tokens[$ti][2]);
}
else {
$save_callback(_potx_format_quoted_string($str), POTX_CONTEXT_NONE, $file_name, $_potx_tokens[$ti][2]);
}
}
}
}