Projet

Général

Profil

Paste
Télécharger (2,84 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_localization_core.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_localization_core.
6
 */
7

    
8
/**
9
 * Localization plugin to pass translatable strings through t().
10
 *
11
 * @ingroup views_localization_plugins
12
 */
13
class views_plugin_localization_core extends views_plugin_localization {
14

    
15
  /**
16
   * Translate a string.
17
   *
18
   * @param string $string
19
   *   The string to be translated.
20
   * @param array $keys
21
   *   An array of keys to identify the string. Generally constructed from
22
   *   view name, display_id, and a property, e.g., 'header'.
23
   * @param string $format
24
   *   The input format of the string. This is optional.
25
   */
26
  public function translate_string($string, $keys = array(), $format = '') {
27
    return t($string);
28
  }
29

    
30
  /**
31
   * Save a string for translation.
32
   *
33
   * @param string $string
34
   *   The string to be translated.
35
   * @param array $keys
36
   *   An array of keys to identify the string. Generally constructed from
37
   *   view name, display_id, and a property, e.g., 'header'.
38
   * @param string $format
39
   *   The input format of the string. This is optional.
40
   */
41
  public function save_string($string, $keys = array(), $format = '') {
42
    global $language;
43

    
44
    // If the current language is 'en', we need to reset the language
45
    // in order to trigger an update.
46
    // @todo add test for number of languages.
47
    if ($language->language == 'en') {
48
      $changed = TRUE;
49
      $languages = language_list();
50
      $cached_language = $language;
51
      unset($languages['en']);
52
      if (!empty($languages)) {
53
        $language = current($languages);
54
      }
55
    }
56

    
57
    t($string);
58

    
59
    if (isset($cached_language)) {
60
      $language = $cached_language;
61
    }
62
    return TRUE;
63
  }
64

    
65
  /**
66
   * Delete a string.
67
   *
68
   * Deletion is not supported.
69
   *
70
   * @param mixed $source
71
   *   Full data for the string to be translated.
72
   */
73
  public function delete($source) {
74
    return FALSE;
75
  }
76

    
77
  /**
78
   * Collect strings to be exported to code.
79
   *
80
   * String identifiers are not supported so strings are anonymously in an
81
   * array.
82
   *
83
   * @param array $source
84
   *   Full data for the string to be translated.
85
   */
86
  public function export($source) {
87
    if (!empty($source['value'])) {
88
      $this->export_strings[] = $source['value'];
89
    }
90
  }
91

    
92
  /**
93
   * Render any collected exported strings to code.
94
   *
95
   * @param string $indent
96
   *   An optional indentation for prettifying nested code.
97
   */
98
  public function export_render($indent = '  ') {
99
    $output = '';
100
    if (!empty($this->export_strings)) {
101
      $this->export_strings = array_unique($this->export_strings);
102
      $output = $indent . '$translatables[\'' . $this->view->name . '\'] = array(' . "\n";
103
      foreach ($this->export_strings as $string) {
104
        $output .= $indent . "  t('" . str_replace("'", "\'", $string) . "'),\n";
105
      }
106
      $output .= $indent . ");\n";
107
    }
108
    return $output;
109
  }
110

    
111
}