rules_i18n.i18n.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization integration based upon the entity API i18n stuff.
  5. */
  6. /**
  7. * Rules i18n integration controller.
  8. */
  9. class RulesI18nStringController extends EntityDefaultI18nStringController {
  10. /**
  11. * Overridden to customize i18n object info.
  12. *
  13. * @see EntityDefaultI18nStringController::hook_object_info()
  14. */
  15. public function hook_object_info() {
  16. $info = parent::hook_object_info();
  17. $info['rules_config']['class'] = 'RulesI18nStringObjectWrapper';
  18. return $info;
  19. }
  20. /**
  21. * Overridden to customize the used menu wildcard.
  22. */
  23. protected function menuWildcard() {
  24. return '%rules_config';
  25. }
  26. /**
  27. * Provide the menu base path. We can provide only one though.
  28. */
  29. protected function menuBasePath() {
  30. return 'admin/config/workflow/rules/reaction';
  31. }
  32. }
  33. /**
  34. * Custom I18n String object wrapper, which register custom properties per config.
  35. */
  36. class RulesI18nStringObjectWrapper extends i18n_string_object_wrapper {
  37. /**
  38. * Get translatable properties.
  39. */
  40. protected function build_properties() {
  41. $strings = parent::build_properties();
  42. $properties = array();
  43. // Also add in the configuration label, as the i18n String UI requires
  44. // a String to be available always.
  45. $properties['label'] = array(
  46. 'title' => t('Configuration name'),
  47. 'string' => $this->object->label,
  48. );
  49. $this->buildElementProperties($this->object, $properties);
  50. // Add in translations for all elements.
  51. foreach ($this->object->elements() as $element) {
  52. $this->buildElementProperties($element, $properties);
  53. }
  54. $strings[$this->get_textgroup()]['rules_config'][$this->object->name] = $properties;
  55. return $strings;
  56. }
  57. /**
  58. * Adds in translatable properties of the given element.
  59. */
  60. protected function buildElementProperties($element, &$properties) {
  61. foreach ($element->pluginParameterInfo() as $name => $info) {
  62. // Add in all directly provided input variables.
  63. if (!empty($info['translatable']) && isset($element->settings[$name])) {
  64. // If its an array of textual values, translate each value on its own.
  65. if (is_array($element->settings[$name])) {
  66. foreach ($element->settings[$name] as $i => $value) {
  67. $properties[$element->elementId() . ':' . $name . ':' . $i] = array(
  68. 'title' => t('@plugin "@label" (id @id), @parameter, Value @delta', array('@plugin' => drupal_ucfirst($element->plugin()), '@label' => $element->label(), '@id' => $element->elementId(), '@parameter' => $info['label'], '@delta' => $i + 1)),
  69. 'string' => $value,
  70. );
  71. }
  72. }
  73. else {
  74. $properties[$element->elementId() . ':' . $name] = array(
  75. 'title' => t('@plugin "@label" (id @id), @parameter', array('@plugin' => drupal_ucfirst($element->plugin()), '@label' => $element->label(), '@id' => $element->elementId(), '@parameter' => $info['label'])),
  76. 'string' => $element->settings[$name],
  77. );
  78. }
  79. }
  80. }
  81. }
  82. }