View source
<?php
function locale_install() {
drupal_install_schema('locale');
db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1', '0', '')");
}
function locale_update_6000() {
$ret = array();
$schema['languages'] = array(
'fields' => array(
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'native' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'direction' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'enabled' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'plurals' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'formula' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'domain' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'prefix' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'javascript' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'language',
),
'indexes' => array(
'list' => array(
'weight',
'name',
),
),
);
db_create_table($ret, 'languages', $schema['languages']);
$ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, name, 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}");
$count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1'));
variable_set('language_count', $count);
$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;
}
function locale_update_6001() {
$ret = array();
$ret[] = update_sql('UPDATE {locales_target} SET language = locale');
db_drop_field($ret, 'locales_target', 'locale');
return $ret;
}
function locale_update_6002() {
$ret = array();
$ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''");
return $ret;
}
function locale_update_6003() {
$ret = array();
$ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN (SELECT lid FROM {locales_target})");
return $ret;
}
function locale_update_6004() {
$ret = array();
db_add_index($ret, 'locales_target', 'language', array(
'language',
));
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_drop_index($ret, 'locales_source', 'source');
db_add_index($ret, 'locales_source', 'source', array(
array(
'source',
30,
),
));
break;
}
return $ret;
}
function locale_update_6005() {
foreach (node_get_types() as $type => $content_type) {
$setting = variable_get('language_' . $type, NULL);
if ($type == 'default' && is_numeric($setting)) {
variable_set('language_content_type_default', $setting);
variable_del('language_default');
drupal_set_message('The default language setting has been reset to its default value. Check the ' . l('language configuration page', 'admin/settings/language') . ' to configure it correctly.');
}
elseif ($type == 'negotiation') {
variable_set('language_content_type_negotiation', $setting);
drupal_set_message('The language negotiation setting was possibly overwritten by a content type of the same name. Check the ' . l('language configuration page', 'admin/settings/language/configure') . ' and the ' . l('<em>' . $content_type->name . "</em> content type's multilingual support settings", 'admin/content/types/negotiation', array(
'html' => TRUE,
)) . ' to configure them correctly.');
}
elseif (!is_null($setting)) {
variable_set('language_content_type_' . $type, $setting);
variable_del('language_' . $type);
}
}
$count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1'));
variable_set('language_count', $count);
return array();
}
function locale_update_6006() {
$ret = array();
$matches = db_result(db_query("SELECT 1 FROM {languages} WHERE native LIKE '%<%' OR native LIKE '%>%' OR name LIKE '%<%' OR name LIKE '%>%'"));
if ($matches) {
$ret[] = update_sql("UPDATE {languages} SET name = REPLACE(name, '<', ''), native = REPLACE(native, '<', '')");
$ret[] = update_sql("UPDATE {languages} SET name = REPLACE(name, '>', ''), native = REPLACE(native, '>', '')");
drupal_set_message('The language name in English and the native language name values of all the existing custom languages of your site have been sanitized for security purposes. Visit the <a href="' . url('admin/settings/language') . '">Languages</a> page to check these and fix them if necessary.', 'warning');
}
if (db_result(db_query("SELECT 1 FROM {languages} WHERE language LIKE '%<%' OR language LIKE '%>%' OR language LIKE '%\"%' OR language LIKE '%\\\\\\%'"))) {
drupal_set_message('Some of your custom language code values contain invalid characters. You should examine the <a href="' . url('admin/settings/language') . '">Languages</a> page. These must be fixed manually.', 'error');
}
return $ret;
}
function locale_update_6007() {
drupal_load('module', 'locale');
locale_inc_callback('_locale_invalidate_js');
return array();
}
function locale_uninstall() {
$files = db_query('SELECT javascript FROM {languages}');
while ($file = db_fetch_object($files)) {
if (!empty($file)) {
file_delete(file_create_path($file->javascript));
}
}
variable_del('language_default');
variable_del('language_count');
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('language_negotiation');
foreach (node_get_types() as $type => $content_type) {
variable_del("language_content_type_{$type}");
}
drupal_init_language();
drupal_uninstall_schema('locale');
}
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' => 32,
'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' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'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.',
),
'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' => array(
array(
'source',
30,
),
),
),
);
$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,
'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',
),
'indexes' => array(
'lid' => array(
'lid',
),
'plid' => array(
'plid',
),
'plural' => array(
'plural',
),
),
);
return $schema;
}