Download & Extend

Possibility to have a all-in one file (zip) of evry module translation template ?

Project:Translation template extractor
Version:5.x-1.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hello
It would be great if we could have a zip containing every .po (in folders like /potx/po/template.pot for the potx module for example).
Would it be too much work, or is it possible ?

Comments

#1

I 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();
}
}