function _potx_find_yaml_translatables in Translation template extractor 6.3
Same name and namespace in other branches
- 8 potx.inc \_potx_find_yaml_translatables()
- 7.3 potx.inc \_potx_find_yaml_translatables()
- 7.2 potx.inc \_potx_find_yaml_translatables()
Recursively look for translatable strings in a YAML file.
Parameters
array $yaml: The parsed YAML data.
array $trans_list: The list of translatable keys to look for, and (optionally) their contexts.
1 call to _potx_find_yaml_translatables()
- _potx_parse_yaml_file in ./
potx.inc - Parse a YAML file for translatables. Drupal 8+.
File
- ./
potx.inc, line 2046 - Extraction API used by the web and command line interface.
Code
function _potx_find_yaml_translatables($yaml, $trans_list, $file_name, $save_callback) {
$extract_values = $trans_list['top_level_translatables'];
foreach ($yaml as $key => $value) {
if (in_array($key, $trans_list['keys'], TRUE)) {
if (isset($trans_list['contexts'][$key])) {
$context_key = $trans_list['contexts'][$key];
if (isset($yaml[$context_key])) {
$context = $yaml[$context_key];
}
else {
$context = POTX_CONTEXT_NONE;
}
}
else {
$context = POTX_CONTEXT_NONE;
}
if (is_array($value)) {
foreach ($value as $item) {
$save_callback(addcslashes($item, "\0..\37\\\""), $context, $file_name);
}
}
else {
$save_callback(addcslashes($value, "\0..\37\\\""), $context, $file_name);
}
}
elseif (is_array($value)) {
_potx_find_yaml_translatables($value, $trans_list, $file_name, $save_callback);
}
elseif ($extract_values) {
$save_callback(addcslashes($value, "\0..\37\\\""), POTX_CONTEXT_NONE, $file_name);
}
}
}