You are here

function _potx_load_yaml_translation_patterns in Translation template extractor 7.3

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

Code

function _potx_load_yaml_translation_patterns($path) {
  global $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)) {
          $yaml_translation_patterns[$match]['keys'][] = $item['key'];
          $yaml_translation_patterns[$match]['contexts'][$item['key']] = isset($item['context']) ? $item['context'] : NULL;
          $yaml_translation_patterns[$match]['array_translatables'][$item['key']] = isset($item['array_translatables']) ? $item['array_translatables'] : FALSE;
        }
        else {
          $yaml_translation_patterns[$match]['keys'][] = $item;
        }
      }
      $yaml_translation_patterns[$match]['top_level_translatables'] = isset($pattern['top_level_translatables']) ? $pattern['top_level_translatables'] : FALSE;
    }
  }
}