Skip to content
Snippets Groups Projects

Prevent installer downloading translations unnecessarily

1 file
+ 21
0
Compare changes
  • Side-by-side
  • Inline
+ 21
0
@@ -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;
}
}
}
}
/**
Loading