From 9ce3f62e04272b301131960b88f35e5f2a6ea875 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 2 Oct 2017 12:15:11 +0200 Subject: [PATCH] po2js.pl: add option -o to specify output filename --- Makefile | 5 ++--- po2js.pl | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ea9836c..2c8331f 100644 --- 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: diff --git a/po2js.pl b/po2js.pl index 127c5c4..b73850b 100755 --- 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; +} -- 2.39.2