You are here

function i18n_node_tokens in Internationalization 7

Implements hook_tokens().

File

i18n_node/i18n_node.tokens.inc, line 31
Builds placeholder replacement tokens for content types.

Code

function i18n_node_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']) ? TRUE : FALSE;
  $langcode = isset($options['language']) ? $options['language']->language : i18n_langcode();
  if ($type == 'content-type' && !empty($data['node_type'])) {
    $node_type = $data['node_type'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'i18n-name':
          $name = array(
            'node',
            'type',
            $node_type->type,
            'name',
          );
          $options = array(
            'sanitize' => $sanitize,
            'langcode' => $langcode,
          );
          $name = i18n_string_translate($name, $node_type->name, $options);
          $replacements[$original] = $name;
          break;
        case 'i18n-description':
          $description = array(
            'node',
            'type',
            $node_type->type,
            'description',
          );
          $options = array(
            'sanitize' => $sanitize,
            'langcode' => $langcode,
          );
          $description = i18n_string_translate($description, $node_type->description, $options);
          $replacements[$original] = $description;
          break;
      }
    }
  }
  return $replacements;
}