You are here

function _potx_load_yaml_translation_patterns in Translation template extractor 7.2

Same name and namespace in other branches
  1. 8 potx.inc \_potx_load_yaml_translation_patterns()
  2. 6.3 potx.inc \_potx_load_yaml_translation_patterns()
  3. 7.3 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()).
  *.test_format.yml:
    # A sequence of translatable keys in the matched YAML files.
    - test_label
    - 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-key' string.
    - %top-level-key

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 1930
Extraction API used by the web and command line interface.

Code

function _potx_load_yaml_translation_patterns($path) {
  global $yaml_translation_patterns;
  $content = Yaml::parse(file_get_contents($path));
  foreach ($content as $pattern => $list) {
    foreach ($list as $value) {
      if (is_array($value)) {
        foreach ($value as $key => $context) {
          $yaml_translation_patterns[$pattern]['keys'][] = $key;
          $yaml_translation_patterns[$pattern]['contexts'][$key] = $context['context'];
        }
      }
      else {
        $yaml_translation_patterns[$pattern]['keys'][] = $value;
      }
    }
  }
}