1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Contains the Drupal core localization plugin. |
---|
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 |
---|
19 | * The string to be translated. |
---|
20 | * @param $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 $format |
---|
24 | * The input format of the string. This is optional. |
---|
25 | */ |
---|
26 | function translate_string($string, $keys = array(), $format = '') { |
---|
27 | return t($string); |
---|
28 | } |
---|
29 | |
---|
30 | /** |
---|
31 | * Save a string for translation. |
---|
32 | * |
---|
33 | * @param $string |
---|
34 | * The string to be translated. |
---|
35 | * @param $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 $format |
---|
39 | * The input format of the string. This is optional. |
---|
40 | */ |
---|
41 | 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 $source |
---|
71 | * Full data for the string to be translated. |
---|
72 | */ |
---|
73 | 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 array. |
---|
81 | * |
---|
82 | * @param $source |
---|
83 | * Full data for the string to be translated. |
---|
84 | */ |
---|
85 | function export($source) { |
---|
86 | if (!empty($source['value'])) { |
---|
87 | $this->export_strings[] = $source['value']; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * Render any collected exported strings to code. |
---|
93 | * |
---|
94 | * @param $indent |
---|
95 | * An optional indentation for prettifying nested code. |
---|
96 | */ |
---|
97 | function export_render($indent = ' ') { |
---|
98 | $output = ''; |
---|
99 | if (!empty($this->export_strings)) { |
---|
100 | $this->export_strings = array_unique($this->export_strings); |
---|
101 | $output = $indent . '$translatables[\'' . $this->view->name . '\'] = array(' . "\n"; |
---|
102 | foreach ($this->export_strings as $string) { |
---|
103 | $output .= $indent . " t('" . str_replace("'", "\'", $string) . "'),\n"; |
---|
104 | } |
---|
105 | $output .= $indent . ");\n"; |
---|
106 | } |
---|
107 | return $output; |
---|
108 | } |
---|
109 | } |
---|