]> git.proxmox.com Git - proxmox-i18n.git/commitdiff
po2js.pl: add option -o to specify output filename
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 2 Oct 2017 10:15:11 +0000 (12:15 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 2 Oct 2017 10:15:11 +0000 (12:15 +0200)
Makefile
po2js.pl

index ea9836cdc56a6bc46a9c9ff516dc285f2f785a0f..2c8331f791b0eb2cb85f2eb57912363634c9e7f6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,11 +36,10 @@ install: ${PMG_LANG_FILES} ${PVE_LANG_FILES}
 
 
 pmg-lang-%.js: proxmox-widget-toolkit-%.po proxmox-mailgateway-%.po
-       ./po2js.pl $? > pmg-lang-$*.js
+       ./po2js.pl -o pmg-lang-$*.js $?
 
 pve-lang-%.js: proxmox-widget-toolkit-%.po pve-manager-%.po
-       ./po2js.pl $? > pve-lang-$*.js
-
+       ./po2js.pl -o pve-lang-$*.js $?
 
 .PHONY: update
 update:
index 127c5c4da33f305521607b4d8156cf7867536a82..b73850bf350ad8f021b04594bdbcac1a65c8938f 100755 (executable)
--- a/po2js.pl
+++ b/po2js.pl
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-
+use Getopt::Std;
 use Locale::PO;
 use JSON;
 use Encode;
@@ -11,6 +11,11 @@ use Encode;
 # - we do not support plural. forms
 # - no message content support
 
+my $options = {};
+
+getopts('o:', $options) ||
+    die "unable to parse options\n";
+
 die "no files specified\n" if !scalar(@ARGV);
 
 #my $filename = shift || die "no po file specified\n";
@@ -76,8 +81,14 @@ foreach my $filename (@ARGV) {
 
 my $json = to_json($catalog, {canonical => 1, utf8 => 1});
 
-print <<__EOD
-PVE = { i18n_msgcat: $json }
+my $content = '';
+
+my $outfile = $options->{o};
+
+$content .= "// Proxmox Message Catalog: $outfile\n" if $outfile;
+
+$content .= <<__EOD;
+Proxmox = { i18n_msgcat: $json }
 
 function fnv31a(text) {
     var len = text.length;
@@ -93,12 +104,18 @@ function fnv31a(text) {
 
 function gettext(buf) {
     var digest = fnv31a(buf);
-    var data = PVE.i18n_msgcat[digest];
+    var data = Proxmox.i18n_msgcat[digest];
     if (!data) {
        return buf;
     }
     return data[0] || buf;
 }
-
 __EOD
 
+if ($outfile) {
+    open(my $fh, '>', $outfile) ||
+       die "unable to open '$outfile' - $!\n";
+    print $fh $content;
+} else {
+    print $content;
+}