function potx_select_form_submit in Translation template extractor 6.2
Same name and namespace in other branches
- 5.2 potx.module \potx_select_form_submit()
- 5 potx.module \potx_select_form_submit()
- 6 potx.module \potx_select_form_submit()
- 7 potx.module \potx_select_form_submit()
Generate translation template or translation file for the requested component.
File
- ./
potx.module, line 93 - Gettext translation template and translation extractor.
Code
function potx_select_form_submit($form, &$form_state) {
// This could take some time.
@set_time_limit(0);
include_once drupal_get_path('module', 'potx') . '/potx.inc';
// Silence status messages.
potx_status('set', POTX_STATUS_MESSAGE);
// $form_state['values']['component'] either contains a specific file name
// with path, or a directory name for a module/theme or a module suite.
// Examples:
// modules/watchdog
// sites/all/modules/coder
// sites/all/modules/i18n/i18n.module
// themes/garland
$component = $form_state['values']['component'];
$pathinfo = pathinfo($component);
if (!isset($pathinfo['filename'])) {
// The filename key is only available in PHP 5.2.0+
$pathinfo['filename'] = substr($pathinfo['basename'], 0, strrpos($pathinfo['basename'], '.'));
}
$strip_prefix = 0;
if (isset($pathinfo['extension'])) {
// A specific module or theme file was requested (otherwise there should be no extension).
$files = _potx_explore_dir($pathinfo['dirname'] . '/', $pathinfo['filename']);
$strip_prefix = 1 + strlen($pathinfo['dirname']);
$outputname = $pathinfo['filename'];
}
else {
$files = _potx_explore_dir($component . '/');
$strip_prefix = 1 + strlen($component);
$outputname = $pathinfo['basename'];
}
// Decide on template or translation file generation.
$template_langcode = $translation_langcode = NULL;
if (isset($form_state['values']['langcode']) && $form_state['values']['langcode'] != 'n/a') {
$template_langcode = $form_state['values']['langcode'];
$outputname .= '.' . $template_langcode;
if (!empty($form_state['values']['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);
}
// 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_write_files($outputname, 'attachment');
exit;
}