You are here

function _potx_find_shipped_config_translatables in Translation template extractor 8

Same name and namespace in other branches
  1. 6.3 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 config 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.

mixed $config_parent: The config element's parent.

string $file_name: Name of file parsed.

string $save_callback: Callback function used to save strings.

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

Code

function _potx_find_shipped_config_translatables($config, $schema_prefix, $config_key, $config_parent, $file_name, $save_callback) {
  global $_potx_processed_schema;
  if (in_array($schema_prefix, $_potx_processed_schema['translatables']) && is_string($config)) {
    if (isset($_potx_processed_schema['contexts'][$schema_prefix])) {
      $context = $_potx_processed_schema['contexts'][$schema_prefix];
    }
    else {
      $context = POTX_CONTEXT_NONE;
    }
    if (strpos($config, "\3") !== FALSE) {

      // Convert plural formatting from config to plural formatting in our
      // format (replacing \03 with \0).
      list($singular, $plural) = explode("\3", $config);
      $save_callback(addcslashes($singular, "\0..\37\\\"") . "\0" . addcslashes($plural, "\0..\37\\\""), $context, $file_name);
    }
    else {
      $save_callback(addcslashes($config, "\0..\37\\\""), $context, $file_name);
    }
  }
  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, [
              '%key' => $sequence_key,
            ]);
          }
          _potx_find_shipped_config_translatables($sequence_item, $sequence_type . '+sequence', $sequence_key, NULL, $file_name, $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, [
            '%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, $file_name, $save_callback);
      }
    }

    // Check the keys belonging to config element's schema's "mapping" key.
    if (in_array($schema_prefix, $_potx_processed_schema['mappings']) && is_array($config)) {
      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, $file_name, $save_callback);
      }
    }
  }
}