2006-07-13 13:14:25 +00:00
<?php
2009-05-13 19:42:18 +00:00
/**
* @file
2012-10-05 15:42:46 +00:00
* Install, update, and uninstall functions for the Locale module.
2009-05-13 19:42:18 +00:00
*/
2014-09-29 13:41:29 +00:00
use Drupal\Core\Url;
2013-05-25 20:12:45 +00:00
use Drupal\Core\Language\Language;
Issue #1862202 by plach, Berdir, katbailey, ParisLiakos, alexpott, chx, sun, larowlan, Gábor Hojtsy, cosmicdreams, vijaycs85, YesCT, penyaskito, andypost, Albert Volkman, joelpitett: Objectify the language system.
2014-01-15 16:27:37 +00:00
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected;
2013-05-25 20:12:45 +00:00
2012-12-07 18:17:37 +00:00
/**
* Implements hook_install().
*/
function locale_install() {
// Create the interface translations directory and ensure it's writable.
2013-09-16 03:58:06 +00:00
if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) {
Issue #1496480 by mrf, disasm, kbasarab, pfrenssen, cam8001, typhonius, Letharion, ACF, vijaycs85, heyrocker, Berdir, alexpott: Convert file system settings to the new configuration system.
2013-02-08 23:36:06 +00:00
$directory = conf_path() . '/files/translations';
2013-09-16 03:58:06 +00:00
\Drupal::config('locale.settings')->set('translation.path', $directory)->save();
Issue #1496480 by mrf, disasm, kbasarab, pfrenssen, cam8001, typhonius, Letharion, ACF, vijaycs85, heyrocker, Berdir, alexpott: Convert file system settings to the new configuration system.
2013-02-08 23:36:06 +00:00
}
2012-12-07 18:17:37 +00:00
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
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() {
2013-09-16 03:58:06 +00:00
$config = \Drupal::config('locale.settings');
2009-02-13 00:45:18 +00:00
// Delete all JavaScript translation files.
2013-02-15 02:40:03 +00:00
$locale_js_directory = 'public://' . $config->get('javascript.directory');
2010-06-02 10:25:15 +00:00
if (is_dir($locale_js_directory)) {
2013-09-16 03:58:06 +00:00
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array();
2011-11-09 04:25:48 +00:00
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.
2013-09-16 03:58:06 +00:00
\Drupal::state()->delete('system.javascript_parsed');
\Drupal::state()->delete('locale.translation.plurals');
\Drupal::state()->delete('locale.translation.javascript');
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
),
'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',
2012-10-23 10:25:45 +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
),
2012-04-09 18:24:12 +00:00
'customized' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0, // LOCALE_NOT_CUSTOMIZED
'description' => 'Boolean indicating whether the translation is custom to this site.',
),
2007-10-05 14:43:26 +00:00
),
2012-03-11 02:35:21 +00:00
'primary key' => array('language', 'lid'),
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(
2014-07-21 10:52:00 +00:00
'lid' => array('lid'),
2007-10-05 14:43:26 +00:00
),
);
2012-10-23 10:25:45 +00:00
$schema['locales_location'] = array(
'description' => 'Location information for source strings.',
'fields' => array(
'lid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Unique identifier of this location.',
),
'sid' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Unique identifier of this string.',
),
'type' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
'description' => 'The location type (file, config, path, etc).',
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Type dependent location information (file name, path, etc).',
),
'version' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'default' => 'none',
'description' => 'Version of Drupal where the location was found.',
),
),
'primary key' => array('lid'),
'foreign keys' => array(
'locales_source' => array(
'table' => 'locales_source',
'columns' => array('sid' => 'lid'),
),
),
'indexes' => array(
2014-07-21 10:52:00 +00:00
'string_id' => array('sid'),
'string_type' => array('sid', 'type'),
2012-10-23 10:25:45 +00:00
),
);
2012-06-16 15:16:07 +00:00
$schema['locale_file'] = array(
'description' => 'File import status information for interface translation files.',
'fields' => array(
2012-12-07 18:17:37 +00:00
'project' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'A unique short name to identify the project the file belongs to.',
),
2012-06-16 15:16:07 +00:00
'langcode' => array(
'type' => 'varchar',
'length' => '12',
'not null' => TRUE,
2012-12-07 18:17:37 +00:00
'default' => '',
'description' => 'Language code of this translation. References {language}.langcode.',
2012-06-16 15:16:07 +00:00
),
'filename' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2012-12-07 18:17:37 +00:00
'description' => 'Filename of the imported file.',
),
'version' => array(
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
'description' => 'Version tag of the imported file.',
2012-06-16 15:16:07 +00:00
),
'uri' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2012-12-07 18:17:37 +00:00
'description' => 'URI of the remote file, the resulting local file or the locally imported file.',
2012-06-16 15:16:07 +00:00
),
'timestamp' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
2012-12-07 18:17:37 +00:00
'description' => 'Unix timestamp of the imported file.',
),
'last_checked' => array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'description' => 'Unix timestamp of the last time this translation was confirmed to be the most recent release available.',
2012-06-16 15:16:07 +00:00
),
),
2012-12-07 18:17:37 +00:00
'primary key' => array('project', 'langcode'),
2012-06-16 15:16:07 +00:00
);
2007-10-05 14:43:26 +00:00
return $schema;
}
2011-10-26 07:48:38 +00:00
2012-12-19 22:11:34 +00:00
/**
* Implements hook_requirements().
*/
function locale_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$available_updates = array();
2013-06-27 11:25:01 +00:00
$untranslated = array();
2012-12-19 22:11:34 +00:00
$languages = locale_translatable_language_list();
if ($languages) {
2013-09-12 14:01:59 +00:00
// Determine the status of the translation updates per language.
2013-06-27 11:25:01 +00:00
$status = locale_translation_get_status();
2012-12-19 22:11:34 +00:00
if ($status) {
2013-10-15 05:00:09 +00:00
foreach ($status as $project) {
2012-12-19 22:11:34 +00:00
foreach ($project as $langcode => $project_info) {
2013-06-27 11:25:01 +00:00
if (empty($project_info->type)) {
$untranslated[$langcode] = $languages[$langcode]->name;
2012-12-19 22:11:34 +00:00
}
elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
$available_updates[$langcode] = $languages[$langcode]->name;
}
}
}
2013-06-27 11:25:01 +00:00
if ($available_updates || $untranslated) {
2012-12-19 22:11:34 +00:00
if ($available_updates) {
$requirements['locale_translation'] = array(
'title' => 'Translation update status',
2014-09-29 13:41:29 +00:00
'value' => \Drupal::l(t('Updates available'), new Url('locale.translate_status')),
2012-12-19 22:11:34 +00:00
'severity' => REQUIREMENT_WARNING,
2014-09-27 07:03:46 +00:00
'description' => t('Updates available for: @languages. See the <a href="@updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $available_updates), '@updates' => \Drupal::url('locale.translate_status'))),
2012-12-19 22:11:34 +00:00
);
}
else {
$requirements['locale_translation'] = array(
'title' => 'Translation update status',
'value' => t('Missing translations'),
'severity' => REQUIREMENT_INFO,
2014-09-27 07:03:46 +00:00
'description' => t('Missing translations for: @languages. See the <a href="@updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $untranslated), '@updates' => \Drupal::url('locale.translate_status'))),
2012-12-19 22:11:34 +00:00
);
}
}
else {
$requirements['locale_translation'] = array(
'title' => 'Translation update status',
'value' => t('Up to date'),
'severity' => REQUIREMENT_OK,
);
}
}
else {
$requirements['locale_translation'] = array(
'title' => 'Translation update status',
2014-09-29 13:41:29 +00:00
'value' => \Drupal::l(t('Can not determine status'), new Url('locale.translate_status')),
2012-12-19 22:11:34 +00:00
'severity' => REQUIREMENT_WARNING,
2014-09-27 07:03:46 +00:00
'description' => t('No translation status is available. See the <a href="@updates">Available translation updates</a> page for more information.', array('@updates' => \Drupal::url('locale.translate_status'))),
2012-12-19 22:11:34 +00:00
);
}
}
}
return $requirements;
}