]>
git.proxmox.com Git - proxmox-i18n.git/blob - po2js.pl
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 #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();
66 # skip entries if t is defined (pve/pmg) and the string is
67 # not used there or in the widget toolkit
68 next if $options->{t
} && $ref !~ m/($options->{t}|proxmox)\-/;
70 my $qmsgid = decode
($charset, $po->msgid);
71 my $msgid = $po->dequote($qmsgid);
73 my $qmsgstr = decode
($charset, $po->msgstr);
74 my $msgstr = $po->dequote($qmsgstr);
76 next if !length($msgid); # skip header
78 next if !length($msgstr); # skip untranslated entries
80 my $digest = fnv31a
($msgid);
82 die "duplicate digest" if $catalog->{$digest};
84 $catalog->{$digest} = [ $msgstr ];
85 # later, we can add plural forms to the array
89 my $json = to_json
($catalog, {canonical
=> 1, utf8
=> 1});
91 my $content = "// $options->{v}\n"; # write version to beginning
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";