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
*/
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
use Drupal\Core\File\Exception\FileException ;
use Drupal\Core\File\FileSystemInterface ;
2019-07-24 15:48:42 +00:00
use Drupal\Core\Link ;
2014-09-29 13:41:29 +00:00
use Drupal\Core\Url ;
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' )) {
2020-03-05 11:22:39 +00:00
$site_path = \Drupal :: getContainer () -> getParameter ( 'site.path' );
2015-06-09 12:15:19 +00:00
$directory = $site_path . '/files/translations' ;
2015-01-16 10:43:35 +00:00
\Drupal :: configFactory () -> getEditable ( '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
}
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
\Drupal :: service ( 'file_system' ) -> prepareDirectory ( $directory , FileSystemInterface :: CREATE_DIRECTORY | FileSystemInterface :: MODIFY_PERMISSIONS );
2024-02-18 21:16:53 +00:00
$t_args = [
':translate_status' => base_path () . 'admin/reports/translations/check?destination=' . urlencode ( base_path () . 'admin/reports/translations' ),
];
$message = t ( 'Check <a href=":translate_status">available translations</a> for your language(s).' , $t_args );
\Drupal :: messenger () -> addStatus ( $message );
2012-12-07 18:17:37 +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 () {
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 )) {
2020-05-02 12:07:36 +00:00
$locale_javascripts = \Drupal :: state () -> get ( 'locale.translation.javascript' , []);
Issue #3035312 by kim.pepper, andypost, martin107, yogeshmpawar, naveenvalecha, pguillard, Berdir, dww, claudiu.cristea, jibran, Mile23: Move file_scan_directory() to file_system service
2019-07-24 10:29:08 +00:00
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal :: service ( 'file_system' );
2011-11-09 04:25:48 +00:00
foreach ( $locale_javascripts as $langcode => $file_suffix ) {
if ( ! empty ( $file_suffix )) {
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
try {
Issue #3035312 by kim.pepper, andypost, martin107, yogeshmpawar, naveenvalecha, pguillard, Berdir, dww, claudiu.cristea, jibran, Mile23: Move file_scan_directory() to file_system service
2019-07-24 10:29:08 +00:00
$file_system -> delete ( $locale_js_directory . '/' . $langcode . '_' . $file_suffix . '.js' );
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
}
catch ( FileException $e ) {
// Ignore and continue.
}
2010-06-02 10:25:15 +00:00
}
}
// Delete the JavaScript translations directory if empty.
Issue #3035312 by kim.pepper, andypost, martin107, yogeshmpawar, naveenvalecha, pguillard, Berdir, dww, claudiu.cristea, jibran, Mile23: Move file_scan_directory() to file_system service
2019-07-24 10:29:08 +00:00
if ( is_dir ( $locale_js_directory )) {
if ( ! $file_system -> scanDirectory ( $locale_js_directory , '/.*/' )) {
$file_system -> 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 () {
2017-03-04 01:20:24 +00:00
$schema [ 'locales_source' ] = [
2008-11-15 13:01:11 +00:00
'description' => 'List of English source strings.' ,
2017-03-04 01:20:24 +00:00
'fields' => [
'lid' => [
2007-10-10 11:39:35 +00:00
'type' => 'serial' ,
'not null' => TRUE ,
2008-11-15 13:01:11 +00:00
'description' => 'Unique identifier of this string.' ,
2017-03-04 01:20:24 +00:00
],
'source' => [
2007-10-10 11:39:35 +00:00
'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.' ,
2017-03-04 01:20:24 +00:00
],
'context' => [
2015-05-05 16:42:09 +00:00
'type' => 'varchar_ascii' ,
2009-06-08 05:00:12 +00:00
'length' => 255 ,
'not null' => TRUE ,
'default' => '' ,
'description' => 'The context this string applies to.' ,
2017-03-04 01:20:24 +00:00
],
'version' => [
2015-05-05 16:42:09 +00:00
'type' => 'varchar_ascii' ,
2007-10-10 11:39:35 +00:00
'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).' ,
2017-03-04 01:20:24 +00:00
],
],
'primary key' => [ 'lid' ],
'indexes' => [
'source_context' => [[ 'source' , 30 ], 'context' ],
],
];
2007-10-05 14:43:26 +00:00
2017-03-04 01:20:24 +00:00
$schema [ 'locales_target' ] = [
2008-11-15 13:01:11 +00:00
'description' => 'Stores translated versions of strings.' ,
2017-03-04 01:20:24 +00:00
'fields' => [
'lid' => [
2007-10-10 11:39:35 +00:00
'type' => 'int' ,
'not null' => TRUE ,
'default' => 0 ,
2008-11-15 13:01:11 +00:00
'description' => 'Source string ID. References {locales_source}.lid.' ,
2017-03-04 01:20:24 +00:00
],
'translation' => [
2007-10-10 11:39:35 +00:00
'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.' ,
2017-03-04 01:20:24 +00:00
],
'language' => [
2015-05-05 16:42:09 +00:00
'type' => 'varchar_ascii' ,
2007-10-10 11:39:35 +00:00
'length' => 12 ,
'not null' => TRUE ,
'default' => '' ,
2012-01-10 15:29:08 +00:00
'description' => 'Language code. References {language}.langcode.' ,
2017-03-04 01:20:24 +00:00
],
'customized' => [
2012-04-09 18:24:12 +00:00
'type' => 'int' ,
'not null' => TRUE ,
2017-10-13 12:43:02 +00:00
// LOCALE_NOT_CUSTOMIZED
'default' => 0 ,
2012-04-09 18:24:12 +00:00
'description' => 'Boolean indicating whether the translation is custom to this site.' ,
2017-03-04 01:20:24 +00:00
],
],
'primary key' => [ 'language' , 'lid' ],
'foreign keys' => [
'locales_source' => [
2010-08-22 13:55:53 +00:00
'table' => 'locales_source' ,
2017-03-04 01:20:24 +00:00
'columns' => [ 'lid' => 'lid' ],
],
],
'indexes' => [
'lid' => [ 'lid' ],
],
];
2007-10-05 14:43:26 +00:00
2017-03-04 01:20:24 +00:00
$schema [ 'locales_location' ] = [
2012-10-23 10:25:45 +00:00
'description' => 'Location information for source strings.' ,
2017-03-04 01:20:24 +00:00
'fields' => [
'lid' => [
2012-10-23 10:25:45 +00:00
'type' => 'serial' ,
'not null' => TRUE ,
'description' => 'Unique identifier of this location.' ,
2017-03-04 01:20:24 +00:00
],
'sid' => [
2012-10-23 10:25:45 +00:00
'type' => 'int' ,
'not null' => TRUE ,
'description' => 'Unique identifier of this string.' ,
2017-03-04 01:20:24 +00:00
],
'type' => [
2015-05-05 16:42:09 +00:00
'type' => 'varchar_ascii' ,
2012-10-23 10:25:45 +00:00
'length' => 50 ,
'not null' => TRUE ,
'default' => '' ,
'description' => 'The location type (file, config, path, etc).' ,
2017-03-04 01:20:24 +00:00
],
'name' => [
2012-10-23 10:25:45 +00:00
'type' => 'varchar' ,
'length' => 255 ,
'not null' => TRUE ,
'default' => '' ,
'description' => 'Type dependent location information (file name, path, etc).' ,
2017-03-04 01:20:24 +00:00
],
'version' => [
2015-05-05 16:42:09 +00:00
'type' => 'varchar_ascii' ,
2012-10-23 10:25:45 +00:00
'length' => 20 ,
'not null' => TRUE ,
'default' => 'none' ,
'description' => 'Version of Drupal where the location was found.' ,
2017-03-04 01:20:24 +00:00
],
],
'primary key' => [ 'lid' ],
'foreign keys' => [
'locales_source' => [
2012-10-23 10:25:45 +00:00
'table' => 'locales_source' ,
2017-03-04 01:20:24 +00:00
'columns' => [ 'sid' => 'lid' ],
],
],
'indexes' => [
'string_type' => [ 'sid' , 'type' ],
],
];
2012-10-23 10:25:45 +00:00
2017-03-04 01:20:24 +00:00
$schema [ 'locale_file' ] = [
2012-06-16 15:16:07 +00:00
'description' => 'File import status information for interface translation files.' ,
2017-03-04 01:20:24 +00:00
'fields' => [
'project' => [
2015-05-05 16:42:09 +00:00
'type' => 'varchar_ascii' ,
2012-12-07 18:17:37 +00:00
'length' => '255' ,
'not null' => TRUE ,
'default' => '' ,
'description' => 'A unique short name to identify the project the file belongs to.' ,
2017-03-04 01:20:24 +00:00
],
'langcode' => [
2015-05-05 16:42:09 +00:00
'type' => 'varchar_ascii' ,
2012-06-16 15:16:07 +00:00
'length' => '12' ,
'not null' => TRUE ,
2012-12-07 18:17:37 +00:00
'default' => '' ,
'description' => 'Language code of this translation. References {language}.langcode.' ,
2017-03-04 01:20:24 +00:00
],
'filename' => [
2012-06-16 15:16:07 +00:00
'type' => 'varchar' ,
'length' => 255 ,
'not null' => TRUE ,
'default' => '' ,
2012-12-07 18:17:37 +00:00
'description' => 'Filename of the imported file.' ,
2017-03-04 01:20:24 +00:00
],
'version' => [
2012-12-07 18:17:37 +00:00
'type' => 'varchar' ,
'length' => '128' ,
'not null' => TRUE ,
'default' => '' ,
'description' => 'Version tag of the imported file.' ,
2017-03-04 01:20:24 +00:00
],
'uri' => [
2012-06-16 15:16:07 +00:00
'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.' ,
2017-03-04 01:20:24 +00:00
],
'timestamp' => [
2012-06-16 15:16:07 +00:00
'type' => 'int' ,
'not null' => FALSE ,
'default' => 0 ,
2012-12-07 18:17:37 +00:00
'description' => 'Unix timestamp of the imported file.' ,
Issue #3215062 by quietone, gambry, ravi.shankar, dww, daffie, yogeshmpawar, aarti zikre, alexpott, mfb, larowlan, longwave, catch: Update hook_schema for Y2038
2022-07-23 05:46:46 +00:00
'size' => 'big' ,
2017-03-04 01:20:24 +00:00
],
'last_checked' => [
2012-12-07 18:17:37 +00:00
'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.' ,
Issue #3215062 by quietone, gambry, ravi.shankar, dww, daffie, yogeshmpawar, aarti zikre, alexpott, mfb, larowlan, longwave, catch: Update hook_schema for Y2038
2022-07-23 05:46:46 +00:00
'size' => 'big' ,
2017-03-04 01:20:24 +00:00
],
],
'primary key' => [ 'project' , 'langcode' ],
];
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 ) {
2017-03-04 01:20:24 +00:00
$requirements = [];
2012-12-19 22:11:34 +00:00
if ( $phase == 'runtime' ) {
2017-03-04 01:20:24 +00:00
$available_updates = [];
$untranslated = [];
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 )) {
2014-10-16 13:45:53 +00:00
$untranslated [ $langcode ] = $languages [ $langcode ] -> getName ();
2012-12-19 22:11:34 +00:00
}
elseif ( $project_info -> type == LOCALE_TRANSLATION_LOCAL || $project_info -> type == LOCALE_TRANSLATION_REMOTE ) {
2014-10-16 13:45:53 +00:00
$available_updates [ $langcode ] = $languages [ $langcode ] -> getName ();
2012-12-19 22:11:34 +00:00
}
}
}
2013-06-27 11:25:01 +00:00
if ( $available_updates || $untranslated ) {
2012-12-19 22:11:34 +00:00
if ( $available_updates ) {
2017-03-04 01:20:24 +00:00
$requirements [ 'locale_translation' ] = [
2018-01-11 02:21:12 +00:00
'title' => t ( 'Translation update status' ),
2019-07-24 15:48:42 +00:00
'value' => Link :: fromTextAndUrl ( t ( 'Updates available' ), Url :: fromRoute ( 'locale.translate_status' )) -> toString (),
2012-12-19 22:11:34 +00:00
'severity' => REQUIREMENT_WARNING ,
2019-04-16 05:38:27 +00:00
'description' => t ( 'Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.' , [ '@languages' => implode ( ', ' , $available_updates ), ':updates' => Url :: fromRoute ( 'locale.translate_status' ) -> toString ()]),
2017-03-04 01:20:24 +00:00
];
2012-12-19 22:11:34 +00:00
}
else {
2017-03-04 01:20:24 +00:00
$requirements [ 'locale_translation' ] = [
2018-01-11 02:21:12 +00:00
'title' => t ( 'Translation update status' ),
2012-12-19 22:11:34 +00:00
'value' => t ( 'Missing translations' ),
'severity' => REQUIREMENT_INFO ,
2019-04-16 05:38:27 +00:00
'description' => t ( 'Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.' , [ '@languages' => implode ( ', ' , $untranslated ), ':updates' => Url :: fromRoute ( 'locale.translate_status' ) -> toString ()]),
2017-03-04 01:20:24 +00:00
];
2012-12-19 22:11:34 +00:00
}
}
else {
2017-03-04 01:20:24 +00:00
$requirements [ 'locale_translation' ] = [
2018-01-11 02:21:12 +00:00
'title' => t ( 'Translation update status' ),
2012-12-19 22:11:34 +00:00
'value' => t ( 'Up to date' ),
'severity' => REQUIREMENT_OK ,
2017-03-04 01:20:24 +00:00
];
2012-12-19 22:11:34 +00:00
}
}
else {
2017-03-04 01:20:24 +00:00
$requirements [ 'locale_translation' ] = [
2018-01-11 02:21:12 +00:00
'title' => t ( 'Translation update status' ),
2019-07-24 15:48:42 +00:00
'value' => Link :: fromTextAndUrl ( t ( 'Can not determine status' ), Url :: fromRoute ( 'locale.translate_status' )) -> toString (),
2012-12-19 22:11:34 +00:00
'severity' => REQUIREMENT_WARNING ,
2019-04-16 05:38:27 +00:00
'description' => t ( 'No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.' , [ ':updates' => Url :: fromRoute ( 'locale.translate_status' ) -> toString ()]),
2017-03-04 01:20:24 +00:00
];
2012-12-19 22:11:34 +00:00
}
}
}
return $requirements ;
}
2016-12-19 09:27:43 +00:00
/**
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
* Implements hook_update_last_removed () .
2016-12-19 09:27:43 +00:00
*/
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
function locale_update_last_removed () {
2022-02-08 12:16:18 +00:00
return 9101 ;
2019-10-29 21:01:28 +00:00
}
Issue #3215062 by quietone, gambry, ravi.shankar, dww, daffie, yogeshmpawar, aarti zikre, alexpott, mfb, larowlan, longwave, catch: Update hook_schema for Y2038
2022-07-23 05:46:46 +00:00
/**
* Remove the year 2038 date limitation .
*/
function locale_update_10100 ( & $sandbox = NULL ) {
$connection = \Drupal :: database ();
if ( $connection -> schema () -> tableExists ( 'locale_file' ) && $connection -> databaseType () != 'sqlite' ) {
$new = [
'type' => 'int' ,
'not null' => FALSE ,
'default' => 0 ,
'description' => 'Unix timestamp of the imported file.' ,
'size' => 'big' ,
];
$connection -> schema () -> changeField ( 'locale_file' , 'timestamp' , 'timestamp' , $new );
$new = [
'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.' ,
'size' => 'big' ,
];
$connection -> schema () -> changeField ( 'locale_file' , 'last_checked' , 'last_checked' , $new );
}
}