You are here

function potx_select_form_submit in Translation template extractor 5.2

Same name and namespace in other branches
  1. 5 potx.module \potx_select_form_submit()
  2. 6 potx.module \potx_select_form_submit()
  3. 6.2 potx.module \potx_select_form_submit()
  4. 7 potx.module \potx_select_form_submit()

Generate translation template or translation file for the requested module.

File

./potx.module, line 98
Gettext translation template and translation extractor.

Code

function potx_select_form_submit($form_id, &$form) {

  // This could take some time.
  @set_time_limit(0);
  include_once drupal_get_path('module', 'potx') . '/potx.inc';

  // Silence status messages.
  _potx_status(POTX_STATUS_MESSAGE);

  // $form['module'] either contains a specific module file name
  // with path, or a directory name for a module or a module suite.
  // Examples:
  //   modules/watchdog
  //   sites/all/modules/potx
  //   sites/all/modules/i18n/i18n.module
  $pathinfo = pathinfo($form['module']);
  $strip_prefix = 0;

  // A specific module file was requested.
  if ($pathinfo['extension'] == 'module') {
    $filename = basename($pathinfo['basename'], '.module');
    $files = _potx_explore_dir($pathinfo['dirname'] . '/', $filename, POTX_API_5);
    $strip_prefix = 1 + strlen($pathinfo['dirname']);
    $outputname = $filename;
  }
  else {
    $files = _potx_explore_dir($form['module'] . '/', '*', POTX_API_5);
    $strip_prefix = 1 + strlen($form['module']);
    $outputname = $pathinfo['basename'];
  }

  // Decide on template or translation file generation.
  $template_langcode = $translation_langcode = NULL;
  if (isset($form['langcode']) && $form['langcode'] != 'n/a') {
    $template_langcode = $form['langcode'];
    $outputname .= '.' . $template_langcode;
    if (!empty($form['translations'])) {
      $translation_langcode = $template_langcode;
      $outputname .= '.po';
    }
    else {
      $outputname .= '.pot';
    }
  }
  else {
    $outputname .= '.pot';
  }

  // Collect every string in affected files. Installer related strings are discared.
  foreach ($files as $file) {
    _potx_process_file($file, $strip_prefix, '_potx_save_string', '_potx_save_version', POTX_API_5);
  }

  // Need to include full parameter list to get to passing the language codes.
  _potx_build_files(POTX_STRING_RUNTIME, POTX_BUILD_SINGLE, 'general', '_potx_save_string', '_potx_save_version', '_potx_get_header', $template_langcode, $translation_langcode, POTX_API_5);
  _potx_write_files($outputname, 'attachment');
  exit;
}