You are here

function _potx_find_shipped_config_translatables in Translation template extractor 6.3

Same name and namespace in other branches
  1. 8 potx.inc \_potx_find_shipped_config_translatables()
  2. 7.3 potx.inc \_potx_find_shipped_config_translatables()
  3. 7.2 potx.inc \_potx_find_shipped_config_translatables()

Recursively check elements in shipped configuration with the processed schema.

To support complex cases of variable replacement, '%key' and '%parent' indexes are defined for every element when available. 'key' and 'parent' values are also passed through the function parameters, because $config might be a scalar value, which would not accept an index. Parsing an element's properties inherited from its 'type' are processed separately from the properties defined through its 'mapping'.

Parameters

mixed $config: The config element being processed.

string $schema_prefix: All parent keys (including the element's key) joined by '+' symbol.

string $config_key: The config element's key.

array $config_parent: The config element's parent.

1 call to _potx_find_shipped_config_translatables()
_potx_parse_shipped_configuration in ./potx.inc
Parse shipped configuration for translatables. Drupal 8+

File

./potx.inc, line 2418
Extraction API used by the web and command line interface.

Code

function _potx_find_shipped_config_translatables($config, $schema_prefix, $config_key, $config_parent, $config_path, $save_callback) {
  global $_potx_processed_schema;
  if (in_array($schema_prefix, $_potx_processed_schema['translatables'])) {
    if (isset($_potx_processed_schema['contexts'][$schema_prefix])) {
      $context = $_potx_processed_schema['contexts'][$schema_prefix];
    }
    else {
      $context = POTX_CONTEXT_NONE;
    }
    $save_callback(addcslashes($config, "\0..\37\\\""), $context, $config_path);
  }
  else {

    // Resolve the config element's type in schema to a real type, replacing all
    // placeholders, and find the shipped config translatables based on that
    // type.
    if (isset($_potx_processed_schema['types'][$schema_prefix])) {
      $schema_type = $_potx_processed_schema['types'][$schema_prefix];
      if ($schema_type == 'sequence') {
        foreach ($config as $sequence_key => $sequence_item) {

          // '%key' and '%parent' keys are added to $config by potx. skip them.
          if ($sequence_key === '%parent' || $sequence_key === '%key') {
            continue;
          }
          if (is_array($sequence_item)) {
            $sequence_item['%key'] = $sequence_key;
            $sequence_type = _potx_config_replace_name($schema_prefix, $sequence_item);
          }
          else {
            $sequence_type = _potx_config_replace_name($schema_prefix, array(
              '%key' => $sequence_key,
            ));
          }
          _potx_find_shipped_config_translatables($sequence_item, $sequence_type . '+sequence', $sequence_key, NULL, $config_path, $save_callback);
        }
      }
      else {
        if (is_array($config)) {
          $schema_type = _potx_config_replace_name($schema_type, $config);
        }
        else {
          $schema_type = _potx_config_replace_name($schema_type, array(
            '%key' => $config_key,
            '%parent' => $config_parent,
          ));
        }
        $matching_schema = _potx_find_matching_schema($schema_type);
        _potx_find_shipped_config_translatables($config, $matching_schema, $config_key, $config_parent, $config_path, $save_callback);
      }
    }

    // Check the keys belonging to config element's schema's "mapping" key.
    if (in_array($schema_prefix, $_potx_processed_schema['mappings'])) {
      foreach ($config as $key => $element) {

        // '%key' and '%parent' keys are added to $config by potx. skip them.
        if ($key === '%parent' || $key === '%key' || empty($element)) {
          continue;
        }
        if (!_potx_element_has_schema($schema_prefix . '+' . $key)) {
          continue;
        }
        if (is_array($element)) {
          $element['%parent'] = $config;
          $element['%key'] = $key;
        }
        _potx_find_shipped_config_translatables($element, $schema_prefix . '+' . $key, $key, $config, $config_path, $save_callback);
      }
    }
  }
}