1 locale.bulk.inc locale_translate_import_form_submit($form, &$form_state)

Process the locale import form submission.

File

core/modules/locale/locale.bulk.inc, line 73
Mass import-export and batch import functionality for Gettext .po files.

Code

function locale_translate_import_form_submit($form, &$form_state) {
  $validators = array('file_validate_extensions' => array('po'));
  // Ensure we have the file uploaded
  if ($file = file_save_upload('file', $validators)) {

    // Add language, if not yet supported
    backdrop_static_reset('language_list');
    $languages = language_list();
    $langcode = $form_state['values']['langcode'];
    if (!isset($languages[$langcode])) {
      include_once BACKDROP_ROOT . '/core/includes/standard.inc';
      $predefined = standard_language_list();
      $language = (object) array(
        'langcode' => $langcode,
      );
      language_save($language);
      backdrop_set_message(t('The language %language has been created.', array('%language' => t($predefined[$langcode][0]))));
    }

    // Now import strings into the language
    if ($return = _locale_import_po($file, $langcode, $form_state['values']['mode']) == FALSE) {
      $variables = array('%filename' => $file->filename);
      backdrop_set_message(t('The translation import of %filename failed.', $variables), 'error');
      watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR);
    }
  }
  else {
    backdrop_set_message(t('File to import not found.'), 'error');
    $form_state['redirect'] = 'admin/config/regional/translate/import';
    return;
  }

  $form_state['redirect'] = 'admin/config/regional/translate';
  return;
}