Skip to content

Commit

Permalink
command line script
Browse files Browse the repository at this point in the history
  • Loading branch information
voda committed Dec 14, 2010
1 parent 95daef3 commit 264a017
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions gettext-extractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/php
<?php
/**
* GettextExtractor
*
* This source file is subject to the New BSD License.
*
* @copyright Copyright (c) 2010 Ondřej Vodáček
* @license New BSD License
* @package Nette Extras
*/

require dirname(__FILE__) . '/NetteGettextExtractor.php';

$output = 'php://stdout';
$log = 'php://stderr';
$files = null;
$keywords = null;

$options = getopt('o::l::f:hk:');


if (isset($options['h'])) {
echo <<<EOF
Usage {$argv[0]} [options]
Options:
-h display this help and exit
-oFILE output file, default output is stdout
-lFILE log file, default is stderr
-fFILE file to extract, can be specified several times
-kFUNCTION add FUNCTION to filters, format is:
FILTER:FUNCTION_NAME:SINGULAR,PLURAL,CONTEXT
default FILTERs are PHP and NetteLatte
for SINGULAR, PLURAL and CONTEXT '0' means not set
can be specified several times
EOF;
exit;
}
if (isset($options['l'])) {
if (is_array($options['l'])) {
echo "Specify only one log file.\n";
exit;
}
$log = $options['l'];
}
if (isset($options['o'])) {
if (is_array($options['o'])) {
echo "Specify only one output file.\n";
exit;
}
$output = $options['o'];
}
if (!isset($options['f'])) {
echo "No input files given.\n";
echo "Try '{$argv[0]} -h' for more informations.\n";
exit;
}
if (isset($options['k'])) {
$keywords = array();
if (is_string($options['k'])) {
$options['k'] = array($options['k']);
}
foreach ($options['k'] as $value) {
$filter = $function = $params = null;
list ($filter, $function, $params) = split(':', $value);
$singular = $plural = $context = null;
$params = split(',', $params);
foreach ($params as &$param) {
$param = (int)$param;
if ($param === 0) {
$param = null;
}
}
list ($singular, $plural, $context) = $params;
$keywords[] = array(
'filter' => $filter,
'function' => $function,
'singular' => $singular,
'plural' => $plural,
'context' => $context
);
}
}

$extractor = new NetteGettextExtractor($log);
$extractor->setupForms()->setupDataGrid();
if ($keywords !== null) {
foreach ($keywords as $value) {
$extractor->getFilter($value['filter'])
->addFunction($value['function'], $value['singular'], $value['plural'], $value['context']);
}
}
$extractor->scan($options['f']);
$extractor->save($output);

0 comments on commit 264a017

Please sign in to comment.