locale.install 4.46 KB
Newer Older
1
<?php
2
// $Id$
3

4 5 6
/**
 * Implementation of hook_install().
 */
7
function locale_install() {
8 9 10
  // locales_source.source and locales_target.target are not used as binary
  // fields; non-MySQL database servers need to ensure the field type is text
  // and that LIKE produces a case-sensitive comparison.
11

12 13
  // Create tables.
  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 25 26
/**
 * {locales_meta} table became {languages}.
 */
function locale_update_6001() {
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {languages} (
        language varchar(12) NOT NULL default '',
        name varchar(64) NOT NULL default '',
        native varchar(64) NOT NULL default '',
        direction int NOT NULL default '0',
        enabled int NOT NULL default '0',
        plurals int NOT NULL default '0',
        formula varchar(128) NOT NULL default '',
        domain varchar(128) NOT NULL default '',
        prefix varchar(128) NOT NULL default '',
        weight int NOT NULL default '0',
        PRIMARY KEY (language)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {languages} (
        language varchar(12) NOT NULL default '',
        name varchar(64) NOT NULL default '',
        native varchar(64) NOT NULL default '',
        direction int NOT NULL default '0',
        enabled int NOT NULL default '0',
        plurals int NOT NULL default '0',
        formula varchar(128) NOT NULL default '',
        domain varchar(128) NOT NULL default '',
        prefix varchar(128) NOT NULL default '',
        weight int NOT NULL default '0',
        PRIMARY KEY (language)
      )");
      break;
  }

  // Save the languages
  $ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, '', 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}");

  // Save the language count in the variable table
  $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1'));
  variable_set('language_count', $count);

  // Save the default language in the variable table
  $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE isdefault = 1'));
  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));

  $ret[] = update_sql("DROP TABLE {locales_meta}");
  return $ret;
}

/**
78 79 80 81
 * Change locale column to language. The language column is added by
 * update_fix_d6_requirements() in update.php to avoid a large number
 * of error messages from update.php.  All we need to do here is copy
 * locale to language and then drop locale.
82 83 84
 */
function locale_update_6002() {
  $ret = array();
85 86
  $ret[] = update_sql('UPDATE {locales_target} SET language = locale');
  db_drop_field($ret, 'locales_target', 'locale');
87 88 89
  return $ret;
}

90 91 92 93 94
/**
 * Adds a column to store the filename of the JavaScript translation file.
 */
function locale_update_6003() {
  $ret = array();
95
  db_add_field($ret, 'languages', 'javascript', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''));
96 97 98
  return $ret;
}

99 100 101 102 103 104 105 106 107
/**
 * Remove empty translations, we don't need these anymore.
 */
function locale_update_6004() {
  $ret = array();
  $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''");
  return $ret;
}

108 109 110 111 112 113 114 115 116
/**
 * Prune strings with no translations (will be automatically re-registered if still in use)
 */
function locale_update_6005() {
  $ret = array();
  $ret[] = update_sql("DELETE s FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE t.lid IS NULL");
  return $ret;
}

117 118
/**
 * @} End of "defgroup updates-5.x-to-6.x"
119 120
 */

121 122 123 124
/**
 * Implementation of hook_uninstall().
 */
function locale_uninstall() {
125 126 127 128 129 130 131 132
  // Delete all JavaScript translation files
  $files = db_query('SELECT javascript FROM {languages}');
  while ($file = db_fetch_object($files)) {
    if (!empty($file)) {
      file_delete(file_create_path($file->javascript));
    }
  }

133 134
  // Remove tables.
  drupal_uninstall_schema('locale');
135
}