You are here

function l10n_update_import_form_submit in Localization update 7.2

Form submission handler for l10n_update_import_form().

File

./l10n_update.bulk.inc, line 104
Mass import-export and batch import functionality for Gettext .po files.

Code

function l10n_update_import_form_submit($form, &$form_state) {

  // Ensure we have the file uploaded.
  if ($file = file_save_upload('file', $form_state, $form['file']['#upload_validators'], 'translations://', 0)) {

    // Add language, if not yet supported.
    $language = language_load($form_state['values']['langcode']);
    if (empty($language)) {
      $language = new Language(array(
        'id' => $form_state['values']['langcode'],
      ));
      $language = language_save($language);
      drupal_set_message(t('The language %language has been created.', array(
        '%language' => t($language->name),
      )));
    }
    $options = array(
      'langcode' => $form_state['values']['langcode'],
      'overwrite_options' => $form_state['values']['overwrite_options'],
      'customized' => $form_state['values']['customized'] ? L10N_UPDATE_CUSTOMIZED : L10N_UPDATE_NOT_CUSTOMIZED,
    );
    $file = l10n_update_file_attach_properties($file, $options);
    $batch = l10n_update_batch_build(array(
      $file->uri => $file,
    ), $options);
    batch_set($batch);
  }
  else {
    form_set_error('file', $form_state, t('File to import not found.'));
    $form_state['rebuild'] = TRUE;
  }
  $form_state['redirect_route']['route_name'] = 'locale.translate_page';
}