/[drupal]/drupal/modules/locale/locale.install
ViewVC logotype

Contents of /drupal/modules/locale/locale.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.52 - (show annotations) (download) (as text)
Sat Oct 17 12:07:31 2009 UTC (5 weeks, 6 days ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.51: +2 -1 lines
File MIME type: text/x-php
- Patch #278592 by catch, Dave Reid, andypost, lilou, sun, tobiasb: sync 6.x extra updates with HEAD.
1 <?php
2 // $Id: locale.install,v 1.51 2009/10/11 11:24:08 dries Exp $
3
4 /**
5 * @file
6 * Install, update and uninstall functions for the locale module.
7 */
8
9 /**
10 * Implement hook_install().
11 */
12 function locale_install() {
13 // locales_source.source and locales_target.target are not used as binary
14 // fields; non-MySQL database servers need to ensure the field type is text
15 // and that LIKE produces a case-sensitive comparison.
16
17 db_insert('languages')
18 ->fields(array(
19 'language' => 'en',
20 'name' => 'English',
21 'native' => 'English',
22 'direction' => 0,
23 'enabled' => 1,
24 'weight' => 0,
25 'javascript' => '',
26 ))
27 ->execute();
28 }
29
30 /**
31 * @defgroup updates-6.x-to-7.x Locale updates from 6.x to 7.x
32 * @{
33 */
34
35 /**
36 * Add context field and allow longer location.
37 */
38 function locale_update_7000() {
39 db_add_field('locales_source', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
40 db_drop_index('locales_source', 'source');
41 db_add_index('locales_source', 'source_context', array(array('source', 30), 'context'));
42 db_change_field('locales_source', 'location', 'location', array('type' => 'text', 'size' => 'big', 'not null' => FALSE));
43 }
44
45 /**
46 * Upgrade language negotiation settings.
47 */
48 function locale_update_7001() {
49 require_once DRUPAL_ROOT . '/includes/language.inc';
50
51 switch (variable_get('language_negotiation', 0)) {
52 // LANGUAGE_NEGOTIATION_NONE.
53 case 0:
54 $negotiation = array();
55 break;
56
57 // LANGUAGE_NEGOTIATION_PATH_DEFAULT.
58 case 1:
59 $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);
60 break;
61
62 // LANGUAGE_NEGOTIATION_PATH.
63 case 2:
64 $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_USER, LOCALE_LANGUAGE_NEGOTIATION_BROWSER);
65 break;
66
67 // LANGUAGE_NEGOTIATION_DOMAIN.
68 case 3:
69 variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN);
70 $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);
71 break;
72 }
73
74 // Save new language negotiation options: UI language is tied to content
75 // language as this was Drupal 6 behavior.
76 language_negotiation_set(LANGUAGE_TYPE_CONTENT, array_flip($negotiation));
77 language_negotiation_set(LANGUAGE_TYPE_INTERFACE, array(LOCALE_LANGUAGE_NEGOTIATION_CONTENT => 0));
78 language_negotiation_set(LANGUAGE_TYPE_URL, array(LOCALE_LANGUAGE_NEGOTIATION_URL => 0));
79
80 // Unset the old language negotiation system variable.
81 variable_del('language_negotiation');
82
83 return array();
84 }
85
86 /**
87 * @} End of "defgroup updates-6.x-to-7.x"
88 */
89
90 /**
91 * Implement hook_uninstall().
92 */
93 function locale_uninstall() {
94 // Delete all JavaScript translation files.
95 $locale_js_directory = 'public://' . variable_get('locale_js_directory', 'languages');
96 $files = db_query('SELECT language, javascript FROM {languages}');
97 foreach ($files as $file) {
98 if (!empty($file->javascript)) {
99 file_unmanaged_delete($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js');
100 }
101 }
102 // Delete the JavaScript translations directory if empty.
103 @rmdir($locale_js_directory);
104
105 // Clear variables.
106 variable_del('language_default');
107 variable_del('language_count');
108 variable_del('language_types');
109 variable_del('locale_language_negotiation_url_part');
110 variable_del('locale_language_negotiation_session_param');
111 variable_del('language_content_type_default');
112 variable_del('language_content_type_negotiation');
113 variable_del('locale_cache_strings');
114 variable_del('locale_js_directory');
115 variable_del('javascript_parsed');
116
117 foreach (language_types() as $type) {
118 variable_del("language_negotiation_$type");
119 variable_del("locale_language_providers_enabled_$type");
120 variable_del("locale_language_providers_weight_$type");
121 }
122
123 foreach (node_type_get_types() as $type => $content_type) {
124 $setting = variable_del("language_content_type_$type");
125 }
126
127 // Switch back to English: with a $language->language value different from 'en'
128 // successive calls of t() might result in calling locale(), which in turn might
129 // try to query the unexisting {locales_source} and {locales_target} tables.
130 drupal_language_initialize();
131
132 }
133
134 /**
135 * Implement hook_schema().
136 */
137 function locale_schema() {
138 $schema['languages'] = array(
139 'description' => 'List of all available languages in the system.',
140 'fields' => array(
141 'language' => array(
142 'type' => 'varchar',
143 'length' => 12,
144 'not null' => TRUE,
145 'default' => '',
146 'description' => "Language code, e.g. 'de' or 'en-US'.",
147 ),
148 'name' => array(
149 'type' => 'varchar',
150 'length' => 64,
151 'not null' => TRUE,
152 'default' => '',
153 'description' => 'Language name in English.',
154 ),
155 'native' => array(
156 'type' => 'varchar',
157 'length' => 64,
158 'not null' => TRUE,
159 'default' => '',
160 'description' => 'Native language name.',
161 ),
162 'direction' => array(
163 'type' => 'int',
164 'not null' => TRUE,
165 'default' => 0,
166 'description' => 'Direction of language (Left-to-Right = 0, Right-to-Left = 1).',
167 ),
168 'enabled' => array(
169 'type' => 'int',
170 'not null' => TRUE,
171 'default' => 0,
172 'description' => 'Enabled flag (1 = Enabled, 0 = Disabled).',
173 ),
174 'plurals' => array(
175 'type' => 'int',
176 'not null' => TRUE,
177 'default' => 0,
178 'description' => 'Number of plural indexes in this language.',
179 ),
180 'formula' => array(
181 'type' => 'varchar',
182 'length' => 128,
183 'not null' => TRUE,
184 'default' => '',
185 'description' => 'Plural formula in PHP code to evaluate to get plural indexes.',
186 ),
187 'domain' => array(
188 'type' => 'varchar',
189 'length' => 128,
190 'not null' => TRUE,
191 'default' => '',
192 'description' => 'Domain to use for this language.',
193 ),
194 'prefix' => array(
195 'type' => 'varchar',
196 'length' => 128,
197 'not null' => TRUE,
198 'default' => '',
199 'description' => 'Path prefix to use for this language.',
200 ),
201 'weight' => array(
202 'type' => 'int',
203 'not null' => TRUE,
204 'default' => 0,
205 'description' => 'Weight, used in lists of languages.',
206 ),
207 'javascript' => array(
208 'type' => 'varchar',
209 'length' => 32,
210 'not null' => TRUE,
211 'default' => '',
212 'description' => 'Location of JavaScript translation file.',
213 ),
214 ),
215 'primary key' => array('language'),
216 'indexes' => array(
217 'list' => array('weight', 'name'),
218 ),
219 );
220
221 $schema['locales_source'] = array(
222 'description' => 'List of English source strings.',
223 'fields' => array(
224 'lid' => array(
225 'type' => 'serial',
226 'not null' => TRUE,
227 'description' => 'Unique identifier of this string.',
228 ),
229 'location' => array(
230 'type' => 'text',
231 'not null' => FALSE,
232 'size' => 'big',
233 'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.',
234 ),
235 'textgroup' => array(
236 'type' => 'varchar',
237 'length' => 255,
238 'not null' => TRUE,
239 'default' => 'default',
240 'description' => 'A module defined group of translations, see hook_locale().',
241 ),
242 'source' => array(
243 'type' => 'text',
244 'mysql_type' => 'blob',
245 'not null' => TRUE,
246 'description' => 'The original string in English.',
247 ),
248 'context' => array(
249 'type' => 'varchar',
250 'length' => 255,
251 'not null' => TRUE,
252 'default' => '',
253 'description' => 'The context this string applies to.',
254 ),
255 'version' => array(
256 'type' => 'varchar',
257 'length' => 20,
258 'not null' => TRUE,
259 'default' => 'none',
260 'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
261 ),
262 ),
263 'primary key' => array('lid'),
264 'indexes' => array(
265 'source_context' => array(array('source', 30), 'context'),
266 ),
267 );
268
269 $schema['locales_target'] = array(
270 'description' => 'Stores translated versions of strings.',
271 'fields' => array(
272 'lid' => array(
273 'type' => 'int',
274 'not null' => TRUE,
275 'default' => 0,
276 'description' => 'Source string ID. References {locales_source}.lid.',
277 ),
278 'translation' => array(
279 'type' => 'text',
280 'mysql_type' => 'blob',
281 'not null' => TRUE,
282 'description' => 'Translation string value in this language.',
283 ),
284 'language' => array(
285 'type' => 'varchar',
286 'length' => 12,
287 'not null' => TRUE,
288 'default' => '',
289 'description' => 'Language code. References {languages}.language.',
290 ),
291 'plid' => array(
292 'type' => 'int',
293 'not null' => TRUE, // This should be NULL for no referenced string, not zero.
294 'default' => 0,
295 'description' => 'Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.',
296 ),
297 'plural' => array(
298 'type' => 'int',
299 'not null' => TRUE,
300 'default' => 0,
301 'description' => 'Plural index number in case of plural strings.',
302 ),
303 ),
304 'primary key' => array('language', 'lid', 'plural'),
305 'foreign keys' => array(
306 'lid' => array('locales_source' => 'lid'),
307 ),
308 'indexes' => array(
309 'lid' => array('lid'),
310 'plid' => array('plid'),
311 'plural' => array('plural'),
312 ),
313 );
314
315 return $schema;
316 }
317

  ViewVC Help
Powered by ViewVC 1.1.2