language.install 3.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

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

/**
 * Implements hook_install().
10
11
12
 *
 * Enable URL language negotiation by default in order to have a basic working
 * system on multilingual sites without needing any preliminary configuration.
13
14
15
16
 */
function language_install() {
  // Add the default language to the database too.
  language_save(language_default());
17
18
19
20
21
22

  // Enable URL language detection for each configurable language type.
  require_once DRUPAL_ROOT . '/core/includes/language.inc';
  foreach (language_types_get_configurable(FALSE) as $type) {
    language_negotiation_set($type, array(LANGUAGE_NEGOTIATION_URL => 0));
  }
23
24
25
26
27
28
29
30
31
32
}

/**
 * Implements hook_uninstall().
 */
function language_uninstall() {
  // Clear variables.
  variable_del('language_default');
  variable_del('language_count');

33
34
35
36
37
38
39
40
41
42
43
44
45
46
  // Clear variables.
  variable_del('language_types');
  variable_del('language_negotiation_url_part');
  variable_del('language_negotiation_url_prefixes');
  variable_del('language_negotiation_url_domains');
  variable_del('language_negotiation_session_param');
  variable_del('language_content_type_default');
  variable_del('language_content_type_negotiation');

  foreach (language_types_get_all() as $type) {
    variable_del("language_negotiation_$type");
    variable_del("language_negotiation_methods_weight_$type");
  }

47
48
49
50
51
52
53
54
55
56
57
58
  // Re-initialize the language system so successive calls to t() and other
  // functions will not expect languages to be present.
  drupal_language_initialize();
}

/**
 * Implements hook_schema().
 */
function language_schema() {
  $schema['language'] = array(
    'description' => 'List of all available languages in the system.',
    'fields' => array(
59
      'langcode' => array(
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
        '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.',
      ),
      '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).',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Weight, used in lists of languages.',
      ),
    ),
92
    'primary key' => array('langcode'),
93
94
95
96
97
98
    'indexes' => array(
      'list' => array('weight', 'name'),
    ),
  );
  return $schema;
}
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

/**
 * Rename {language}.language to {language}.langcode.
 *
 * @see update_prepare_d8_language()
 */
function language_update_8000() {
  // Rename language column to langcode and set it again as the primary key.
  if (db_field_exists('language', 'language')) {
    db_drop_primary_key('language');
    $langcode_spec = array(
      'type' => 'varchar',
      'length' => 12,
      'not null' => TRUE,
      'default' => '',
      'description' => "Language code, e.g. 'de' or 'en-US'.",
    );
    db_change_field('language', 'language', 'langcode', $langcode_spec, array('primary key' => array('langcode')));
  }

  // Update the 'language_default' system variable, if configured.
  $language_default = variable_get('language_default');
  if (!empty($language_default) && isset($language_default->language)) {
    $language_default->langcode = $language_default->language;
    unset($language_default->language);
    variable_set('language_default', $language_default);
  }
}