Projet

Général

Profil

Paste
Télécharger (3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / rules / rules_i18n / rules_i18n.i18n.inc @ 950416da

1
<?php
2

    
3
/**
4
 * @file
5
 * Internationalization integration based upon the entity API i18n stuff.
6
 */
7

    
8
/**
9
 * Rules i18n integration controller.
10
 */
11
class RulesI18nStringController extends EntityDefaultI18nStringController {
12

    
13
  /**
14
   * Overridden to customize i18n object info.
15
   *
16
   * @see EntityDefaultI18nStringController::hook_object_info()
17
   */
18
  public function hook_object_info() {
19
    $info = parent::hook_object_info();
20
    $info['rules_config']['class'] = 'RulesI18nStringObjectWrapper';
21
    return $info;
22
  }
23

    
24
  /**
25
   * Overridden to customize the used menu wildcard.
26
   */
27
  protected function menuWildcard() {
28
    return '%rules_config';
29
  }
30

    
31
  /**
32
   * Provide the menu base path. We can provide only one though.
33
   */
34
  protected function menuBasePath() {
35
    return 'admin/config/workflow/rules/reaction';
36
  }
37

    
38
}
39

    
40
/**
41
 * Custom I18n String object wrapper, which register custom properties per config.
42
 */
43
class RulesI18nStringObjectWrapper extends i18n_string_object_wrapper {
44

    
45
  /**
46
   * Get translatable properties.
47
   */
48
  protected function build_properties() {
49
    $strings = parent::build_properties();
50
    $properties = array();
51

    
52
    // Also add in the configuration label, as the i18n String UI requires
53
    // a String to be available always.
54
    $properties['label'] = array(
55
      'title' => t('Configuration name'),
56
      'string' => $this->object->label,
57
    );
58

    
59
    $this->buildElementProperties($this->object, $properties);
60

    
61
    // Add in translations for all elements.
62
    foreach ($this->object->elements() as $element) {
63
      $this->buildElementProperties($element, $properties);
64
    }
65
    $strings[$this->get_textgroup()]['rules_config'][$this->object->name] = $properties;
66
    return $strings;
67
  }
68

    
69
  /**
70
   * Adds in translatable properties of the given element.
71
   */
72
  protected function buildElementProperties($element, &$properties) {
73

    
74
    foreach ($element->pluginParameterInfo() as $name => $info) {
75
      // Add in all directly provided input variables.
76
      if (!empty($info['translatable']) && isset($element->settings[$name])) {
77
        // If its an array of textual values, translate each value on its own.
78
        if (is_array($element->settings[$name])) {
79
          foreach ($element->settings[$name] as $i => $value) {
80
            $properties[$element->elementId() . ':' . $name . ':' . $i] = array(
81
              '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)),
82
              'string' => $value,
83
            );
84
          }
85
        }
86
        else {
87
          $properties[$element->elementId() . ':' . $name] = array(
88
            'title' => t('@plugin "@label" (id @id), @parameter', array('@plugin' => drupal_ucfirst($element->plugin()), '@label' => $element->label(), '@id' => $element->elementId(), '@parameter' => $info['label'])),
89
            'string' => $element->settings[$name],
90
          );
91
        }
92
      }
93
    }
94
  }
95

    
96
}