]>
git.proxmox.com Git - proxmox-i18n.git/blob - po2js.pl
12 # - we do not support plural. forms
13 # - no message content support
16 GetOptions
($options, 't=s', 'o=s', 'v=s') or die "unable to parse options\n";
18 die "no files specified\n" if !scalar(@ARGV);
20 #my $filename = shift || die "no po file specified\n";
22 # like FNV32a, but we only return 31 bits (positive numbers)
26 my $hval = 0x811c9dc5;
28 foreach my $c (unpack('C*', $string)) {
36 $hval = $hval & 0xffffffff;
38 return $hval & 0x7fffffff;
43 foreach my $filename (@ARGV) {
44 my $href = Locale
::PO-
>load_file_ashash($filename) ||
45 die "unable to load '$filename'\n";
48 my $hpo = $href->{'""'} || die "no header";
49 my $header = $hpo->dequote($hpo->msgstr);
50 if ($header =~ m
|^Content-Type
:\s
+text
/plain
;\s
+charset
=(\S
+)$|im
) {
53 die "unable to get charset\n" if !$charset;
57 foreach my $k (keys %$href) {
59 next if $po->fuzzy(); # skip fuzzy entries
60 my $ref = $po->reference();
65 # skip entries if t is defined (pve/pmg) and the string is
66 # not used there or in the widget toolkit
67 next if $options->{t
} && $ref !~ m/($options->{t}|proxmox)\-/;
69 my $qmsgid = decode
($charset, $po->msgid);
70 my $msgid = $po->dequote($qmsgid);
72 my $qmsgstr = decode
($charset, $po->msgstr);
73 my $msgstr = $po->dequote($qmsgstr);
75 next if !length($msgid); # skip header
77 next if !length($msgstr); # skip untranslated entries
79 my $digest = fnv31a
($msgid);
81 die "duplicate digest" if $catalog->{$digest};
83 $catalog->{$digest} = [ $msgstr ];
84 # later, we can add plural forms to the array
88 my $json = to_json
($catalog, {canonical
=> 1, utf8
=> 1});
90 my $version = $options->{v
} // ("dev-build " . localtime());
91 my $content = "// $version\n"; # write version to the beginning to better avoid stale cache
93 my $outfile = $options->{o
};
95 $content .= "// Proxmox Message Catalog: $outfile\n" if $outfile;
98 __proxmox_i18n_msgcat__ = $json;
100 function fnv31a(text) {
101 var len = text.length;
102 var hval = 0x811c9dc5;
103 for (var i = 0; i < len; i++) {
104 var c = text.charCodeAt(i);
106 hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
112 function gettext(buf) {
113 var digest = fnv31a(buf);
114 var data = __proxmox_i18n_msgcat__[digest];
118 return data[0] || buf;
123 open(my $fh, '>', $outfile) ||
124 die "unable to open '$outfile' - $!\n";