i18n_node.tokens.inc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Builds placeholder replacement tokens for content types.
  5. */
  6. /**
  7. * Implements hook_token_info().
  8. */
  9. function i18n_node_token_info() {
  10. $content_type['i18n-name'] = array(
  11. 'name' => t("Name (localized)"),
  12. 'description' => t("The name of the content type."),
  13. );
  14. $content_type['i18n-description'] = array(
  15. 'name' => t("Description (localized)"),
  16. 'description' => t("The optional description of the content type."),
  17. );
  18. return array(
  19. 'tokens' => array(
  20. 'content-type' => $content_type,
  21. ),
  22. );
  23. }
  24. /**
  25. * Implements hook_tokens().
  26. */
  27. function i18n_node_tokens($type, $tokens, array $data = array(), array $options = array()) {
  28. $replacements = array();
  29. $sanitize = !empty($options['sanitize']) ? TRUE : FALSE;
  30. $langcode = isset($options['language']) ? $options['language']->language : i18n_langcode();
  31. if ($type == 'content-type' && !empty($data['node_type'])) {
  32. $node_type = $data['node_type'];
  33. foreach ($tokens as $name => $original) {
  34. switch ($name) {
  35. case 'i18n-name':
  36. $name = array('node', 'type', $node_type->type, 'name');
  37. $options = array('sanitize' => $sanitize, 'langcode' => $langcode);
  38. $name = i18n_string_translate($name, $node_type->name, $options);
  39. $replacements[$original] = $name;
  40. break;
  41. case 'i18n-description':
  42. $description = array('node', 'type', $node_type->type, 'description');
  43. $options = array('sanitize' => $sanitize, 'langcode' => $langcode);
  44. $description = i18n_string_translate($description, $node_type->description, $options);
  45. $replacements[$original] = $description;
  46. break;
  47. }
  48. }
  49. }
  50. return $replacements;
  51. }