diff --git a/locale_deploy.install b/locale_deploy.install index 951db72142f3d00558ce61e00d5e509235ed6cf9..8b81c1b75780c40ad830f5a8ca6f48f21f3be3af 100644 --- a/locale_deploy.install +++ b/locale_deploy.install @@ -5,6 +5,9 @@ * Install, update and uninstall functions for the Locale Deploy module. */ +use Drupal\Core\Installer\InstallerKernel; +use Drupal\Core\Language\LanguageInterface; + /** * Implements hook_install(). */ @@ -12,6 +15,24 @@ function locale_deploy_install(bool $is_syncing): void { if (!$is_syncing) { _locale_deploy_config_fix(); } + + // Prevent install_config_download_translations() from doing unnecessary + // downloads during an install. This code is inspired by + // install_find_translations(). + if (InstallerKernel::installationAttempted() && $is_syncing) { + global $install_state; + $files = \Drupal::service('file_system')->scanDirectory('translations://', '!drupal\.' . LanguageInterface::VALID_LANGCODE_REGEX . '\.po$!', ['recurse' => FALSE]); + + foreach ($files as $uri => $file) { + // Strip off the file name component before the language code. + $langcode = preg_replace('!^(.+\.)?([^\.]+)$!', '\2', $file->name); + // Language codes cannot exceed 12 characters to fit into the {language} + // table. + if (strlen($langcode) <= 12) { + $install_state['translations'][$langcode] = $uri; + } + } + } } /**