locale.install 6.37 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
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
14
15
      db_query("CREATE TABLE {languages} (
        language varchar(12) NOT NULL default '',
16
        name varchar(64) NOT NULL default '',
17
18
        native varchar(64) NOT NULL default '',
        direction int NOT NULL default '0',
19
20
        enabled int NOT NULL default '0',
        plurals int NOT NULL default '0',
21
        formula varchar(128) NOT NULL default '',
22
23
24
25
        domain varchar(128) NOT NULL default '',
        prefix varchar(128) NOT NULL default '',
        weight int NOT NULL default '0',
        PRIMARY KEY (language)
26
27
28
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {locales_source} (
29
        lid int NOT NULL auto_increment,
30
        location varchar(255) NOT NULL default '',
31
        textgroup varchar(255) NOT NULL default '',
32
        source blob NOT NULL,
33
34
        PRIMARY KEY (lid),
        KEY source (source(30))
35
36
37
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {locales_target} (
38
        lid int NOT NULL default '0',
39
        translation blob NOT NULL,
40
        language varchar(12) NOT NULL default '',
41
42
        plid int NOT NULL default '0',
        plural int NOT NULL default '0',
43
        KEY lid (lid),
44
        KEY lang (language),
45
46
47
        KEY plid (plid),
        KEY plural (plural)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
48
      break;
49

50
    case 'pgsql':
51
52
      db_query("CREATE TABLE {languages} (
        language varchar(12) NOT NULL default '',
53
        name varchar(64) NOT NULL default '',
54
55
        native varchar(64) NOT NULL default '',
        direction int NOT NULL default '0',
56
57
58
        enabled int NOT NULL default '0',
        plurals int NOT NULL default '0',
        formula varchar(128) NOT NULL default '',
59
60
61
62
        domain varchar(128) NOT NULL default '',
        prefix varchar(128) NOT NULL default '',
        weight int NOT NULL default '0',
        PRIMARY KEY (language)
63
64
65
66
67
      )");

      db_query("CREATE TABLE {locales_source} (
        lid serial,
        location varchar(255) NOT NULL default '',
68
        textgroup varchar(255) NOT NULL default '',
69
        source text NOT NULL,
70
71
72
73
74
        PRIMARY KEY (lid)
      )");

      db_query("CREATE TABLE {locales_target} (
        lid int NOT NULL default '0',
75
        translation text NOT NULL,
76
        language varchar(12) NOT NULL default '',
77
78
79
80
        plid int NOT NULL default '0',
        plural int NOT NULL default '0'
      )");
      db_query("CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)");
81
      db_query("CREATE INDEX {locales_target}_language_idx ON {locales_target} (language)");
82
83
      db_query("CREATE INDEX {locales_target}_plid_idx ON {locales_target} (plid)");
      db_query("CREATE INDEX {locales_target}_plural_idx ON {locales_target} (plural)");
84
      db_query("CREATE INDEX {locales_source}_source_idx ON {locales_source} (source)");
85
      break;
86
  }
87
  db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight) VALUES ('en', 'English', 'English', '0', '1', '0')");
88
}
89

90
/**
91
 * @defgroup updates-5.x-to-6.x Locale updates from 5.x to 6.x
92
93
94
 * @{
 */

95
96
97
98
/**
 * {locales_meta} table became {languages}.
 */
function locale_update_6001() {
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
  $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;
}

/**
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
 * Add multiple text group support to allow for user defined string translation.
 */
function locale_update_6002() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_add_column($ret, 'locales_source', 'textgroup', 'varchar(255)', array('default' => "''", 'not null' => TRUE));
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {locales_source} ADD textgroup varchar(255) NOT NULL default ''");
      break;
  }
  return $ret;
}

/**
 * @} End of "defgroup updates-5.x-to-6.x"
168
169
 */

170
171
172
173
/**
 * Implementation of hook_uninstall().
 */
function locale_uninstall() {
174
  db_query('DROP TABLE {languages}');
175
176
177
  db_query('DROP TABLE {locales_source}');
  db_query('DROP TABLE {locales_target}');
}