You are here

i18n.install in Internationalization 5.3

Same filename and directory in other branches
  1. 5 i18n.install
  2. 5.2 i18n.install
  3. 6 i18n.install
  4. 7 i18n.install

File

i18n.install
View source
<?php

/**
 * Set language field in its own table
 * Do not drop node.language now, just in case
 * TO-DO: Drop old tables, fields
 */
function i18n_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {i18n_node} (\n        nid int(11) unsigned NOT NULL ,\n        trid int(10) unsigned NOT NULL default '0',\n        language VARCHAR(12) NOT NULL default '',  \n        status smallint(6) NOT NULL default '0',\n        PRIMARY KEY (nid) \n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
      db_query("ALTER TABLE {term_data}\n        ADD language varchar(12) NOT NULL default '',\n        ADD trid int(10) unsigned NOT NULL default '0'\n      ");
      db_query("ALTER TABLE {vocabulary}\n        ADD language varchar(12) NOT NULL default ''\n      ");
      db_query("CREATE TABLE {i18n_variable} (\n        name varchar(48) NOT NULL default '',\n        language varchar(12) NOT NULL default '',\n        value longtext NOT NULL,\n        PRIMARY KEY (name, language)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("ALTER TABLE {menu} \n        ADD language VARCHAR(12) NOT NULL default ''\n      ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {i18n_node} (\n        nid integer NOT NULL default '0', \n        trid integer NOT NULL default '0',\n        language varchar(12) NOT NULL default '',\n        status smallint NOT NULL default '0',\n        PRIMARY KEY  (nid)\n      )");
      db_query("CREATE TABLE {i18n_variable} (\n        name varchar(48) NOT NULL default '',\n        language varchar(12) NOT NULL default '',\n        value text NOT NULL,\n        PRIMARY KEY (name, language)\n      )");
      db_query("ALTER TABLE {term_data} ADD language varchar(12)");
      db_query("UPDATE {term_data} SET language=''");
      db_query("ALTER TABLE {term_data} ALTER COLUMN language SET NOT NULL");
      db_query("ALTER TABLE {term_data} ALTER COLUMN language SET DEFAULT ''");
      db_query("ALTER TABLE {term_data} ADD trid integer");
      db_query("UPDATE {term_data} SET trid='0'");
      db_query("ALTER TABLE {term_data} ALTER COLUMN trid SET NOT NULL");
      db_query("ALTER TABLE {term_data} ALTER COLUMN trid SET DEFAULT '0'");
      db_query("ALTER TABLE {vocabulary} ADD language varchar(12)");
      db_query("UPDATE {vocabulary} SET language=''");
      db_query("ALTER TABLE {vocabulary} ALTER COLUMN language SET NOT NULL");
      db_query("ALTER TABLE {vocabulary} ALTER COLUMN language SET DEFAULT ''");
      db_query("ALTER TABLE {menu} ADD language varchar(12)");
      db_query("UPDATE {menu} SET language=''");
      db_query("ALTER TABLE {menu} ALTER COLUMN language SET NOT NULL");
      db_query("ALTER TABLE {menu} ALTER COLUMN language SET DEFAULT ''");

      // Sequences
      db_query("CREATE SEQUENCE {i18n_node}_trid_seq INCREMENT 1 START 1");
      db_query("CREATE SEQUENCE {term_data}_trid_seq INCREMENT 1 START 1");
  }

  // Set module weight for it to run after core modules
  db_query("UPDATE {system} SET weight = -10 WHERE name = 'i18n' AND type = 'module'");
  db_query("UPDATE {system} SET weight = 10 WHERE name = 'translation' AND type = 'module'");
}

/**
 *  Drupal 4.7 updates 
 **/
function i18n_update_1() {
  $items = array();
  $items[] = update_sql("ALTER TABLE {i18n_node} ADD language VARCHAR(12)");
  $items[] = update_sql("UPDATE {i18n_node} i INNER JOIN {node} n ON i.nid = n.nid SET i.language = n.language ");
  $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");
  return $items;
}
function i18n_update_2() {
  $items = array();
  $items[] = update_sql("ALTER TABLE {term_data} ADD trid int(10) unsigned NOT NULL default '0'");
  $items[] = update_sql("UPDATE {term_data} t INNER JOIN {i18n_taxonomy_term} i ON i.tid = t.tid SET t.trid = i.trid");
  return $items;
}
function i18n_update_3() {
  $items = array();
  $items[] = update_sql("ALTER TABLE {i18n_node} MODIFY COLUMN trid INTEGER UNSIGNED NOT NULL default '0', DROP PRIMARY KEY, ADD PRIMARY KEY(nid)");
  $items[] = update_sql("ALTER TABLE {term_data} MODIFY COLUMN trid INTEGER UNSIGNED NOT NULL default '0', DROP PRIMARY KEY, ADD PRIMARY KEY(tid)");
  return $items;
}
function i18n_update_4() {
  $items[] = update_sql("CREATE TABLE {i18n_variable} (\n        name varchar(48) NOT NULL default '',\n        language varchar(12) NOT NULL default '',\n        value longtext NOT NULL,\n        PRIMARY KEY (name, language)\n      )");
  return $items;
}

/**
 * Drupal 5 updates
 */

// Multilingual menu items
function i18n_update_5() {
  $items[] = update_sql("ALTER TABLE {menu} ADD language VARCHAR(12) NOT NULL default ''");
  return $items;
}

// Module weithgts
function i18n_update_6() {

  // Old module weights. Caused some trouble with other modules.
}

// Redefinition of module weights
function i18n_update_7() {
  $items[] = update_sql("UPDATE {system} SET weight = -10 WHERE name = 'i18n' AND type = 'module'");
  $items[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'translation' AND type = 'module'");
  return $items;
}

// Update tables to utf8
function i18n_update_8() {
  return _system_update_utf8(array(
    'i18n_variable',
  ));
}

Functions

Namesort descending Description
i18n_install Set language field in its own table Do not drop node.language now, just in case TO-DO: Drop old tables, fields
i18n_update_1 Drupal 4.7 updates
i18n_update_2
i18n_update_3
i18n_update_4
i18n_update_5
i18n_update_6
i18n_update_7
i18n_update_8