function install_import_translations
Same name in other branches
- 9 core/includes/install.core.inc \install_import_translations()
- 8.9.x core/includes/install.core.inc \install_import_translations()
- 10 core/includes/install.core.inc \install_import_translations()
Imports languages via a batch process during installation.
Parameters
$install_state: An array of information about the current installation state.
Return value
array|null The batch definition, if there are language files to import.
File
-
core/
includes/ install.core.inc, line 1738
Code
function install_import_translations(&$install_state) {
$module_handler = \Drupal::moduleHandler();
$module_handler->loadInclude('locale', 'inc', 'locale.translation');
// If there is more than one language or the single one is not English, we
// should import translations.
$batch_builder = (new BatchBuilder())->setFile(\Drupal::service('extension.path.resolver')->getPath('module', 'locale') . '/locale.batch.inc');
foreach (install_download_additional_translations_operations($install_state) as $operation) {
$batch_builder->addOperation($operation[0], $operation[1]);
}
$languages = \Drupal::languageManager()->getLanguages();
if (count($languages) > 1 || !isset($languages['en'])) {
$batch_builder->addOperation('_install_prepare_import', [
array_keys($languages),
$install_state['server_pattern'],
]);
// Set up a batch to import translations for drupal core. Translation import
// for contrib modules happens in install_import_translations_remaining.
foreach ($languages as $language) {
if (locale_translation_use_remote_source()) {
$batch_builder->addOperation('locale_translation_batch_fetch_download', [
'drupal',
$language->getId(),
]);
}
$batch_builder->addOperation('locale_translation_batch_fetch_import', [
'drupal',
$language->getId(),
[],
]);
}
$module_handler->loadInclude('locale', 'inc', 'locale.fetch');
$batch_builder->setTitle(t('Updating translations.'))
->setProgressMessage('')
->setErrorMessage(t('Error importing translation files'))
->setFinishCallback('locale_translation_batch_fetch_finished');
return $batch_builder->toArray();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.