function _potx_load_yaml_translation_patterns in Translation template extractor 8
Same name and namespace in other branches
- 6.3 potx.inc \_potx_load_yaml_translation_patterns()
- 7.3 potx.inc \_potx_load_yaml_translation_patterns()
- 7.2 potx.inc \_potx_load_yaml_translation_patterns()
Load the list of YAML translation patterns from a file.
The file is expected to be in the following format:
# A list of file matching patterns (as expected by fnmatch()).
- matches: *.test_format.yml:
# A sequence of translatable keys in the matched YAML files.
translatable_keys:
# Using the shorthand form
- test_label
# Using the long form
- key: test_label_2
# An optional key, used as context for the translatable string.
context: label_2_context
# To mark all top-level keys as translatable,
# use the 'top_level_translatables' setting (optional; default: FALSE).
top_level_translatables: TRUE
Parameters
string $path: The path for the YAML translation patterns file.
1 call to _potx_load_yaml_translation_patterns()
- _potx_init_yaml_translation_patterns in ./
potx.inc - Initialize the list of translation patterns for YAML files.
File
- ./
potx.inc, line 2306 - Extraction API used by the web and command line interface.
Code
function _potx_load_yaml_translation_patterns($path) {
global $_potx_yaml_translation_patterns;
$content = _potx_parse_yaml($path);
if ($content === NULL) {
return;
}
if (isset($content['translation_patterns'])) {
$patterns = $content['translation_patterns'];
foreach ($patterns as $pattern) {
if (!isset($pattern['matches']) || !isset($pattern['translatable_keys'])) {
continue;
}
$match = $pattern['matches'];
$list = $pattern['translatable_keys'];
foreach ($list as $item) {
if (is_array($item)) {
$_potx_yaml_translation_patterns[$match]['keys'][] = $item['key'];
$_potx_yaml_translation_patterns[$match]['contexts'][$item['key']] = isset($item['context']) ? $item['context'] : NULL;
$_potx_yaml_translation_patterns[$match]['array_translatables'][$item['key']] = isset($item['array_translatables']) ? $item['array_translatables'] : FALSE;
}
else {
$_potx_yaml_translation_patterns[$match]['keys'][] = $item;
}
}
$_potx_yaml_translation_patterns[$match]['top_level_translatables'] = isset($pattern['top_level_translatables']) ? $pattern['top_level_translatables'] : FALSE;
}
}
}