238 lines
7.6 KiB
Plaintext
238 lines
7.6 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Install, update and uninstall functions for the locale module.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_install().
|
|
*
|
|
* Enable URL language negotiation by default in order to have a basic working
|
|
* system on multilingual sites without needing any preliminary configuration.
|
|
*/
|
|
function locale_install() {
|
|
require_once DRUPAL_ROOT . '/core/includes/language.inc';
|
|
|
|
// We cannot rely on language negotiation hooks here, because locale module is
|
|
// not enabled yet. Therefore language_negotiation_set() cannot be used.
|
|
$info = locale_language_negotiation_info();
|
|
$provider = $info[LOCALE_LANGUAGE_NEGOTIATION_URL];
|
|
$provider_fields = array('callbacks', 'file', 'cache');
|
|
$negotiation = array();
|
|
|
|
// Store only the needed data.
|
|
foreach ($provider_fields as $field) {
|
|
if (isset($provider[$field])) {
|
|
$negotiation[LOCALE_LANGUAGE_NEGOTIATION_URL][$field] = $provider[$field];
|
|
}
|
|
}
|
|
|
|
// Enable URL language detection for each (core) configurable language type.
|
|
foreach (language_types_configurable() as $type) {
|
|
variable_set("language_negotiation_$type", $negotiation);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fill in the path prefixes and domains when enabled.
|
|
*
|
|
* Language module might change the list of languages, so we need to sync our
|
|
* configuration for domains and paths with the current language list. This
|
|
* should run every time the module is enabled.
|
|
*/
|
|
function locale_enable() {
|
|
require_once DRUPAL_ROOT . '/core/includes/locale.inc';
|
|
|
|
$languages = language_list();
|
|
$prefixes_old = locale_language_negotiation_url_prefixes();
|
|
$domains_old = locale_language_negotiation_url_domains();
|
|
|
|
$prefixes = array();
|
|
$domains = array();
|
|
foreach ($languages as $langcode => $language) {
|
|
// Keep the old prefix or fill in based on whether the language is default.
|
|
$prefixes[$langcode] = empty($prefixes_old[$langcode]) ? (empty($language->default) ? $langcode : '') : $prefixes_old[$langcode];
|
|
// Keep the old domain or fill in empty value.
|
|
$domains[$langcode] = empty($domains_old[$langcode]) ? '' : $domains_old[$langcode];
|
|
}
|
|
|
|
locale_language_negotiation_url_prefixes_save($prefixes);
|
|
locale_language_negotiation_url_domains_save($domains);
|
|
}
|
|
|
|
/**
|
|
* 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)) {
|
|
$locale_javascripts = variable_get('locale_translation_javascript', array());
|
|
foreach ($locale_javascripts as $langcode => $file_suffix) {
|
|
if (!empty($file_suffix)) {
|
|
file_unmanaged_delete($locale_js_directory . '/' . $langcode . '_' . $file_suffix . '.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_types');
|
|
variable_del('locale_language_negotiation_url_part');
|
|
variable_del('locale_language_negotiation_url_prefixes');
|
|
variable_del('locale_language_negotiation_url_domains');
|
|
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');
|
|
variable_del('locale_translation_plurals');
|
|
variable_del('locale_translation_javascript');
|
|
|
|
foreach (language_types() as $type) {
|
|
variable_del("language_negotiation_$type");
|
|
variable_del("locale_language_providers_weight_$type");
|
|
}
|
|
|
|
// Remove all node type language variables. Node module might have been
|
|
// enabled, but may be disabled, so use a wildcard delete.
|
|
db_delete('variable')
|
|
->condition('name', db_like('language_content_type_') . '%', 'LIKE')
|
|
->execute();
|
|
}
|
|
|
|
/**
|
|
* Implements hook_schema().
|
|
*/
|
|
function locale_schema() {
|
|
$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.',
|
|
),
|
|
'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 {language}.langcode.',
|
|
),
|
|
'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;
|
|
}
|
|
|
|
/**
|
|
* @addtogroup updates-7.x-to-8.x
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* Drop textgroup support.
|
|
*
|
|
* Update assumes i18n migrated this data before the update happened. Core
|
|
* never used textgroups for anything, so it is not our job to find place
|
|
* for the data elsewhere.
|
|
*/
|
|
function locale_update_8000() {
|
|
$subquery = db_select('locales_source', 'ls')
|
|
->fields('ls', array('lid'))
|
|
->condition('ls.textgroup', 'default', '<>');
|
|
db_delete('locales_target')
|
|
->condition('lid', $subquery, 'IN')
|
|
->execute();
|
|
db_delete('locales_source')
|
|
->condition('textgroup', 'default', '<>')
|
|
->execute();
|
|
db_drop_field('locales_source', 'textgroup');
|
|
}
|
|
|
|
/**
|
|
* @} End of "addtogroup updates-7.x-to-8.x"
|
|
* The next series of updates should start at 9000.
|
|
*/
|