Closed (duplicate)
Project:
Translation template extractor
Version:
6.x-3.3
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 Mar 2008 at 09:24 UTC
Updated:
12 Jul 2013 at 02:17 UTC
Comments
Comment #1
lpulira commentedI implemented something like it ... doing ..
function potx_export_form(){
$form = array();
$_modules = array();
$form = potx_select_form();
$i = 0;
foreach($form['potx-fs--modules'] as $k => $v){
if (preg_match('/\Apotx-dir-modules-/sm', $k)) {
$i++;
$_modules[$k] = array('#name'=>"modules[$i]", '#type' => 'hidden', '#value' => $v['#return_value']);
}
}
unset($form['potx-fs--modules']);
foreach($form['potx-fs--sites-all-modules'] as $k => $v){
if (preg_match('/\Apotx-dir-sites-all-modules-/sm', $k)) {
$i++;
$_modules[$k] = array('#name'=>"modules[$i]", '#type' => 'hidden', '#value' => $v['#return_value']);
}
}
unset($form['potx-fs--sites-all-modules']);
$form = array_merge($form, $_modules);
return $form;
}
function potx_export_form_submit($form_id, &$form) {
$_modules_to_process = $_POST['modules'];
ini_set("memory_limit","256M");
for($i=1; $i<=count($_modules_to_process); $i++) {
global $_potx_store, $_potx_tokens, $_potx_lookup, $_potx_strings, $_potx_install;
$_potx_store = null;
$_potx_tokens = null;
$_potx_lookup = null;
$_potx_strings = null;
$_potx_install = null;
$form['module'] = $_modules_to_process[$i];
_potx_export($form_id, $form, true);
}
drupal_set_message(t('processed @count modules in general.pot file!', array('@count' => count($_modules_to_process))));
}
/**
* Generate translation template or translation file for the requested module.
*/
function _potx_export($form_id, &$form, $all = false) {
// 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;
}
// A directory name was requested.
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, $pathinfo['basename'], '_potx_save_string', '_potx_save_version', '_potx_get_header', $template_langcode, $translation_langcode, POTX_API_5);
if (!$all) {
_potx_write_files($outputname, 'attachment');
exit;
} else {
_potx_write_files();
}
}
Comment #2
gábor hojtsyThis is actually now possible with our drush integration in #720986: Add drush integration for extraction, the whole code tree can be parsed and will be output in one big .po file. Not going to backport to Drupal 5, but its on Drupal 6!