You are here

function locale_translate_import_form_submit in Drupal 6

Same name and namespace in other branches
  1. 7 modules/locale/locale.admin.inc \locale_translate_import_form_submit()

Process the locale import form submission.

Related topics

File

includes/locale.inc, line 663
Administration functions for locale.module.

Code

function locale_translate_import_form_submit($form, &$form_state) {

  // Ensure we have the file uploaded
  if ($file = file_save_upload('file')) {

    // Add language, if not yet supported
    $languages = language_list('language', TRUE);
    $langcode = $form_state['values']['langcode'];
    if (!isset($languages[$langcode])) {
      $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 ($ret = _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/build/translate/import';
    return;
  }
  $form_state['redirect'] = 'admin/build/translate';
  return;
}