summaryrefslogtreecommitdiff
path: root/modules/locale/locale.install
blob: 2594667d07ea0efcf1a4239d3e062d5905399ec2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
// $Id$

/**
 * @file
 * Install, update and uninstall functions for the locale module.
 */

/**
 * Implements hook_install().
 */
function locale_install() {
  // 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.

  db_insert('languages')
    ->fields(array(
      'language' => 'en',
      'name' => 'English',
      'native' => 'English',
      'direction' => 0,
      'enabled' => 1,
      'weight' => 0,
      'javascript' => '',
    ))
    ->execute();
}

/**
 * @addtogroup updates-6.x-to-7.x
 * @{
 */

/**
 * Add context field index and allow longer location.
 */
function locale_update_7000() {
  db_drop_index('locales_source', 'source');
  db_add_index('locales_source', 'source_context', array(array('source', 30), 'context'));

  // Also drop the 'textgroup_location' index added by the i18nstrings module
  // of the i18n project, which prevents the below schema update from running.
  if (db_index_exists('locales_source', 'textgroup_location')) {
    db_drop_index('locales_source', 'textgroup_location');
  }

  db_change_field('locales_source', 'location', 'location', array(
    'type' => 'text',
    'not null' => FALSE,
    'size' => 'big',
    'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.',
  ));
}

/**
 * Upgrade language negotiation settings.
 */
function locale_update_7001() {
  require_once DRUPAL_ROOT . '/includes/language.inc';
  require_once DRUPAL_ROOT . '/includes/locale.inc';
  require_once DRUPAL_ROOT . '/modules/locale/locale.module';

  switch (variable_get('language_negotiation', 0)) {
    // LANGUAGE_NEGOTIATION_NONE.
    case 0:
      $negotiation = array();
      break;

    // LANGUAGE_NEGOTIATION_PATH_DEFAULT.
    case 1:
      $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);
      // In Drupal 6 path prefixes are shown for the default language only when
      // language negotiation is set to LANGUAGE_NEGOTIATION_PATH, while in
      // Drupal 7 path prefixes are always shown if not empty. Hence we need to
      // ensure that the default language has an empty prefix to avoid breaking
      // the site URLs with a prefix that previously was missing.
      $default = language_default();
      $default->prefix = '';
      variable_set('language_default', $default);
      db_update('languages')
        ->fields(array('prefix' => $default->prefix))
        ->condition('language', $default->language)
        ->execute();
      break;

    // LANGUAGE_NEGOTIATION_PATH.
    case 2:
      $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_USER, LOCALE_LANGUAGE_NEGOTIATION_BROWSER);
      break;

    // LANGUAGE_NEGOTIATION_DOMAIN.
    case 3:
      variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN);
      $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);
      break;
  }

  // Save the new language negotiation options.
  language_negotiation_set(LANGUAGE_TYPE_INTERFACE, array_flip($negotiation));
  language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LOCALE_LANGUAGE_NEGOTIATION_INTERFACE => 0));
  language_negotiation_set(LANGUAGE_TYPE_URL, array(LOCALE_LANGUAGE_NEGOTIATION_URL => 0));

  // Save admininstration UI settings.
  $type = LANGUAGE_TYPE_INTERFACE;
  $provider_weights = array_flip(array_keys(locale_language_negotiation_info()));
  variable_set("locale_language_providers_weight_$type", $provider_weights);

  // Unset the old language negotiation system variable.
  variable_del('language_negotiation');

  return array();
}

/**
 * Updates URL language negotiation by adding the URL fallback detection method.
 */
function locale_update_7002() {
  // language.inc may not have been included during bootstrap if there is not
  // more than one language currently enabled.
  require_once DRUPAL_ROOT . '/includes/language.inc';
  $language_types_info = language_types_info();
  $info = $language_types_info[LANGUAGE_TYPE_URL];
  if (isset($info['fixed'])) {
    language_negotiation_set(LANGUAGE_TYPE_URL, array_flip($info['fixed']));
  }
}

/**
 * @} End of "addtogroup updates-6.x-to-7.x"
 */

/**
 * Implements hook_uninstall().
 */
