2006-07-13 13:14:25 +00:00
|
|
|
<?php
|
|
|
|
|
2009-05-13 19:42:18 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Install, update and uninstall functions for the locale module.
|
|
|
|
*/
|
|
|
|
|
2012-01-23 00:46:31 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
2012-02-08 14:51:31 +00:00
|
|
|
$provider = $info[LANGUAGE_NEGOTIATION_URL];
|
2012-01-23 00:46:31 +00:00
|
|
|
$provider_fields = array('callbacks', 'file', 'cache');
|
|
|
|
$negotiation = array();
|
|
|
|
|
|
|
|
// Store only the needed data.
|
|
|
|
foreach ($provider_fields as $field) {
|
|
|
|
if (isset($provider[$field])) {
|
2012-02-08 14:51:31 +00:00
|
|
|
$negotiation[LANGUAGE_NEGOTIATION_URL][$field] = $provider[$field];
|
2012-01-23 00:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable URL language detection for each (core) configurable language type.
|
2012-02-21 15:44:11 +00:00
|
|
|
foreach (language_types_get_configurable() as $type) {
|
2012-01-23 00:46:31 +00:00
|
|
|
variable_set("language_negotiation_$type", $negotiation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-01 07:40:08 +00:00
|
|
|
/**
|
2011-12-22 11:26:12 +00:00
|
|
|
* 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.
|
2006-09-01 07:40:08 +00:00
|
|
|
*/
|
2011-12-22 11:26:12 +00:00
|
|
|
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);
|
2006-07-13 13:14:25 +00:00
|
|
|
}
|
2006-09-01 07:40:08 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_uninstall().
|
2006-09-01 07:40:08 +00:00
|
|
|
*/
|
|
|
|
function locale_uninstall() {
|
2009-02-13 00:45:18 +00:00
|
|
|
// Delete all JavaScript translation files.
|
2009-08-17 19:14:42 +00:00
|
|
|
$locale_js_directory = 'public://' . variable_get('locale_js_directory', 'languages');
|
2010-06-02 10:25:15 +00:00
|
|
|
|
|
|
|
if (is_dir($locale_js_directory)) {
|
2011-11-09 04:25:48 +00:00
|
|
|
$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');
|
2010-06-02 10:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Delete the JavaScript translations directory if empty.
|
|
|
|
if (!file_scan_directory($locale_js_directory, '/.*/')) {
|
2010-08-17 22:05:22 +00:00
|
|
|
drupal_rmdir($locale_js_directory);
|
2007-06-08 12:51:59 +00:00
|
|
|
}
|
2009-12-10 15:39:43 +00:00
|
|
|
}
|
2009-05-24 17:39:35 +00:00
|
|
|
|
2009-02-13 00:45:18 +00:00
|
|
|
// Clear variables.
|
2009-10-09 16:33:14 +00:00
|
|
|
variable_del('language_types');
|
|
|
|
variable_del('locale_language_negotiation_url_part');
|
2011-11-29 02:23:49 +00:00
|
|
|
variable_del('locale_language_negotiation_url_prefixes');
|
|
|
|
variable_del('locale_language_negotiation_url_domains');
|
2009-10-09 16:33:14 +00:00
|
|
|
variable_del('locale_language_negotiation_session_param');
|
2009-02-13 00:45:18 +00:00
|
|
|
variable_del('language_content_type_default');
|
|
|
|
variable_del('language_content_type_negotiation');
|
|
|
|
variable_del('locale_cache_strings');
|
|
|
|
variable_del('locale_js_directory');
|
2009-10-09 16:33:14 +00:00
|
|
|
variable_del('javascript_parsed');
|
2010-03-25 11:46:21 +00:00
|
|
|
variable_del('locale_field_language_fallback');
|
2010-07-29 02:31:40 +00:00
|
|
|
variable_del('locale_cache_length');
|
2011-11-09 04:25:48 +00:00
|
|
|
variable_del('locale_translation_plurals');
|
|
|
|
variable_del('locale_translation_javascript');
|
2009-10-09 16:33:14 +00:00
|
|
|
|
2012-02-21 15:44:11 +00:00
|
|
|
foreach (language_types_get_all() as $type) {
|
2009-10-09 16:33:14 +00:00
|
|
|
variable_del("language_negotiation_$type");
|
|
|
|
variable_del("locale_language_providers_weight_$type");
|
|
|
|
}
|
2009-05-24 17:39:35 +00:00
|
|
|
|
2012-01-08 07:14:15 +00:00
|
|
|
// 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();
|
2006-09-01 07:40:08 +00:00
|
|
|
}
|
2007-10-05 14:43:26 +00:00
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_schema().
|
2007-10-05 14:43:26 +00:00
|
|
|
*/
|
|
|
|
function locale_schema() {
|
|
|
|
$schema['locales_source'] = array(
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'List of English source strings.',
|
2007-10-05 14:43:26 +00:00
|
|
|
'fields' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'lid' => array(
|
|
|
|
'type' => 'serial',
|
|
|
|
'not null' => TRUE,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Unique identifier of this string.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
|
|
|
'location' => array(
|
2009-05-27 19:54:21 +00:00
|
|
|
'type' => 'text',
|
|
|
|
'not null' => FALSE,
|
|
|
|
'size' => 'big',
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
|
|
|
'source' => array(
|
|
|
|
'type' => 'text',
|
2009-04-20 02:23:17 +00:00
|
|
|
'mysql_type' => 'blob',
|
2007-10-10 11:39:35 +00:00
|
|
|
'not null' => TRUE,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'The original string in English.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
2009-06-08 05:00:12 +00:00
|
|
|
'context' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 255,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
|
|
|
'description' => 'The context this string applies to.',
|
|
|
|
),
|
2007-10-10 11:39:35 +00:00
|
|
|
'version' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 20,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 'none',
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
),
|
|
|
|
'primary key' => array('lid'),
|
2007-12-18 12:59:22 +00:00
|
|
|
'indexes' => array(
|
2009-06-08 05:00:12 +00:00
|
|
|
'source_context' => array(array('source', 30), 'context'),
|
2007-12-18 12:59:22 +00:00
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$schema['locales_target'] = array(
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Stores translated versions of strings.',
|
2007-10-05 14:43:26 +00:00
|
|
|
'fields' => array(
|
2007-10-10 11:39:35 +00:00
|
|
|
'lid' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Source string ID. References {locales_source}.lid.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
|
|
|
'translation' => array(
|
|
|
|
'type' => 'text',
|
2009-04-20 02:23:17 +00:00
|
|
|
'mysql_type' => 'blob',
|
2007-10-10 11:39:35 +00:00
|
|
|
'not null' => TRUE,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Translation string value in this language.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
|
|
|
'language' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 12,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
2012-01-10 15:29:08 +00:00
|
|
|
'description' => 'Language code. References {language}.langcode.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
|
|
|
'plid' => array(
|
|
|
|
'type' => 'int',
|
2007-12-18 12:59:22 +00:00
|
|
|
'not null' => TRUE, // This should be NULL for no referenced string, not zero.
|
2007-10-10 11:39:35 +00:00
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
|
|
|
'plural' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-11-15 13:01:11 +00:00
|
|
|
'description' => 'Plural index number in case of plural strings.',
|
2007-10-10 11:39:35 +00:00
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
),
|
2007-12-18 12:59:22 +00:00
|
|
|
'primary key' => array('language', 'lid', 'plural'),
|
2009-06-01 22:07:10 +00:00
|
|
|
'foreign keys' => array(
|
2010-08-22 13:55:53 +00:00
|
|
|
'locales_source' => array(
|
|
|
|
'table' => 'locales_source',
|
|
|
|
'columns' => array('lid' => 'lid'),
|
|
|
|
),
|
2009-06-01 22:07:10 +00:00
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
'indexes' => array(
|
2007-12-18 12:59:22 +00:00
|
|
|
'lid' => array('lid'),
|
|
|
|
'plid' => array('plid'),
|
|
|
|
'plural' => array('plural'),
|
2007-10-05 14:43:26 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|
2011-10-26 07:48:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup updates-7.x-to-8.x
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-11-25 03:19:32 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-12-22 11:26:12 +00:00
|
|
|
function locale_update_8000() {
|
2011-11-25 03:19:32 +00:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2012-02-22 13:37:04 +00:00
|
|
|
/**
|
|
|
|
* Language type 'language' renamed to 'language_interface'.
|
|
|
|
*/
|
|
|
|
function locale_update_8001() {
|
|
|
|
// Only change language_types if we had this setting saved. Keep order
|
|
|
|
// of types because that is significant for value dependency.
|
|
|
|
$types = variable_get('language_types', NULL);
|
|
|
|
if (!empty($types) && isset($types['language'])) {
|
|
|
|
$new_types = array();
|
|
|
|
foreach ($types as $key => $type) {
|
|
|
|
$new_types[$key == 'language' ? 'language_interface' : $key] = $type;
|
|
|
|
}
|
|
|
|
variable_set('language_types', $new_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rename language_negotiation_language setting if exists.
|
|
|
|
$setting = variable_get('language_negotiation_language', NULL);
|
|
|
|
if ($setting !== NULL) {
|
|
|
|
variable_set('language_negotiation_language_interface', $setting);
|
|
|
|
variable_del('language_negotiation_language');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rename locale_language_providers_weight_language setting if exists.
|
|
|
|
$weight = variable_get('locale_language_providers_weight_language', NULL);
|
|
|
|
if ($weight !== NULL) {
|
|
|
|
variable_set('locale_language_providers_weight_language_interface', $weight);
|
|
|
|
variable_del('locale_language_providers_weight_language');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update block data in all core block related tables. Contributed modules
|
|
|
|
// storing data for blocks will need to update for themselves.
|
|
|
|
$block_tables = array('block', 'block_node_type', 'block_role');
|
|
|
|
foreach ($block_tables as $table) {
|
2012-02-28 06:29:03 +00:00
|
|
|
// Perform the update only if the language switcher block data is available.
|
|
|
|
$block_data = db_query_range('SELECT 1 FROM {' . $table . '} WHERE delta = :delta AND module = :module', 0, 1, array(':delta' => 'language', ':module' => 'locale'))
|
|
|
|
->fetchField();
|
|
|
|
if ($block_data) {
|
|
|
|
// If block information is rebuilt before performing the update, we might
|
|
|
|
// already have data for the new delta. In this case we need to remove it
|
|
|
|
// to avoid integrity constraint violation errors.
|
|
|
|
db_delete($table)
|
|
|
|
->condition('delta', 'language_interface')
|
|
|
|
->condition('module', 'locale')
|
|
|
|
->execute();
|
|
|
|
db_update($table)
|
|
|
|
->fields(array(
|
|
|
|
'delta' => 'language_interface',
|
|
|
|
))
|
|
|
|
->condition('delta', 'language')
|
|
|
|
->condition('module', 'locale')
|
|
|
|
->execute();
|
|
|
|
}
|
2012-02-22 13:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-26 07:48:38 +00:00
|
|
|
/**
|
|
|
|
* @} End of "addtogroup updates-7.x-to-8.x"
|
|
|
|
* The next series of updates should start at 9000.
|
|
|
|
*/
|