]>
Commit | Line | Data |
---|---|---|
660fe2ae DM |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use Time::Local; | |
5 | use PVE::Tools; | |
6 | use Locale::PO; | |
7 | ||
8 | my $dir = shift; | |
9 | ||
10 | ||
11 | die "no such directory\n" if ! -d $dir; | |
12 | ||
13 | my $sources = []; | |
14 | ||
15 | my $findcmd = ['find', $dir, '-name', '*.js']; | |
16 | PVE::Tools::run_command($findcmd, outfunc => sub { | |
17 | my $line = shift; | |
18 | next if $line =~ m|/pvemanagerlib.js$|; | |
19 | push @$sources, $line; | |
20 | }); | |
21 | ||
22 | my $filename = "messages.pot"; | |
23 | ||
24 | my $header = <<__EOD; | |
25 | SOME DESCRIPTIVE TITLE. | |
26 | Copyright (C) 20011 Proxmox Server Solutions GmbH | |
27 | This file is distributed under the same license as the pve-manager package. | |
28 | Proxmox Support Team <support\@proxmox.com>, 2011. | |
29 | __EOD | |
30 | ||
31 | my $ctime = scalar localtime; | |
32 | ||
33 | my $href = {}; | |
34 | my $po = new Locale::PO(-msgid=> '', | |
35 | -comment=> $header, | |
36 | -fuzzy=> 1, | |
37 | -msgstr=> | |
38 | "Project-Id-Version: pve-manager 2.0\\n" . | |
39 | "Report-Msgid-Bugs-To: <support\@proxmox.com>\\n" . | |
40 | "POT-Creation-Date: $ctime\\n" . | |
41 | "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n" . | |
42 | "Last-Translator: FULL NAME <EMAIL\@ADDRESS>\\n" . | |
43 | "Language-Team: LANGUAGE <support\@proxmox.com>\\n" . | |
44 | "MIME-Version: 1.0\\n" . | |
45 | "Content-Type: text/plain; charset=CHARSET\\n" . | |
46 | "Content-Transfer-Encoding: 8bit\\n"); | |
47 | ||
48 | $href->{''} = $po; | |
49 | ||
50 | sub extract_msg { | |
51 | my ($filename, $linenr, $line) = @_; | |
52 | ||
53 | my $text; | |
54 | if ($line =~ m/\Wgettext\s*\("((?:[^"\\]++|\\.)*+)"\)/) { | |
55 | $text = $1; | |
56 | } elsif ($line =~ m/\Wgettext\s*\('((?:[^'\\]++|\\.)*+)'\)/) { | |
57 | $text = $1; | |
58 | } else { | |
59 | die "can't extract gettext message in '$filename' line $linenr\n"; | |
60 | } | |
61 | ||
62 | my $ref = "$filename:$linenr"; | |
63 | ||
64 | if (my $po = $href->{$text}) { | |
65 | $po->reference($po->reference() . " $ref"); | |
66 | return; | |
67 | } | |
68 | ||
69 | my $po = new Locale::PO(-msgid=> $text, -reference=> $ref, -msgstr=> ''); | |
70 | $href->{$text} = $po; | |
71 | } | |
72 | ||
73 | ||
74 | foreach my $s (@$sources) { | |
75 | open(SRC, $s) || die "unable to open file '$s' - $!\n"; | |
76 | while(defined(my $line = <SRC>)) { | |
77 | if ($line =~ m/gettext/) { | |
78 | extract_msg($s, $., $line); | |
79 | } | |
80 | } | |
81 | close(SRC); | |
82 | } | |
83 | ||
84 | Locale::PO->save_file_fromhash($filename, $href); | |
85 |