summaryrefslogtreecommitdiff
path: root/tools/inc/lib/jsgettext/po2json.php
diff options
context:
space:
mode:
authorCzterooki <czterooki1337@gmail.com>2013-07-20 00:19:08 -0400
committerCzterooki <czterooki1337@gmail.com>2013-07-20 00:19:08 -0400
commitaef44255920c18f443af28d100fb06d9699d4895 (patch)
treeb1d72ffc9a0e4f6a009ca16e9e3af2260806c193 /tools/inc/lib/jsgettext/po2json.php
parent81892ebcdcd2929128c2c320f7de975cab8ed368 (diff)
parentf04566f6d30553560d5a69e25e38de72a60f297c (diff)
merge with vichan-gold
Diffstat (limited to 'tools/inc/lib/jsgettext/po2json.php')
-rw-r--r--tools/inc/lib/jsgettext/po2json.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/inc/lib/jsgettext/po2json.php b/tools/inc/lib/jsgettext/po2json.php
new file mode 100644
index 00000000..847b0899
--- /dev/null
+++ b/tools/inc/lib/jsgettext/po2json.php
@@ -0,0 +1,42 @@
+<?php
+
+ require_once 'PoeditParser.php';
+
+ function buildOptions($args) {
+ $options = array(
+ '-o' => null,
+ '-i' => null,
+ '-n' => 'l10n'
+ );
+ $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[] = $args[$i];
+ $i++;
+ }
+ }
+ return $options;
+ }
+
+ $options = buildOptions($argv);
+
+ if (!file_exists($options['-i']) || !is_readable($options['-i'])) {
+ die("Invalid input file. Make sure it exists and is readable.");
+ }
+
+ $poeditParser = new PoeditParser($options['-i']);
+ $poeditParser->parse();
+
+ if ($poeditParser->toJSON($options['-o'], $options['-n'])) {
+ $strings = count($poeditParser->getStrings());
+ echo "Successfully exported " . count($strings) . " strings.\n";
+ }
+ else {
+ echo "Cannor write to file '{$options['-o']}'.\n";
+ }
+?>