Imports languages via a batch process during installation.
$install_state: An array of information about the current installation state.
The batch definition, if there are language files to import.
function install_import_translations(&$install_state) {
include_once __DIR__ . '/../modules/locale/locale.bulk.inc';
$langcode = $install_state['parameters']['langcode'];
$standard_languages = LanguageManager::getStandardLanguageList();
if (!isset($standard_languages[$langcode])) {
// Drupal does not know about this language, so we prefill its values with
// our best guess. The user will be able to edit afterwards.
$language = new Language(array(
'langcode' => $langcode,
'name' => $langcode,
'default' => TRUE,
));
language_save($language);
}
else {
// A known predefined language, details will be filled in properly.
$language = new Language(array(
'langcode' => $langcode,
'default' => TRUE,
));
language_save($language);
}
// If a non-English language was selected, remove English and import the
// translations.
if ($langcode != 'en') {
language_delete('en');
// Set up a batch to import translations for the newly added language.
_install_prepare_import();
module_load_include('fetch.inc', 'locale');
if ($batch = locale_translation_batch_fetch_build(array(), array(
$langcode,
))) {
return $batch;
}
}
}