4 * Implementation of hook_schema().
6 function i18n_schema() {
7 $schema['i18n_variable'] = array(
8 'description' => t('Multilingual variables.'),
11 'description' => t('The name of the variable.'),
17 'description' => t('The language of the variable.'),
23 'description' => t('The value of the variable.'),
28 'primary key' => array('name', 'language'),
34 * Set language field in its own table
35 * Do not drop node.language now, just in case
36 * TO-DO: Drop old tables, fields
38 function i18n_install() {
39 // Create database tables
40 drupal_install_schema('i18n');
41 // Set module weight for it to run after core modules
42 db_query("UPDATE {system} SET weight = 10 WHERE name = 'i18n' AND type = 'module'");
48 function i18n_update_1() {
50 $items[] = update_sql("ALTER TABLE {i18n_node} ADD language VARCHAR(12)");
51 $items[] = update_sql("UPDATE {i18n_node} i INNER JOIN {node} n ON i.nid = n.nid SET i.language = n.language ");
52 $items[] = update_sql("INSERT INTO {i18n_node}(nid,language) SELECT n.nid, n.language FROM {node} n LEFT JOIN {i18n_node} i ON n.nid = i.nid WHERE n.language != '' AND i.nid IS NULL");
56 function i18n_update_2() {
58 $items[] = update_sql("ALTER TABLE {term_data} ADD trid int(10) unsigned NOT NULL default '0'");
59 $items[] = update_sql("UPDATE {term_data} t INNER JOIN {i18n_taxonomy_term} i ON i.tid = t.tid SET t.trid = i.trid");
63 function i18n_update_3(){
65 $items[] = update_sql("ALTER TABLE {i18n_node} MODIFY COLUMN trid INTEGER UNSIGNED NOT NULL default '0', DROP PRIMARY KEY, ADD PRIMARY KEY(nid)");
66 $items[] = update_sql("ALTER TABLE {term_data} MODIFY COLUMN trid INTEGER UNSIGNED NOT NULL default '0', DROP PRIMARY KEY, ADD PRIMARY KEY(tid)");
70 function i18n_update_4(){
71 $items[] = update_sql("CREATE TABLE {i18n_variable} (
72 name varchar(48) NOT NULL default '',
73 language varchar(12) NOT NULL default '',
74 value longtext NOT NULL,
75 PRIMARY KEY (name, language)
83 // Multilingual menu items
84 function i18n_update_5(){
85 $items[] = update_sql("ALTER TABLE {menu} ADD language VARCHAR(12) NOT NULL default ''");
89 function i18n_update_6(){
90 // Old module weights. Caused some trouble with other modules.
92 // Redefinition of module weights
93 function i18n_update_7(){
94 $items[] = update_sql("UPDATE {system} SET weight = -10 WHERE name = 'i18n' AND type = 'module'");
95 $items[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'translation' AND type = 'module'");
98 // Update tables to utf8
99 function i18n_update_8(){
100 return _system_update_utf8(array('i18n_variable'));
106 function i18n_update_9() {
107 // Update content type settings
108 foreach (array_keys(node_get_types()) as
$type) {
109 if (variable_get('i18n_node_'.
$type, 0)) {
110 variable_set('language_content_type_'.
$type, TRANSLATION_ENABLED
);
113 // General language settings
114 if (variable_get('i18n_browser', 0)) {
115 variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH
);
117 variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH_DEFAULT
);
119 // Set module weight for it to run after core modules
120 $items[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'i18n' AND type = 'module'");
121 // Move node language and trid into node table
122 $items[] = update_sql("UPDATE {node} n INNER JOIN {i18n_node} i ON n.nid = i.nid SET n.language = i.language, n.tnid = i.trid");
128 * Drupal 6 clean up. To uncomment after making sure all previous updates work
131 function i18n_update_10() {
133 $items[] = update_sql("DROP TABLE {i18n_node}");
135 // Delete variables. Most settings will be now handled by Drupal core.
136 variable_del('i18n_allow');
137 variable_del('i18n_browser');
138 variable_del('i18n_content');
139 variable_del('i18n_keep');
140 variable_del('i18n_multi');
141 variable_del('i18n_interface');
142 variable_del('i18n_default');
143 variable_del('i18n_supported_langs');
144 variable_del('i18n_translation_links');
145 variable_del('i18n_translation_node_links');