]> git.proxmox.com Git - proxmox-i18n.git/blobdiff - po2js.pl
update Polish translations
[proxmox-i18n.git] / po2js.pl
index 127c5c4da33f305521607b4d8156cf7867536a82..f4060aada61546a28653ea634ea868cc077cbc37 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('t:o:v:', $options) ||
+    die "unable to parse options\n";
+
 die "no files specified\n" if !scalar(@ARGV);
 
 #my $filename = shift || die "no po file specified\n";
@@ -34,7 +39,7 @@ sub fnv31a {
     return $hval & 0x7fffffff;
 }
 
-my $catalog;
+my $catalog = {};
 
 foreach my $filename (@ARGV) {
     my $href = Locale::PO->load_file_ashash($filename) ||
@@ -54,6 +59,13 @@ foreach my $filename (@ARGV) {
        my $po = $href->{$k};
        next if $po->fuzzy(); # skip fuzzy entries
        my $ref = $po->reference();
+
+       # skip unused entries
+       next if !$ref;
+
+       # skip entries if t is defined (pve/pmg) and the string is
+       # not used there or in the widget toolkit
+       next if $options->{t} && $ref !~ m/($options->{t}|proxmox)\-/;
     
        my $qmsgid = decode($charset, $po->msgid);
        my $msgid = $po->dequote($qmsgid);
@@ -63,7 +75,7 @@ foreach my $filename (@ARGV) {
 
        next if !length($msgid); # skip header
        
-       #next if !length($msgstr); # skip untranslated entries
+       next if !length($msgstr); # skip untranslated entries
 
        my $digest = fnv31a($msgid);
 
@@ -76,8 +88,14 @@ foreach my $filename (@ARGV) {
 
 my $json = to_json($catalog, {canonical => 1, utf8 => 1});
 
-print <<__EOD
-PVE = { i18n_msgcat: $json }
+my $content = "// $options->{v}\n"; # write version to beginning
+
+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 +111,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;
+}