| 1 | | <?php |
| 2 | | // $Id: locale.install,v 1.30 2008/04/14 17:48:37 dries Exp $ |
| 3 | | |
| 4 | | /** |
| 5 | | * Implementation of hook_install(). |
| 6 | | */ |
| 7 | 5 | 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 | 4 | drupal_install_schema('locale'); |
| 14 | | |
| 15 | 4 | db_query("INSERT INTO {languages} (language, name, native, direction,
enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1',
'0', '')"); |
| 16 | 4 | } |
| 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 | 5 | function locale_update_6000() { |
| 27 | 0 | $ret = array(); |
| 28 | | |
| 29 | 0 | $schema['languages'] = array( |
| 30 | | 'fields' => array( |
| 31 | | 'language' => array( |
| 32 | 0 | 'type' => 'varchar', |
| 33 | 0 | 'length' => 12, |
| 34 | 0 | 'not null' => TRUE, |
| 35 | 0 | 'default' => '', |
| 36 | 0 | ), |
| 37 | | 'name' => array( |
| 38 | 0 | 'type' => 'varchar', |
| 39 | 0 | 'length' => 64, |
| 40 | 0 | 'not null' => TRUE, |
| 41 | 0 | 'default' => '', |
| 42 | 0 | ), |
| 43 | | 'native' => array( |
| 44 | 0 | 'type' => 'varchar', |
| 45 | 0 | 'length' => 64, |
| 46 | 0 | 'not null' => TRUE, |
| 47 | 0 | 'default' => '', |
| 48 | 0 | ), |
| 49 | | 'direction' => array( |
| 50 | 0 | 'type' => 'int', |
| 51 | 0 | 'not null' => TRUE, |
| 52 | 0 | 'default' => 0, |
| 53 | 0 | ), |
| 54 | | 'enabled' => array( |
| 55 | 0 | 'type' => 'int', |
| 56 | 0 | 'not null' => TRUE, |
| 57 | 0 | 'default' => 0, |
| 58 | 0 | ), |
| 59 | | 'plurals' => array( |
| 60 | 0 | 'type' => 'int', |
| 61 | 0 | 'not null' => TRUE, |
| 62 | 0 | 'default' => 0, |
| 63 | 0 | ), |
| 64 | | 'formula' => array( |
| 65 | 0 | 'type' => 'varchar', |
| 66 | 0 | 'length' => 128, |
| 67 | 0 | 'not null' => TRUE, |
| 68 | 0 | 'default' => '', |
| 69 | 0 | ), |
| 70 | | 'domain' => array( |
| 71 | 0 | 'type' => 'varchar', |
| 72 | 0 | 'length' => 128, |
| 73 | 0 | 'not null' => TRUE, |
| 74 | 0 | 'default' => '', |
| 75 | 0 | ), |
| 76 | | 'prefix' => array( |
| 77 | 0 | 'type' => 'varchar', |
| 78 | 0 | 'length' => 128, |
| 79 | 0 | 'not null' => TRUE, |
| 80 | 0 | 'default' => '', |
| 81 | 0 | ), |
| 82 | | 'weight' => array( |
| 83 | 0 | 'type' => 'int', |
| 84 | 0 | 'not null' => TRUE, |
| 85 | 0 | 'default' => 0, |
| 86 | 0 | ), |
| 87 | | 'javascript' => array( //Adds a column to store the filename of the
JavaScript translation file. |
| 88 | 0 | 'type' => 'varchar', |
| 89 | 0 | 'length' => 32, |
| 90 | 0 | 'not null' => TRUE, |
| 91 | 0 | 'default' => '', |
| 92 | 0 | ), |
| 93 | 0 | ), |
| 94 | 0 | 'primary key' => array('language'), |
| 95 | | 'indexes' => array( |
| 96 | 0 | 'list' => array('weight', 'name'), |
| 97 | 0 | ), |
| 98 | | ); |
| 99 | | |
| 100 | 0 | db_create_table($ret, 'languages', $schema['languages']); |
| 101 | | |
| 102 | | // Save the languages |
| 103 | 0 | $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 | 0 | $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE
enabled = 1')); |
| 107 | 0 | variable_set('language_count', $count); |
| 108 | | |
| 109 | | // Save the default language in the variable table |
| 110 | 0 | $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE
isdefault = 1')); |
| 111 | 0 | 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 | 0 | $ret[] = update_sql("DROP TABLE {locales_meta}"); |
| 114 | 0 | return $ret; |
| 115 | 0 | } |
| 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 | 5 | function locale_update_6001() { |
| 124 | 0 | $ret = array(); |
| 125 | 0 | $ret[] = update_sql('UPDATE {locales_target} SET language = locale'); |
| 126 | 0 | db_drop_field($ret, 'locales_target', 'locale'); |
| 127 | 0 | return $ret; |
| 128 | 0 | } |
| 129 | | |
| 130 | | /** |
| 131 | | * Remove empty translations, we don't need these anymore. |
| 132 | | */ |
| 133 | 5 | function locale_update_6002() { |
| 134 | 0 | $ret = array(); |
| 135 | 0 | $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation =
''"); |
| 136 | 0 | return $ret; |
| 137 | 0 | } |
| 138 | | |
| 139 | | /** |
| 140 | | * Prune strings with no translations (will be automatically re-registered
if still in use) |
| 141 | | */ |
| 142 | 5 | function locale_update_6003() { |
| 143 | 0 | $ret = array(); |
| 144 | 0 | $ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN
(SELECT lid FROM {locales_target})"); |
| 145 | 0 | return $ret; |
| 146 | 0 | } |
| 147 | | |
| 148 | | /** |
| 149 | | * Fix remaining inconsistent indexes. |
| 150 | | */ |
| 151 | 5 | function locale_update_6004() { |
| 152 | 0 | $ret = array(); |
| 153 | 0 | db_add_index($ret, 'locales_target', 'language', array('language')); |
| 154 | | |
| 155 | 0 | switch ($GLOBALS['db_type']) { |
| 156 | 0 | case 'pgsql': |
| 157 | 0 | db_drop_index($ret, 'locales_source', 'source'); |
| 158 | 0 | db_add_index($ret, 'locales_source', 'source', array(array('source',
30))); |
| 159 | 0 | break; |
| 160 | 0 | } |
| 161 | | |
| 162 | 0 | return $ret; |
| 163 | 0 | } |
| 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 | 5 | function locale_update_6005() { |
| 173 | 0 | foreach (node_get_types() as $type => $content_type) { |
| 174 | | // Default to NULL, so we can skip dealing with non-existent settings. |
| 175 | 0 | $setting = variable_get('language_' . $type, NULL); |
| 176 | 0 | 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 | 0 | variable_set('language_content_type_default', $setting); |
| 180 | 0 | variable_del('language_default'); |
| 181 | 0 | 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 | 0 | } |
| 183 | 0 | 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 | 0 | variable_set('language_content_type_negotiation', $setting); |
| 189 | 0 | 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/build/types/negotiation', array('html' => TRUE)) . ' to
configure them correctly.'); |
| 190 | 0 | } |
| 191 | 0 | 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 | 0 | variable_set('language_content_type_' . $type, $setting); |
| 195 | 0 | variable_del('language_' . $type); |
| 196 | 0 | } |
| 197 | 0 | } |
| 198 | | // Update language count variable that might be overwritten. |
| 199 | 0 | $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE
enabled = 1')); |
| 200 | 0 | variable_set('language_count', $count); |
| 201 | 0 | return array(); |
| 202 | 0 | } |
| 203 | | |
| 204 | | /** |
| 205 | | * @} End of "defgroup updates-5.x-to-6.x" |
| 206 | | */ |
| 207 | | |
| 208 | | /** |
| 209 | | * Implementation of hook_uninstall(). |
| 210 | | */ |
| 211 | 5 | function locale_uninstall() { |
| 212 | | // Delete all JavaScript translation files |
| 213 | 0 | $files = db_query('SELECT javascript FROM {languages}'); |
| 214 | 0 | while ($file = db_fetch_object($files)) { |
| 215 | 0 | if (!empty($file)) { |
| 216 | 0 | file_delete(file_create_path($file->javascript)); |
| 217 | 0 | } |
| 218 | 0 | } |
| 219 | | |
| 220 | | // Remove tables. |
| 221 | 0 | drupal_uninstall_schema('locale'); |
| 222 | 0 | } |
| 223 | | |
| 224 | | /** |
| 225 | | * Implementation of hook_schema(). |
| 226 | | */ |
| 227 | 5 | function locale_schema() { |
| 228 | 4 | $schema['languages'] = array( |
| 229 | 4 | 'description' => t('List of all available languages in the system.'), |
| 230 | | 'fields' => array( |
| 231 | | 'language' => array( |
| 232 | 4 | 'type' => 'varchar', |
| 233 | 4 | 'length' => 12, |
| 234 | 4 | 'not null' => TRUE, |
| 235 | 4 | 'default' => '', |
| 236 | 4 | 'description' => t("Language code, e.g. 'de' or 'en-US'."), |
| 237 | 4 | ), |
| 238 | | 'name' => array( |
| 239 | 4 | 'type' => 'varchar', |
| 240 | 4 | 'length' => 64, |
| 241 | 4 | 'not null' => TRUE, |
| 242 | 4 | 'default' => '', |
| 243 | 4 | 'description' => t('Language name in English.'), |
| 244 | 4 | ), |
| 245 | | 'native' => array( |
| 246 | 4 | 'type' => 'varchar', |
| 247 | 4 | 'length' => 64, |
| 248 | 4 | 'not null' => TRUE, |
| 249 | 4 | 'default' => '', |
| 250 | 4 | 'description' => t('Native language name.'), |
| 251 | 4 | ), |
| 252 | | 'direction' => array( |
| 253 | 4 | 'type' => 'int', |
| 254 | 4 | 'not null' => TRUE, |
| 255 | 4 | 'default' => 0, |
| 256 | 4 | 'description' => t('Direction of language (Left-to-Right = 0,
Right-to-Left = 1).'), |
| 257 | 4 | ), |
| 258 | | 'enabled' => array( |
| 259 | 4 | 'type' => 'int', |
| 260 | 4 | 'not null' => TRUE, |
| 261 | 4 | 'default' => 0, |
| 262 | 4 | 'description' => t('Enabled flag (1 = Enabled, 0 = Disabled).'), |
| 263 | 4 | ), |
| 264 | | 'plurals' => array( |
| 265 | 4 | 'type' => 'int', |
| 266 | 4 | 'not null' => TRUE, |
| 267 | 4 | 'default' => 0, |
| 268 | 4 | 'description' => t('Number of plural indexes in this language.'), |
| 269 | 4 | ), |
| 270 | | 'formula' => array( |
| 271 | 4 | 'type' => 'varchar', |
| 272 | 4 | 'length' => 128, |
| 273 | 4 | 'not null' => TRUE, |
| 274 | 4 | 'default' => '', |
| 275 | 4 | 'description' => t('Plural formula in PHP code to evaluate to get
plural indexes.'), |
| 276 | 4 | ), |
| 277 | | 'domain' => array( |
| 278 | 4 | 'type' => 'varchar', |
| 279 | 4 | 'length' => 128, |
| 280 | 4 | 'not null' => TRUE, |
| 281 | 4 | 'default' => '', |
| 282 | 4 | 'description' => t('Domain to use for this language.'), |
| 283 | 4 | ), |
| 284 | | 'prefix' => array( |
| 285 | 4 | 'type' => 'varchar', |
| 286 | 4 | 'length' => 128, |
| 287 | 4 | 'not null' => TRUE, |
| 288 | 4 | 'default' => '', |
| 289 | 4 | 'description' => t('Path prefix to use for this language.'), |
| 290 | 4 | ), |
| 291 | | 'weight' => array( |
| 292 | 4 | 'type' => 'int', |
| 293 | 4 | 'not null' => TRUE, |
| 294 | 4 | 'default' => 0, |
| 295 | 4 | 'description' => t('Weight, used in lists of languages.'), |
| 296 | 4 | ), |
| 297 | | 'javascript' => array( |
| 298 | 4 | 'type' => 'varchar', |
| 299 | 4 | 'length' => 32, |
| 300 | 4 | 'not null' => TRUE, |
| 301 | 4 | 'default' => '', |
| 302 | 4 | 'description' => t('Location of JavaScript translation file.'), |
| 303 | 4 | ), |
| 304 | 4 | ), |
| 305 | 4 | 'primary key' => array('language'), |
| 306 | | 'indexes' => array( |
| 307 | 4 | 'list' => array('weight', 'name'), |
| 308 | 4 | ), |
| 309 | | ); |
| 310 | | |
| 311 | 4 | $schema['locales_source'] = array( |
| 312 | 4 | 'description' => t('List of English source strings.'), |
| 313 | | 'fields' => array( |
| 314 | | 'lid' => array( |
| 315 | 4 | 'type' => 'serial', |
| 316 | 4 | 'not null' => TRUE, |
| 317 | 4 | 'description' => t('Unique identifier of this string.'), |
| 318 | 4 | ), |
| 319 | | 'location' => array( |
| 320 | 4 | 'type' => 'varchar', |
| 321 | 4 | 'length' => 255, |
| 322 | 4 | 'not null' => TRUE, |
| 323 | 4 | 'default' => '', |
| 324 | 4 | 'description' => t('Drupal path in case of online discovered
translations or file path in case of imported strings.'), |
| 325 | 4 | ), |
| 326 | | 'textgroup' => array( |
| 327 | 4 | 'type' => 'varchar', |
| 328 | 4 | 'length' => 255, |
| 329 | 4 | 'not null' => TRUE, |
| 330 | 4 | 'default' => 'default', |
| 331 | 4 | 'description' => t('A module defined group of translations, see
hook_locale().'), |
| 332 | 4 | ), |
| 333 | | 'source' => array( |
| 334 | 4 | 'type' => 'text', |
| 335 | 4 | 'mysql_type' => 'blob', |
| 336 | 4 | 'not null' => TRUE, |
| 337 | 4 | 'description' => t('The original string in English.'), |
| 338 | 4 | ), |
| 339 | | 'version' => array( |
| 340 | 4 | 'type' => 'varchar', |
| 341 | 4 | 'length' => 20, |
| 342 | 4 | 'not null' => TRUE, |
| 343 | 4 | 'default' => 'none', |
| 344 | 4 | 'description' => t('Version of Drupal, where the string was last
used (for locales optimization).'), |
| 345 | 4 | ), |
| 346 | 4 | ), |
| 347 | 4 | 'primary key' => array('lid'), |
| 348 | | 'indexes' => array( |
| 349 | 4 | 'source' => array(array('source', 30)), |
| 350 | 4 | ), |
| 351 | | ); |
| 352 | | |
| 353 | 4 | $schema['locales_target'] = array( |
| 354 | 4 | 'description' => t('Stores translated versions of strings.'), |
| 355 | | 'fields' => array( |
| 356 | | 'lid' => array( |
| 357 | 4 | 'type' => 'int', |
| 358 | 4 | 'not null' => TRUE, |
| 359 | 4 | 'default' => 0, |
| 360 | 4 | 'description' => t('Source string ID. References
{locales_source}.lid.'), |
| 361 | 4 | ), |
| 362 | | 'translation' => array( |
| 363 | 4 | 'type' => 'text', |
| 364 | 4 | 'mysql_type' => 'blob', |
| 365 | 4 | 'not null' => TRUE, |
| 366 | 4 | 'description' => t('Translation string value in this language.'), |
| 367 | 4 | ), |
| 368 | | 'language' => array( |
| 369 | 4 | 'type' => 'varchar', |
| 370 | 4 | 'length' => 12, |
| 371 | 4 | 'not null' => TRUE, |
| 372 | 4 | 'default' => '', |
| 373 | 4 | 'description' => t('Language code. References
{languages}.language.'), |
| 374 | 4 | ), |
| 375 | | 'plid' => array( |
| 376 | 4 | 'type' => 'int', |
| 377 | 4 | 'not null' => TRUE, // This should be NULL for no referenced
string, not zero. |
| 378 | 4 | 'default' => 0, |
| 379 | 4 | 'description' => t('Parent lid (lid of the previous string in the
plural chain) in case of plural strings. References
{locales_source}.lid.'), |
| 380 | 4 | ), |
| 381 | | 'plural' => array( |
| 382 | 4 | 'type' => 'int', |
| 383 | 4 | 'not null' => TRUE, |
| 384 | 4 | 'default' => 0, |
| 385 | 4 | 'description' => t('Plural index number in case of plural
strings.'), |
| 386 | 4 | ), |
| 387 | 4 | ), |
| 388 | 4 | 'primary key' => array('language', 'lid', 'plural'), |
| 389 | | 'indexes' => array( |
| 390 | 4 | 'lid' => array('lid'), |
| 391 | 4 | 'plid' => array('plid'), |
| 392 | 4 | 'plural' => array('plural'), |
| 393 | 4 | ), |
| 394 | | ); |
| 395 | | |
| 396 | 4 | return $schema; |
| 397 | 0 | } |
| 398 | | |
| 399 | 5 | |