Mercurial > defr > drupal > core
comparison modules/locale/locale.install @ 1:c1f4ac30525a 6.0
Drupal 6.0
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:28:28 +0100 |
parents | |
children | 3edae6ecd6c6 |
comparison
equal
deleted
inserted
replaced
0:5a113a1c4740 | 1:c1f4ac30525a |
---|---|
1 <?php | |
2 // $Id: locale.install,v 1.27 2008/01/10 14:35:24 goba Exp $ | |
3 | |
4 /** | |
5 * Implementation of hook_install(). | |
6 */ | |
7 function locale_install() { | |
8 // locales_source.source and locales_target.target are not used as binary | |
9 // fields; non-MySQL database servers need to ensure the field type is text | |
10 // and that LIKE produces a case-sensitive comparison. | |
11 | |
12 // Create tables. | |
13 drupal_install_schema('locale'); | |
14 | |
15 db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1', '0', '')"); | |
16 } | |
17 | |
18 /** | |
19 * @defgroup updates-5.x-to-6.x Locale updates from 5.x to 6.x | |
20 * @{ | |
21 */ | |
22 | |
23 /** | |
24 * {locales_meta} table became {languages}. | |
25 */ | |
26 function locale_update_6000() { | |
27 $ret = array(); | |
28 | |
29 $schema['languages'] = array( | |
30 'fields' => array( | |
31 'language' => array( | |
32 'type' => 'varchar', | |
33 'length' => 12, | |
34 'not null' => TRUE, | |
35 'default' => '', | |
36 ), | |
37 'name' => array( | |
38 'type' => 'varchar', | |
39 'length' => 64, | |
40 'not null' => TRUE, | |
41 'default' => '', | |
42 ), | |
43 'native' => array( | |
44 'type' => 'varchar', | |
45 'length' => 64, | |
46 'not null' => TRUE, | |
47 'default' => '', | |
48 ), | |
49 'direction' => array( | |
50 'type' => 'int', | |
51 'not null' => TRUE, | |
52 'default' => 0, | |
53 ), | |
54 'enabled' => array( | |
55 'type' => 'int', | |
56 'not null' => TRUE, | |
57 'default' => 0, | |
58 ), | |
59 'plurals' => array( | |
60 'type' => 'int', | |
61 'not null' => TRUE, | |
62 'default' => 0, | |
63 ), | |
64 'formula' => array( | |
65 'type' => 'varchar', | |
66 'length' => 128, | |
67 'not null' => TRUE, | |
68 'default' => '', | |
69 ), | |
70 'domain' => array( | |
71 'type' => 'varchar', | |
72 'length' => 128, | |
73 'not null' => TRUE, | |
74 'default' => '', | |
75 ), | |
76 'prefix' => array( | |
77 'type' => 'varchar', | |
78 'length' => 128, | |
79 'not null' => TRUE, | |
80 'default' => '', | |
81 ), | |
82 'weight' => array( | |
83 'type' => 'int', | |
84 'not null' => TRUE, | |
85 'default' => 0, | |
86 ), | |
87 'javascript' => array( //Adds a column to store the filename of the JavaScript translation file. | |
88 'type' => 'varchar', | |
89 'length' => 32, | |
90 'not null' => TRUE, | |
91 'default' => '', | |
92 ), | |
93 ), | |
94 'primary key' => array('language'), | |
95 'indexes' => array( | |
96 'list' => array('weight', 'name'), | |
97 ), | |
98 ); | |
99 | |
100 db_create_table($ret, 'languages', $schema['languages']); | |
101 | |
102 // Save the languages | |
103 $ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, name, 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}"); | |
104 | |
105 // Save the language count in the variable table | |
106 $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1')); | |
107 variable_set('language_count', $count); | |
108 | |
109 // Save the default language in the variable table | |
110 $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE isdefault = 1')); | |
111 variable_set('language_default', (object) array('language' => $default->locale, 'name' => $default->name, 'native' => '', 'direction' => 0, 'enabled' => 1, 'plurals' => $default->plurals, 'formula' => $default->formula, 'domain' => '', 'prefix' => $default->locale, 'weight' => 0)); | |
112 | |
113 $ret[] = update_sql("DROP TABLE {locales_meta}"); | |
114 return $ret; | |
115 } | |
116 | |
117 /** | |
118 * Change locale column to language. The language column is added by | |
119 * update_fix_d6_requirements() in update.php to avoid a large number | |
120 * of error messages from update.php. All we need to do here is copy | |
121 * locale to language and then drop locale. | |
122 */ | |
123 function locale_update_6001() { | |
124 $ret = array(); | |
125 $ret[] = update_sql('UPDATE {locales_target} SET language = locale'); | |
126 db_drop_field($ret, 'locales_target', 'locale'); | |
127 return $ret; | |
128 } | |
129 | |
130 /** | |
131 * Remove empty translations, we don't need these anymore. | |
132 */ | |
133 function locale_update_6002() { | |
134 $ret = array(); | |
135 $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''"); | |
136 return $ret; | |
137 } | |
138 | |
139 /** | |
140 * Prune strings with no translations (will be automatically re-registered if still in use) | |
141 */ | |
142 function locale_update_6003() { | |
143 $ret = array(); | |
144 $ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN (SELECT lid FROM {locales_target})"); | |
145 return $ret; | |
146 } | |
147 | |
148 /** | |
149 * Fix remaining inconsistent indexes. | |
150 */ | |
151 function locale_update_6004() { | |
152 $ret = array(); | |
153 db_add_index($ret, 'locales_target', 'language', array('language')); | |
154 | |
155 switch ($GLOBALS['db_type']) { | |
156 case 'pgsql': | |
157 db_drop_index($ret, 'locales_source', 'source'); | |
158 db_add_index($ret, 'locales_source', 'source', array(array('source', 30))); | |
159 break; | |
160 } | |
161 | |
162 return $ret; | |
163 } | |
164 | |
165 /** | |
166 * Change language setting variable of content types. | |
167 * | |
168 * Use language_content_type_<content_type> instead of language_<content_type> | |
169 * so content types such as 'default', 'count' or 'negotiation' will not | |
170 * interfere with language variables. | |
171 */ | |
172 function locale_update_6005() { | |
173 foreach (node_get_types() as $type => $content_type) { | |
174 // Default to NULL, so we can skip dealing with non-existent settings. | |
175 $setting = variable_get('language_'. $type, NULL); | |
176 if ($type == 'default' && is_numeric($setting)) { | |
177 // language_default was overwritten with the content type setting, | |
178 // so reset the default language and save the content type setting. | |
179 variable_set('language_content_type_default', $setting); | |
180 variable_del('language_default'); | |
181 drupal_set_message('The default language setting has been reset to its default value. Check the '. l('language configuration page', 'admin/settings/language') .' to configure it correctly.'); | |
182 } | |
183 elseif ($type == 'negotiation') { | |
184 // language_content_type_negotiation is an integer either if it is | |
185 // the negotiation setting or the content type setting. | |
186 // The language_negotiation setting is not reset, but | |
187 // the user is alerted that this setting possibly was overwritten | |
188 variable_set('language_content_type_negotiation', $setting); | |
189 drupal_set_message('The language negotiation setting was possibly overwritten by a content type of the same name. Check the '. l('language configuration page', 'admin/settings/language/configure') .' and the '. l('<em>'. $content_type->name ."</em> content type's multilingual support settings", 'admin/content/types/negotiation', array('html' => TRUE)) .' to configure them correctly.'); | |
190 } | |
191 elseif (!is_null($setting)) { | |
192 // Change the language setting variable for any other content type. | |
193 // Do not worry about language_count, it will be updated below. | |
194 variable_set('language_content_type_'. $type, $setting); | |
195 variable_del('language_'. $type); | |
196 } | |
197 } | |
198 // Update language count variable that might be overwritten. | |
199 $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1')); | |
200 variable_set('language_count', $count); | |
201 return array(); | |
202 } | |
203 | |
204 /** | |
205 * @} End of "defgroup updates-5.x-to-6.x" | |
206 */ | |
207 | |
208 /** | |
209 * Implementation of hook_uninstall(). | |
210 */ | |
211 function locale_uninstall() { | |
212 // Delete all JavaScript translation files | |
213 $files = db_query('SELECT javascript FROM {languages}'); | |
214 while ($file = db_fetch_object($files)) { | |
215 if (!empty($file)) { | |
216 file_delete(file_create_path($file->javascript)); | |
217 } | |
218 } | |
219 | |
220 // Remove tables. | |
221 drupal_uninstall_schema('locale'); | |
222 } | |
223 | |
224 /** | |
225 * Implementation of hook_schema(). | |
226 */ | |
227 function locale_schema() { | |
228 $schema['languages'] = array( | |
229 'description' => t('List of all available languages in the system.'), | |
230 'fields' => array( | |
231 'language' => array( | |
232 'type' => 'varchar', | |
233 'length' => 12, | |
234 'not null' => TRUE, | |
235 'default' => '', | |
236 'description' => t("Language code, e.g. 'de' or 'en-US'."), | |
237 ), | |
238 'name' => array( | |
239 'type' => 'varchar', | |
240 'length' => 64, | |
241 'not null' => TRUE, | |
242 'default' => '', | |
243 'description' => t('Language name in English.'), | |
244 ), | |
245 'native' => array( | |
246 'type' => 'varchar', | |
247 'length' => 64, | |
248 'not null' => TRUE, | |
249 'default' => '', | |
250 'description' => t('Native language name.'), | |
251 ), | |
252 'direction' => array( | |
253 'type' => 'int', | |
254 'not null' => TRUE, | |
255 'default' => 0, | |
256 'description' => t('Direction of language (Left-to-Right = 0, Right-to-Left = 1).'), | |
257 ), | |
258 'enabled' => array( | |
259 'type' => 'int', | |
260 'not null' => TRUE, | |
261 'default' => 0, | |
262 'description' => t('Enabled flag (1 = Enabled, 0 = Disabled).'), | |
263 ), | |
264 'plurals' => array( | |
265 'type' => 'int', | |
266 'not null' => TRUE, | |
267 'default' => 0, | |
268 'description' => t('Number of plural indexes in this language.'), | |
269 ), | |
270 'formula' => array( | |
271 'type' => 'varchar', | |
272 'length' => 128, | |
273 'not null' => TRUE, | |
274 'default' => '', | |
275 'description' => t('Plural formula in PHP code to evaluate to get plural indexes.'), | |
276 ), | |
277 'domain' => array( | |
278 'type' => 'varchar', | |
279 'length' => 128, | |
280 'not null' => TRUE, | |
281 'default' => '', | |
282 'description' => t('Domain to use for this language.'), | |
283 ), | |
284 'prefix' => array( | |
285 'type' => 'varchar', | |
286 'length' => 128, | |
287 'not null' => TRUE, | |
288 'default' => '', | |
289 'description' => t('Path prefix to use for this language.'), | |
290 ), | |
291 'weight' => array( | |
292 'type' => 'int', | |
293 'not null' => TRUE, | |
294 'default' => 0, | |
295 'description' => t('Weight, used in lists of languages.'), | |
296 ), | |
297 'javascript' => array( | |
298 'type' => 'varchar', | |
299 'length' => 32, | |
300 'not null' => TRUE, | |
301 'default' => '', | |
302 'description' => t('Location of JavaScript translation file.'), | |
303 ), | |
304 ), | |
305 'primary key' => array('language'), | |
306 'indexes' => array( | |
307 'list' => array('weight', 'name'), | |
308 ), | |
309 ); | |
310 | |
311 $schema['locales_source'] = array( | |
312 'description' => t('List of English source strings.'), | |
313 'fields' => array( | |
314 'lid' => array( | |
315 'type' => 'serial', | |
316 'not null' => TRUE, | |
317 'description' => t('Unique identifier of this string.'), | |
318 ), | |
319 'location' => array( | |
320 'type' => 'varchar', | |
321 'length' => 255, | |
322 'not null' => TRUE, | |
323 'default' => '', | |
324 'description' => t('Drupal path in case of online discovered translations or file path in case of imported strings.'), | |
325 ), | |
326 'textgroup' => array( | |
327 'type' => 'varchar', | |
328 'length' => 255, | |
329 'not null' => TRUE, | |
330 'default' => 'default', | |
331 'description' => t('A module defined group of translations, see hook_locale().'), | |
332 ), | |
333 'source' => array( | |
334 'type' => 'text', | |
335 'mysql_type' => 'blob', | |
336 'not null' => TRUE, | |
337 'description' => t('The original string in English.'), | |
338 ), | |
339 'version' => array( | |
340 'type' => 'varchar', | |
341 'length' => 20, | |
342 'not null' => TRUE, | |
343 'default' => 'none', | |
344 'description' => t('Version of Drupal, where the string was last used (for locales optimization).'), | |
345 ), | |
346 ), | |
347 'primary key' => array('lid'), | |
348 'indexes' => array( | |
349 'source' => array(array('source', 30)), | |
350 ), | |
351 ); | |
352 | |
353 $schema['locales_target'] = array( | |
354 'description' => t('Stores translated versions of strings.'), | |
355 'fields' => array( | |
356 'lid' => array( | |
357 'type' => 'int', | |
358 'not null' => TRUE, | |
359 'default' => 0, | |
360 'description' => t('Source string ID. References {locales_source}.lid.'), | |
361 ), | |
362 'translation' => array( | |
363 'type' => 'text', | |
364 'mysql_type' => 'blob', | |
365 'not null' => TRUE, | |
366 'description' => t('Translation string value in this language.'), | |
367 ), | |
368 'language' => array( | |
369 'type' => 'varchar', | |
370 'length' => 12, | |
371 'not null' => TRUE, | |
372 'default' => '', | |
373 'description' => t('Language code. References {languages}.language.'), | |
374 ), | |
375 'plid' => array( | |
376 'type' => 'int', | |
377 'not null' => TRUE, // This should be NULL for no referenced string, not zero. | |
378 'default' => 0, | |
379 'description' => t('Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.'), | |
380 ), | |
381 'plural' => array( | |
382 'type' => 'int', | |
383 'not null' => TRUE, | |
384 'default' => 0, | |
385 'description' => t('Plural index number in case of plural strings.'), | |
386 ), | |
387 ), | |
388 'primary key' => array('language', 'lid', 'plural'), | |
389 'indexes' => array( | |
390 'lid' => array('lid'), | |
391 'plid' => array('plid'), | |
392 'plural' => array('plural'), | |
393 ), | |
394 ); | |
395 | |
396 return $schema; | |
397 } | |
398 |