Chris@0: get('translation.path')) {
Chris@0: $site_path = \Drupal::service('site.path');
Chris@0: $directory = $site_path . '/files/translations';
Chris@0: \Drupal::configFactory()->getEditable('locale.settings')->set('translation.path', $directory)->save();
Chris@0: }
Chris@18: \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Implements hook_uninstall().
Chris@0: */
Chris@0: function locale_uninstall() {
Chris@0: $config = \Drupal::config('locale.settings');
Chris@0: // Delete all JavaScript translation files.
Chris@0: $locale_js_directory = 'public://' . $config->get('javascript.directory');
Chris@0:
Chris@0: if (is_dir($locale_js_directory)) {
Chris@0: $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
Chris@0: foreach ($locale_javascripts as $langcode => $file_suffix) {
Chris@0: if (!empty($file_suffix)) {
Chris@18: try {
Chris@18: \Drupal::service('file_system')->delete($locale_js_directory . '/' . $langcode . '_' . $file_suffix . '.js');
Chris@18: }
Chris@18: catch (FileException $e) {
Chris@18: // Ignore and continue.
Chris@18: }
Chris@0: }
Chris@0: }
Chris@0: // Delete the JavaScript translations directory if empty.
Chris@0: if (!file_scan_directory($locale_js_directory, '/.*/')) {
Chris@18: \Drupal::service('file_system')->rmdir($locale_js_directory);
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: // Clear variables.
Chris@0: \Drupal::state()->delete('system.javascript_parsed');
Chris@0: \Drupal::state()->delete('locale.translation.plurals');
Chris@0: \Drupal::state()->delete('locale.translation.javascript');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Implements hook_schema().
Chris@0: */
Chris@0: function locale_schema() {
Chris@0: $schema['locales_source'] = [
Chris@0: 'description' => 'List of English source strings.',
Chris@0: 'fields' => [
Chris@0: 'lid' => [
Chris@0: 'type' => 'serial',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'Unique identifier of this string.',
Chris@0: ],
Chris@0: 'source' => [
Chris@0: 'type' => 'text',
Chris@0: 'mysql_type' => 'blob',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'The original string in English.',
Chris@0: ],
Chris@0: 'context' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'The context this string applies to.',
Chris@0: ],
Chris@0: 'version' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 20,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => 'none',
Chris@0: 'description' => 'Version of Drupal where the string was last used (for locales optimization).',
Chris@0: ],
Chris@0: ],
Chris@0: 'primary key' => ['lid'],
Chris@0: 'indexes' => [
Chris@0: 'source_context' => [['source', 30], 'context'],
Chris@0: ],
Chris@0: ];
Chris@0:
Chris@0: $schema['locales_target'] = [
Chris@0: 'description' => 'Stores translated versions of strings.',
Chris@0: 'fields' => [
Chris@0: 'lid' => [
Chris@0: 'type' => 'int',
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => 0,
Chris@0: 'description' => 'Source string ID. References {locales_source}.lid.',
Chris@0: ],
Chris@0: 'translation' => [
Chris@0: 'type' => 'text',
Chris@0: 'mysql_type' => 'blob',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'Translation string value in this language.',
Chris@0: ],
Chris@0: 'language' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 12,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Language code. References {language}.langcode.',
Chris@0: ],
Chris@0: 'customized' => [
Chris@0: 'type' => 'int',
Chris@0: 'not null' => TRUE,
Chris@0: // LOCALE_NOT_CUSTOMIZED
Chris@0: 'default' => 0,
Chris@0: 'description' => 'Boolean indicating whether the translation is custom to this site.',
Chris@0: ],
Chris@0: ],
Chris@0: 'primary key' => ['language', 'lid'],
Chris@0: 'foreign keys' => [
Chris@0: 'locales_source' => [
Chris@0: 'table' => 'locales_source',
Chris@0: 'columns' => ['lid' => 'lid'],
Chris@0: ],
Chris@0: ],
Chris@0: 'indexes' => [
Chris@0: 'lid' => ['lid'],
Chris@0: ],
Chris@0: ];
Chris@0:
Chris@0: $schema['locales_location'] = [
Chris@0: 'description' => 'Location information for source strings.',
Chris@0: 'fields' => [
Chris@0: 'lid' => [
Chris@0: 'type' => 'serial',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'Unique identifier of this location.',
Chris@0: ],
Chris@0: 'sid' => [
Chris@0: 'type' => 'int',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'Unique identifier of this string.',
Chris@0: ],
Chris@0: 'type' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 50,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'The location type (file, config, path, etc).',
Chris@0: ],
Chris@0: 'name' => [
Chris@0: 'type' => 'varchar',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Type dependent location information (file name, path, etc).',
Chris@0: ],
Chris@0: 'version' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 20,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => 'none',
Chris@0: 'description' => 'Version of Drupal where the location was found.',
Chris@0: ],
Chris@0: ],
Chris@0: 'primary key' => ['lid'],
Chris@0: 'foreign keys' => [
Chris@0: 'locales_source' => [
Chris@0: 'table' => 'locales_source',
Chris@0: 'columns' => ['sid' => 'lid'],
Chris@0: ],
Chris@0: ],
Chris@0: 'indexes' => [
Chris@0: 'string_id' => ['sid'],
Chris@0: 'string_type' => ['sid', 'type'],
Chris@0: ],
Chris@0: ];
Chris@0:
Chris@0: $schema['locale_file'] = [
Chris@0: 'description' => 'File import status information for interface translation files.',
Chris@0: 'fields' => [
Chris@0: 'project' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => '255',
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'A unique short name to identify the project the file belongs to.',
Chris@0: ],
Chris@0: 'langcode' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => '12',
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Language code of this translation. References {language}.langcode.',
Chris@0: ],
Chris@0: 'filename' => [
Chris@0: 'type' => 'varchar',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Filename of the imported file.',
Chris@0: ],
Chris@0: 'version' => [
Chris@0: 'type' => 'varchar',
Chris@0: 'length' => '128',
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Version tag of the imported file.',
Chris@0: ],
Chris@0: 'uri' => [
Chris@0: 'type' => 'varchar',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'URI of the remote file, the resulting local file or the locally imported file.',
Chris@0: ],
Chris@0: 'timestamp' => [
Chris@0: 'type' => 'int',
Chris@0: 'not null' => FALSE,
Chris@0: 'default' => 0,
Chris@0: 'description' => 'Unix timestamp of the imported file.',
Chris@0: ],
Chris@0: 'last_checked' => [
Chris@0: 'type' => 'int',
Chris@0: 'not null' => FALSE,
Chris@0: 'default' => 0,
Chris@0: 'description' => 'Unix timestamp of the last time this translation was confirmed to be the most recent release available.',
Chris@0: ],
Chris@0: ],
Chris@0: 'primary key' => ['project', 'langcode'],
Chris@0: ];
Chris@0: return $schema;
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Implements hook_requirements().
Chris@0: */
Chris@0: function locale_requirements($phase) {
Chris@0: $requirements = [];
Chris@0: if ($phase == 'runtime') {
Chris@0: $available_updates = [];
Chris@0: $untranslated = [];
Chris@0: $languages = locale_translatable_language_list();
Chris@0:
Chris@0: if ($languages) {
Chris@0: // Determine the status of the translation updates per language.
Chris@0: $status = locale_translation_get_status();
Chris@0: if ($status) {
Chris@0: foreach ($status as $project) {
Chris@0: foreach ($project as $langcode => $project_info) {
Chris@0: if (empty($project_info->type)) {
Chris@0: $untranslated[$langcode] = $languages[$langcode]->getName();
Chris@0: }
Chris@0: elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
Chris@0: $available_updates[$langcode] = $languages[$langcode]->getName();
Chris@0: }
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: if ($available_updates || $untranslated) {
Chris@0: if ($available_updates) {
Chris@0: $requirements['locale_translation'] = [
Chris@14: 'title' => t('Translation update status'),
Chris@0: 'value' => \Drupal::l(t('Updates available'), new Url('locale.translate_status')),
Chris@0: 'severity' => REQUIREMENT_WARNING,
Chris@18: 'description' => t('Updates available for: @languages. See the Available translation updates page for more information.', ['@languages' => implode(', ', $available_updates), ':updates' => Url::fromRoute('locale.translate_status')->toString()]),
Chris@0: ];
Chris@0: }
Chris@0: else {
Chris@0: $requirements['locale_translation'] = [
Chris@14: 'title' => t('Translation update status'),
Chris@0: 'value' => t('Missing translations'),
Chris@0: 'severity' => REQUIREMENT_INFO,
Chris@18: 'description' => t('Missing translations for: @languages. See the Available translation updates page for more information.', ['@languages' => implode(', ', $untranslated), ':updates' => Url::fromRoute('locale.translate_status')->toString()]),
Chris@0: ];
Chris@0: }
Chris@0: }
Chris@0: else {
Chris@0: $requirements['locale_translation'] = [
Chris@14: 'title' => t('Translation update status'),
Chris@0: 'value' => t('Up to date'),
Chris@0: 'severity' => REQUIREMENT_OK,
Chris@0: ];
Chris@0: }
Chris@0: }
Chris@0: else {
Chris@0: $requirements['locale_translation'] = [
Chris@14: 'title' => t('Translation update status'),
Chris@0: 'value' => \Drupal::l(t('Can not determine status'), new Url('locale.translate_status')),
Chris@0: 'severity' => REQUIREMENT_WARNING,
Chris@18: 'description' => t('No translation status is available. See the Available translation updates page for more information.', [':updates' => Url::fromRoute('locale.translate_status')->toString()]),
Chris@0: ];
Chris@0: }
Chris@0: }
Chris@0: }
Chris@0: return $requirements;
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Delete translation status data in state.
Chris@0: */
Chris@0: function locale_update_8300() {
Chris@0: // Delete the old translation status data, it will be rebuilt and stored in
Chris@0: // the new key value collection.
Chris@0: \Drupal::state()->delete('locale.translation_status');
Chris@0: }
Chris@14:
Chris@14: /**
Chris@14: * Update default server pattern value to use https.
Chris@14: */
Chris@14: function locale_update_8500() {
Chris@14: $update_url = \Drupal::config('locale.settings')->get('translation.default_server_pattern');
Chris@14: if ($update_url == 'http://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po') {
Chris@14: \Drupal::configFactory()->getEditable('locale.settings')
Chris@14: ->set('translation.default_server_pattern', 'https://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po')
Chris@14: ->save();
Chris@14: }
Chris@14: }