274 lines
7.8 KiB
Plaintext
274 lines
7.8 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Install, update and uninstall functions for the locale module.
|
|
*/
|
|
|
|
/**
|
|
* Implement 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.
|
|
|
|
// Create tables.
|
|
drupal_install_schema('locale');
|
|
|
|
db_insert('languages')
|
|
->fields(array(
|
|
'language' => 'en',
|
|
'name' => 'English',
|
|
'native' => 'English',
|
|
'direction' => 0,
|
|
'enabled' => 1,
|
|
'weight' => 0,
|
|
'javascript' => '',
|
|
))
|
|
->execute();
|
|
}
|
|
|
|
/**
|
|
* @defgroup updates-6.x-to-7.x Locale updates from 6.x to 7.x
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* Allow longer location.
|
|
*/
|
|
function locale_update_7000() {
|
|
$ret = array();
|
|
db_drop_index($ret, 'locales_source', 'source');
|
|
db_add_index($ret, 'locales_source', 'source_context', array(array('source', 30), 'context'));
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* @} End of "defgroup updates-6.x-to-7.x"
|
|
*/
|
|
|
|
/**
|
|
* Implement hook_uninstall().
|
|
*/
|
|
function locale_uninstall() {
|
|
// Delete all JavaScript translation files.
|
|
$locale_js_directory = file_create_path(variable_get('locale_js_directory', 'languages'));
|
|
$files = db_query('SELECT language, javascript FROM {languages}');
|
|
foreach ($files as $file) {
|
|
if (!empty($file->javascript)) {
|
|
file_unmanaged_delete(file_create_path($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js'));
|
|
}
|
|
}
|
|
// Delete the JavaScript translations directory if empty.
|
|
@rmdir($locale_js_directory);
|
|
|
|
// Clear variables.
|
|
variable_del('language_default');
|
|
variable_del('language_count');
|
|
variable_del('language_negotiation');
|
|
variable_del('javascript_parsed');
|
|
variable_del('language_content_type_default');
|
|
variable_del('language_content_type_negotiation');
|
|
variable_del('locale_cache_strings');
|
|
variable_del('locale_js_directory');
|
|
|
|
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();
|
|
|
|
// Remove tables.
|
|
drupal_uninstall_schema('locale');
|
|
}
|
|
|
|
/**
|
|
* Implement 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' => 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' => '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(
|
|
'lid' => array('locales_source' => 'lid'),
|
|
),
|
|
'indexes' => array(
|
|
'lid' => array('lid'),
|
|
'plid' => array('plid'),
|
|
'plural' => array('plural'),
|
|
),
|
|
);
|
|
|
|
return $schema;
|
|
}
|
|
|