You are here

function l10n_update_export_form_submit in Localization update 7.2

Form submission handler for l10n_update_export_form().

File

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

Code

function l10n_update_export_form_submit($form, &$form_state) {
  global $language;

  // If template is required, language code is not given.
  if ($form_state['values']['langcode'] != $language->language) {
    $languages = language_list();
    $language = isset($languages[$form_state['values']['langcode']]) ? $languages[$form_state['values']['langcode']] : NULL;
  }
  else {
    $language = NULL;
  }
  $content_options = isset($form_state['values']['content_options']) ? $form_state['values']['content_options'] : array();
  $textgroup = isset($form_state['values']['textgroup']) ? $form_state['values']['textgroup'] : NULL;
  $reader = new PoDatabaseReader();
  $languageName = '';
  if ($language != NULL) {
    $reader
      ->setLangcode($language->id);
    $reader
      ->setOptions($content_options);
    $reader
      ->setTextgroup($textgroup);
    $languages = language_list();
    $languageName = isset($languages[$language->id]) ? $languages[$language->id]->name : '';
    $filename = $language->id . '.po';
  }
  else {

    // Template required.
    $filename = 'drupal.pot';
  }
  $item = $reader
    ->readItem();
  if (!empty($item)) {
    $uri = tempnam('temporary://', 'po_');
    $header = $reader
      ->getHeader();
    $header
      ->setProjectName(variable_get('site_name'));
    $header
      ->setLanguageName($languageName);
    $writer = new PoStreamWriter();
    $writer
      ->setUri($uri);
    $writer
      ->setHeader($header);
    $writer
      ->open();
    $writer
      ->writeItem($item);
    $writer
      ->writeItems($reader);
    $writer
      ->close();
  }
  else {
    drupal_set_message('Nothing to export.');
  }
}