]>
git.proxmox.com Git - proxmox-i18n.git/blob - po2js.pl
f2f289e4df6c844ca125f63bdc9f2c7f3ea29c65
11 # - we do not support plural. forms
12 # - no message content support
16 getopts
('t:o:v:', $options) ||
17 die "unable to parse options\n";
19 die "no files specified\n" if !scalar(@ARGV);
21 # like FNV32a, but we only return 31 bits (positive numbers)
25 my $hval = 0x811c9dc5;
26 for my $c (unpack('C*', $string)) {
28 $hval += ($hval << 1) + ($hval << 4) + ($hval << 7) + ($hval << 8) + ($hval << 24);
29 $hval = $hval & 0xffffffff;
31 return $hval & 0x7fffffff;
36 foreach my $filename (@ARGV) {
37 my $href = Locale
::PO-
>load_file_ashash($filename) ||
38 die "unable to load '$filename'\n";
41 my $hpo = $href->{'""'} || die "no header";
42 my $header = $hpo->dequote($hpo->msgstr);
43 if ($header =~ m
|^Content-Type
:\s
+text
/plain
;\s
+charset
=(\S
+)$|im
) {
46 die "unable to get charset\n" if !$charset;
49 for my $k (keys %$href) {
51 next if $po->fuzzy(); # skip fuzzy entries
52 my $ref = $po->reference() or next; # skip unused entries
54 # skip entries if "t" is defined (pve/pmg) and the string is
55 # not used there or in the widget toolkit
56 next if $options->{t
} && $ref !~ m/($options->{t}|proxmox)\-/;
58 my $qmsgid = decode
($charset, $po->msgid);
59 my $msgid = $po->dequote($qmsgid);
61 my $qmsgstr = decode
($charset, $po->msgstr);
62 my $msgstr = $po->dequote($qmsgstr);
64 next if !length($msgid); # skip header
65 next if !length($msgstr); # skip untranslated entries
67 my $digest = fnv31a
($msgid);
69 die "duplicate digest '$digest' (msgid '$msgid')\n" if $catalog->{$digest};
71 $catalog->{$digest} = [ $msgstr ];
72 # later, we can add plural forms to the array
76 my $json = to_json
($catalog, {canonical
=> 1, utf8
=> 1});
78 my $version = $options->{v
} // ("dev-build " . localtime());
79 my $content = "// $version\n"; # write version to the beginning to better avoid stale cache
81 my $outfile = $options->{o
};
83 $content .= "// Proxmox Message Catalog: $outfile\n" if $outfile;
86 const __proxmox_i18n_msgcat__ = $json;
88 function fnv31a(text) {
89 let hval = 0x811c9dc5;
90 for (const c of text) {
92 hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
98 function gettext(buf) {
99 let digest = fnv31a(buf);
100 return __proxmox_i18n_msgcat__[digest]?.[0] ?? buf;
105 open(my $fh, '>', $outfile) ||
106 die "unable to open '$outfile' - $!\n";