You are here

function _potx_find_yaml_translatables in Translation template extractor 8

Same name and namespace in other branches
  1. 6.3 potx.inc \_potx_find_yaml_translatables()
  2. 7.3 potx.inc \_potx_find_yaml_translatables()
  3. 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.

string $file_name: Name of the file parsed.

string $save_callback: Callback function used to save strings.

bool $top_level: Indicates that the top-level keys are being scanned.

bool $extract_array: Set to TRUE to cause all array keys' values to be treated as translatable at this level of the YAML.

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

Code

function _potx_find_yaml_translatables(array $yaml, array $trans_list, $file_name, $save_callback, $top_level = FALSE, $extract_array = FALSE) {
  $extract_all = $top_level && $trans_list['top_level_translatables'] || $extract_array;
  foreach ($yaml as $key => $value) {
    if (is_array($value)) {

      // If the value is an array, we need to recurse, and possibly treat all
      // the next-level array keys as translatable.
      $extract_sub = isset($trans_list['array_translatables'][$key]) && $trans_list['array_translatables'][$key];
      _potx_find_yaml_translatables($value, $trans_list, $file_name, $save_callback, FALSE, $extract_sub);
    }
    elseif (in_array($key, $trans_list['keys'], TRUE) || $extract_all) {
      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;
      }
      $save_callback(addcslashes($value, "\0..\37\\\""), $context, $file_name);
    }
  }
}