]>
git.proxmox.com Git - proxmox-i18n.git/blob - po2js.pl
11 # - we do not support plural. forms
12 # - no message content support
16 getopts
('o:', $options) ||
17 die "unable to parse options\n";
19 die "no files specified\n" if !scalar(@ARGV);
21 #my $filename = shift || die "no po file specified\n";
23 # like FNV32a, but we only return 31 bits (positive numbers)
27 my $hval = 0x811c9dc5;
29 foreach my $c (unpack('C*', $string)) {
37 $hval = $hval & 0xffffffff;
39 return $hval & 0x7fffffff;
44 foreach my $filename (@ARGV) {
45 my $href = Locale
::PO-
>load_file_ashash($filename) ||
46 die "unable to load '$filename'\n";
49 my $hpo = $href->{'""'} || die "no header";
50 my $header = $hpo->dequote($hpo->msgstr);
51 if ($header =~ m
|^Content-Type
:\s
+text
/plain
;\s
+charset
=(\S
+)$|im
) {
54 die "unable to get charset\n" if !$charset;
58 foreach my $k (keys %$href) {
60 next if $po->fuzzy(); # skip fuzzy entries
61 my $ref = $po->reference();
63 my $qmsgid = decode
($charset, $po->msgid);
64 my $msgid = $po->dequote($qmsgid);
66 my $qmsgstr = decode
($charset, $po->msgstr);
67 my $msgstr = $po->dequote($qmsgstr);
69 next if !length($msgid); # skip header
71 next if !length($msgstr); # skip untranslated entries
73 my $digest = fnv31a
($msgid);
75 die "duplicate digest" if $catalog->{$digest};
77 $catalog->{$digest} = [ $msgstr ];
78 # later, we can add plural forms to the array
82 my $json = to_json
($catalog, {canonical
=> 1, utf8
=> 1});
86 my $outfile = $options->{o
};
88 $content .= "// Proxmox Message Catalog: $outfile\n" if $outfile;
91 Proxmox = { i18n_msgcat: $json }
93 function fnv31a(text) {
94 var len = text.length;
95 var hval = 0x811c9dc5;
96 for (var i = 0; i < len; i++) {
97 var c = text.charCodeAt(i);
99 hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
105 function gettext(buf) {
106 var digest = fnv31a(buf);
107 var data = Proxmox.i18n_msgcat[digest];
111 return data[0] || buf;
116 open(my $fh, '>', $outfile) ||
117 die "unable to open '$outfile' - $!\n";