You are here

function locale_translate_import_form_submit in Drupal 7

Same name and namespace in other branches
  1. 6 includes/locale.inc \locale_translate_import_form_submit()

Process the locale import form submission.

Related topics

File

modules/locale/locale.admin.inc, line 982
Administration functions for locale.module.

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
    drupal_static_reset('language_list');
    $languages = language_list('language');
    $langcode = $form_state['values']['langcode'];
    if (!isset($languages[$langcode])) {
      include_once DRUPAL_ROOT . '/includes/iso.inc';
      $predefined = _locale_get_predefined_list();
      locale_add_language($langcode);
      drupal_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'], $form_state['values']['group']) == FALSE) {
      $variables = array(
        '%filename' => $file->filename,
      );
      drupal_set_message(t('The translation import of %filename failed.', $variables), 'error');
      watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR);
    }
  }
  else {
    drupal_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;
}