]>
git.proxmox.com Git - proxmox-i18n.git/blob - jsgettext.pl
12 GetOptions
($options, 'o=s', 'b=s', 'p=s') or die "unable to parse options\n";
16 die "no directory specified\n" if !scalar(@$dirs);
18 foreach my $dir (@$dirs) {
19 die "no such directory '$dir'\n" if ! -d
$dir;
22 my $projectId = $options->{p
} || die "missing project ID\n";
25 if (my $base = $options->{b
}) {
26 my $aref = Locale
::PO-
>load_file_asarray($base) ||
27 die "unable to load '$base'\n";
30 my $hpo = $aref->[0] || die "no header";
31 my $header = $hpo->dequote($hpo->msgstr);
32 if ($header =~ m
|^Content-Type
:\s
+text
/plain
;\s
+charset
=(\S
+)$|im
) {
35 die "unable to get charset\n" if !$charset;
38 foreach my $po (@$aref) {
39 my $qmsgid = decode
($charset, $po->msgid);
40 my $msgid = $po->dequote($qmsgid);
41 $basehref->{$msgid} = $po;
48 my $find_cmd = 'find ';
49 # shell quote heuristic, with the (here safe) assumption that the dirs don't contain single-quotes
50 $find_cmd .= join(' ', map { "'$_'" } $base_dirs->@*);
51 $find_cmd .= ' -name "*.js"';
52 open(my $find_cmd_output, '-|', "$find_cmd | sort") or die "Failed to execute command: $!";
55 while (my $line = <$find_cmd_output>) {
58 push @$sources, $line;
60 close($find_cmd_output);
65 my $header = <<'__EOD';
66 Proxmox message catalog.
68 Copyright (C) Proxmox Server Solutions GmbH
70 This file is free software: you can redistribute it and/or modify it under the terms of the GNU
71 Affero General Public License as published by the Free Software Foundation, either version 3 of the
72 License, or (at your option) any later version.
73 -- Proxmox Support Team <support\@proxmox.com>
76 my $ctime = scalar localtime;
79 '' => Locale
::PO-
>new(
83 -msgstr
=> "Project-Id-Version: $projectId\n"
84 ."Report-Msgid-Bugs-To: <support\@proxmox.com>\n"
85 ."POT-Creation-Date: $ctime\n"
86 ."PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
87 ."Last-Translator: FULL NAME <EMAIL\@ADDRESS>\n"
88 ."Language-Team: LANGUAGE <support\@proxmox.com>\n"
89 ."MIME-Version: 1.0\n"
90 ."Content-Type: text/plain; charset=UTF-8\n"
91 ."Content-Transfer-Encoding: 8bit\n",
96 my ($filename, $linenr, $line) = @_;
102 if ($line =~ m/\bgettext\s*\((("((?:[^"\\]++|\\.)*+)")|('((?:[^'\\]++|\\.)*+)'))\)/g) {
106 return if $basehref->{$text};
109 my $ref = "$filename:$linenr";
111 if (my $po = $href->{$text}) {
112 $po->reference($po->reference() . " $ref");
114 $href->{$text} = Locale
::PO-
>new(-msgid
=> $text, -reference
=> $ref, -msgstr
=> '');
117 die "can't extract gettext message in '$filename' line $linenr\n" if !$count;
121 my $sources = find_js_sources
($dirs);
123 foreach my $s (@$sources) {
124 open(my $SRC_FH, '<', $s) || die "unable to open file '$s' - $!\n";
125 while(defined(my $line = <$SRC_FH>)) {
126 if ($line =~ m/gettext\s*\(/ && $line !~ m/^\s*function gettext/) {
127 extract_msg
($s, $., $line);
133 my $filename = $options->{o
} // "messages.pot";
134 Locale
::PO-
>save_file_fromhash($filename, $href);