]> git.proxmox.com Git - proxmox-i18n.git/commitdiff
po2js: cleanup perl code
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 16 May 2023 15:20:32 +0000 (17:20 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 16 May 2023 16:09:00 +0000 (18:09 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
po2js.pl

index 6323b58821b1ef5555a8e0b720895a2654673da1..f2f289e4df6c844ca125f63bdc9f2c7f3ea29c65 100755 (executable)
--- a/po2js.pl
+++ b/po2js.pl
@@ -18,22 +18,14 @@ getopts('t:o:v:', $options) ||
 
 die "no files specified\n" if !scalar(@ARGV);
 
-#my $filename = shift || die "no po file specified\n";
-
 # like FNV32a, but we only return 31 bits (positive numbers)
 sub fnv31a {
     my ($string) = @_;
 
     my $hval = 0x811c9dc5;
-
-    foreach my $c (unpack('C*', $string)) {
+    for my $c (unpack('C*', $string)) {
        $hval ^= $c;
-       $hval += (
-           (($hval << 1) ) +
-           (($hval << 4) ) +
-           (($hval << 7) ) +
-           (($hval << 8) ) +
-           (($hval << 24) ) );
+       $hval += ($hval << 1) + ($hval << 4) + ($hval << 7) + ($hval << 8) + ($hval << 24);
        $hval = $hval & 0xffffffff;
     }
     return $hval & 0x7fffffff;
@@ -44,7 +36,7 @@ my $catalog = {};
 foreach my $filename (@ARGV) {
     my $href = Locale::PO->load_file_ashash($filename) ||
        die "unable to load '$filename'\n";
-    
+
     my $charset;
     my $hpo = $href->{'""'} || die "no header";
     my $header = $hpo->dequote($hpo->msgstr);
@@ -54,19 +46,15 @@ foreach my $filename (@ARGV) {
        die "unable to get charset\n" if !$charset;
     }
 
-
-    foreach my $k (keys %$href) {
+    for my $k (keys %$href) {
        my $po = $href->{$k};
        next if $po->fuzzy(); # skip fuzzy entries
-       my $ref = $po->reference();
-
-       # skip unused entries
-       next if !$ref;
+       my $ref = $po->reference() or next; # skip unused entries
 
-       # skip entries if t is defined (pve/pmg) and the string is
+       # 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);
 
@@ -74,12 +62,11 @@ foreach my $filename (@ARGV) {
        my $msgstr = $po->dequote($qmsgstr);
 
        next if !length($msgid); # skip header
-       
        next if !length($msgstr); # skip untranslated entries
 
        my $digest = fnv31a($msgid);
 
-       die "duplicate digest" if $catalog->{$digest};
+       die "duplicate digest '$digest' (msgid '$msgid')\n" if $catalog->{$digest};
 
        $catalog->{$digest} = [ $msgstr ];
        # later, we can add plural forms to the array