]>
git.proxmox.com Git - proxmox-i18n.git/blob - jsgettext.pl
327b11783fdeae8f84d6fed3daddde4a9973c83b
15 getopts
('o:b:p:', $options) ||
16 die "unable to parse options\n";
20 die "no directory specified\n" if !scalar(@$dirs);
22 foreach my $dir (@$dirs) {
23 die "no such directory '$dir'\n" if ! -d
$dir;
26 my $projectId = $options->{p
} || die "missing project ID\n";
29 if (my $base = $options->{b
}) {
30 my $aref = Locale
::PO-
>load_file_asarray($base) ||
31 die "unable to load '$base'\n";
34 my $hpo = $aref->[0] || die "no header";
35 my $header = $hpo->dequote($hpo->msgstr);
36 if ($header =~ m
|^Content-Type
:\s
+text
/plain
;\s
+charset
=(\S
+)$|im
) {
39 die "unable to get charset\n" if !$charset;
42 foreach my $po (@$aref) {
43 my $qmsgid = decode
($charset, $po->msgid);
44 my $msgid = $po->dequote($qmsgid);
45 $basehref->{$msgid} = $po;
51 my $findcmd = [['find', @$dirs, '-name', '*.js'],['sort']];
52 PVE
::Tools
::run_command
($findcmd, outfunc
=> sub {
55 push @$sources, $line;
59 Proxmox message catalog.
60 Copyright (C) 2011-2020 Proxmox Server Solutions GmbH
61 This file is free software: you can redistribute it and\/or modify
62 it under the terms of the GNU Affero General Public License as published by
63 the Free Software Foundation, either version 3 of the License, or
64 (at your option) any later version.
65 Proxmox Support Team <support\@proxmox.com>, 2020.
68 my $ctime = scalar localtime;
71 my $po = new Locale
::PO
(-msgid
=> '',
75 "Project-Id-Version: $projectId\n" .
76 "Report-Msgid-Bugs-To: <support\@proxmox.com>\n" .
77 "POT-Creation-Date: $ctime\n" .
78 "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n" .
79 "Last-Translator: FULL NAME <EMAIL\@ADDRESS>\n" .
80 "Language-Team: LANGUAGE <support\@proxmox.com>\n" .
81 "MIME-Version: 1.0\n" .
82 "Content-Type: text/plain; charset=UTF-8\n" .
83 "Content-Transfer-Encoding: 8bit\n");
88 my ($filename, $linenr, $line) = @_;
94 if ($line =~ m/\Wgettext\s*\((("((?:[^"\\]++|\\.)*+)")|('((?:[^'\\]++|\\.)*+)'))\)/g) {
100 if ($basehref->{$text}) {
106 my $ref = "$filename:$linenr";
108 if (my $po = $href->{$text}) {
109 $po->reference($po->reference() . " $ref");
111 my $po = new Locale
::PO
(-msgid
=> $text, -reference
=> $ref, -msgstr
=> '');
112 $href->{$text} = $po;
116 die "can't extract gettext message in '$filename' line $linenr\n"
120 foreach my $s (@$sources) {
121 open(SRC
, $s) || die "unable to open file '$s' - $!\n";
122 while(defined(my $line = <SRC
>)) {
123 next if $line =~ m/^\s*function gettext/;
124 if ($line =~ m/gettext\s*\(/) {
125 extract_msg
($s, $., $line);
131 my $filename = $options->{o
} // "messages.pot";
132 Locale
::PO-
>save_file_fromhash($filename, $href);