From 7ab1ec4caa74fc017948829dbd57c91a659a4b4b Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 2 Jul 2013 22:48:43 -0400 Subject: tools/inc/lib/jsgettext/: bundle jsgettext library from https://code.google.com/p/jsgettext --- tools/inc/lib/jsgettext/jsgettext.php | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tools/inc/lib/jsgettext/jsgettext.php (limited to 'tools/inc/lib/jsgettext/jsgettext.php') diff --git a/tools/inc/lib/jsgettext/jsgettext.php b/tools/inc/lib/jsgettext/jsgettext.php new file mode 100644 index 00000000..3ce2c9f7 --- /dev/null +++ b/tools/inc/lib/jsgettext/jsgettext.php @@ -0,0 +1,59 @@ + array(), + '-o' => null, + '-k' => '_' + ); + $len = count($args); + $i = 0; + while ($i < $len) { + if (preg_match('#^-[a-z]$#i', $args[$i])) { + $options[$args[$i]] = isset($args[$i+1]) ? trim($args[$i+1]) : true; + $i += 2; + } + else { + $options['files'][] = $args[$i]; + $i++; + } + } + return $options; + } + + $options = buildOptions($argv); + + if (!file_exists($options['-o']) || !is_writable($options['-o'])) { + die("Invalid output file name. Make sure it exists and is writable."); + } + + $inputFiles = $options['files']; + + if (empty($inputFiles)) { + die("You did not provide any input file."); + } + + $poeditParser = new PoeditParser($options['-o']); + $poeditParser->parse(); + + $errors = array(); + + foreach ($inputFiles as $f) { + if (!is_readable($f) || !preg_match('#\.js$#', $f)) { + $errors[] = ("$f is not a valid javascript file."); + continue; + } + $jsparser = new JSParser($f, explode(' ', $options['-k'])); + $jsStrings = $jsparser->parse(); + $poeditParser->merge($jsStrings); + } + + if (!empty($errors)) { + echo "\nThe following errors occured:\n" . implode("\n", $errors) . "\n"; + } + + $poeditParser->save(); +?> -- cgit v1.3 From f7d7981248c50262253a4f86cab922919e8dfd84 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 2 Jul 2013 23:57:47 -0400 Subject: tools/inc/lib/jsgettext/: apply fixes from bugtracker --- tools/inc/lib/jsgettext/jsgettext.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tools/inc/lib/jsgettext/jsgettext.php') diff --git a/tools/inc/lib/jsgettext/jsgettext.php b/tools/inc/lib/jsgettext/jsgettext.php index 3ce2c9f7..6c70f0b4 100644 --- a/tools/inc/lib/jsgettext/jsgettext.php +++ b/tools/inc/lib/jsgettext/jsgettext.php @@ -10,7 +10,7 @@ '-k' => '_' ); $len = count($args); - $i = 0; + $i = 1; while ($i < $len) { if (preg_match('#^-[a-z]$#i', $args[$i])) { $options[$args[$i]] = isset($args[$i+1]) ? trim($args[$i+1]) : true; @@ -26,7 +26,11 @@ $options = buildOptions($argv); - if (!file_exists($options['-o']) || !is_writable($options['-o'])) { + if (!file_exists($options['-o'])) { + touch($options['-o']); + } + + if (!is_writable($options['-o'])) { die("Invalid output file name. Make sure it exists and is writable."); } -- cgit v1.3