function locale_uninstall() {
  // Delete all JavaScript translation files.
  $locale_js_directory = 'public://' . variable_get('locale_js_directory', 'languages');

  if (is_dir($locale_js_directory)) {
    $files = db_query('SELECT language, javascript FROM {languages}');
    foreach ($files as $file) {
      if (!empty($file->javascript)) {
        file_unmanaged_delete($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js');
      }
    }
    // Delete the JavaScript translations directory if empty.
    if (!file_scan_directory($locale_js_directory, '/.*/')) {
      drupal_rmdir($locale_js_directory);
    }
  }

  // Clear variables.
  variable_del('language_default');
  variable_del('language_count');
  variable_del('language_types');
  variable_del('locale_language_negotiation_url_part');
  variable_del('locale_language_negotiation_session_param');
  variable_del('language_content_type_default');
  variable_del('language_content_type_negotiation');
  variable_del('locale_cache_strings');
  variable_del('locale_js_directory');
  variable_del('javascript_parsed');
  variable_del('locale_field_language_fallback');
  variable_del('locale_cache_length');

  foreach (language_types() as $type) {
    variable_del("language_negotiation_$type");
    variable_del("locale_language_providers_weight_$type");
  }

  foreach (node_type_get_types() as $type => $content_type) {
    $setting = variable_del("language_content_type_$type");
  }

  // Switch back to English: with a $language->language value different from 'en'
  // successive calls of t() might result in calling locale(), which in turn might
  // try to query the unexisting {locales_source} and {locales_target} tables.
  drupal_language_initialize();

}

/**
 * Implements hook_schema().
 */
function locale_schema() {
  $schema['languages'] = array(
    'description' => 'List of all available languages in the system.',
    'fields' => array(
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => "Language code, e.g. 'de' or 'en-US'.",
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Language name in English.',
      ),
      'native' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Native language name.',
      ),
      'direction' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Direction of language (Left-to-Right = 0, Right-to-Left = 1).',
      ),
      'enabled' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Enabled flag (1 = Enabled, 0 = Disabled).',
      ),
      'plurals' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Number of plural indexes in this language.',
      ),
      'formula' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Plural formula in PHP code to evaluate to get plural indexes.',
      ),
      'domain' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Domain to use for this language.',
      ),
      'prefix' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Path prefix to use for this language.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Weight, used in lists of languages.',
      ),
      'javascript' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Location of JavaScript translation file.',
      ),
    ),
    'primary key' => array('language'),
    'indexes' => array(
      'list' => array('weight', 'name'),
    ),
  );

  $schema['locales_source'] = array(
    'description' => 'List of English source strings.',
    'fields' => array(
      'lid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Unique identifier of this string.',
      ),
      'location' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.',
      ),
      'textgroup' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'default',
        'description' => 'A module defined group of translations, see hook_locale().',
      ),
      'source' => array(
        'type' => 'text',
        'mysql_type' => 'blob',
        'not null' => TRUE,
        'description' => 'The original string in English.',
      ),
      'context' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The context this string applies to.',
      ),
      'version' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => 'none',
        'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
      ),
    ),
    'primary key' => array('lid'),
    'indexes' => array(
      'source_context' => array(array('source', 30), 'context'),
    ),
  );

  $schema['locales_target'] = array(
    'description' => 'Stores translated versions of strings.',
    'fields' => array(
      'lid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Source string ID. References {locales_source}.lid.',
      ),
      'translation' => array(
        'type' => 'text',
        'mysql_type' => 'blob',
        'not null' => TRUE,
        'description' => 'Translation string value in this language.',
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Language code. References {languages}.language.',
      ),
      'plid' => array(
        'type' => 'int',
        'not null' => TRUE, // This should be NULL for no referenced string, not zero.
        'default' => 0,
        'description' => 'Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.',
      ),
      'plural' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Plural index number in case of plural strings.',
      ),
    ),
    'primary key' => array('language', 'lid', 'plural'),
    'foreign keys' => array(
      'locales_source' => array(
        'table' => 'locales_source',
        'columns' => array('lid' => 'lid'),
      ),
    ),
    'indexes' => array(
      'lid'      => array('lid'),
      'plid'     => array('plid'),
      'plural'   => array('plural'),
    ),
  );

  return $schema;
}