-Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api
[oweals/gnunet.git] / po / update.pl.in
1 #!@PERL@ -w
2
3 #  GNOME po update utility.
4 #  (C) 2000 The Free Software Foundation
5 #
6 #  Author(s): Kenneth Christiansen
7 #  Patches:   Björn Voigt <bjoern@cs.tu-berlin.de>
8
9
10 $VERSION = "1.2.5 beta 2";
11 $LANG    = $ARGV[0];
12 $PACKAGE  = "GNUnet";
13
14 if (! $LANG){
15     print "update.pl:  missing file arguments\n";
16     print "Try `update.pl --help' for more information.\n";
17     exit;
18 }
19
20 if ($LANG=~/^-(.)*/){
21
22     if ("$LANG" eq "--version" || "$LANG" eq "-V"){
23         print "GNOME PO Updater $VERSION\n";
24         print "Written by Kenneth Christiansen <kenneth\@gnome.org>, 2000.\n\n";
25         print "Copyright (C) 2000 Free Software Foundation, Inc.\n";
26         print "This is free software; see the source for copying conditions.  There is NO\n";
27         print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
28         exit;
29     }
30
31
32     elsif ($LANG eq "--help" || "$LANG" eq "-H"){
33         print "Usage: ./update.pl [OPTIONS] ...LANGCODE\n";
34         print "Updates pot files and merge them with the translations.\n\n";
35         print "  -V, --version                shows the version\n";
36         print "  -H, --help                   shows this help page\n";
37         print "  -P, --pot                    only generates the potfile\n";
38         print "  -M, --maintain               search for missing files in POTFILES.in\n";
39         print "\nExamples of use:\n";
40         print "update.sh --pot    just creates a new pot file from the source\n";
41         print "update.sh da       created new pot file and updated the da.po file\n\n";
42         print "Report bugs to <kenneth\@gnome.org>.\n";
43         exit;
44     }
45
46     elsif($LANG eq "--pot" || "$LANG" eq "-P"){
47
48         print "Building the $PACKAGE.pot ...";
49
50         $b="xgettext --default-domain\=$PACKAGE --directory\=\.\."
51           ." --add-comments --keyword\=\_ --keyword\=N\_"
52           ." --files-from\=\.\/POTFILES\.in ";
53         $b1="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
54            ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)";
55         if(($ret=system($b . " && " . $b1))==0) {
56             print "...done\n";
57         }
58         else {
59             print "...failed\n";
60         }
61
62         exit $ret;
63     }
64
65     elsif ($LANG eq "--maintain" || "$LANG" eq "-M"){
66
67         $a="find ../ -path ../intl -prune -o -print | egrep '.*\\.(c|y|cc|c++|h|gob)\$' ";
68
69         open(BUF2, "POTFILES.in") || die "update.pl:  there's not POTFILES.in!!!\n";
70         print "Searching for missing _(\" \") entries and for deleted files...\n";
71         open(BUF1, "$a|");
72
73
74         @buf2 = <BUF2>;
75         @buf1 = <BUF1>;
76
77         if (-s "POTFILES.ignore") {
78             open FILE, "POTFILES.ignore";
79             while (<FILE>) {
80                 if ($_=~/^[^#]/o) {
81                     push @bup, $_;
82                 }
83             }
84             print "POTFILES.ignore found! Ignoring files...\n";
85             @buf2 = (@bup, @buf2);
86             }
87
88         foreach my $file (@buf1) {
89             $cmd="xgettext -o - --omit-header --keyword=_ " .
90                 "--keyword=N_ " . $file . " |";
91             open XGET, $cmd;
92             if(<XGET>) {
93                 $file = unpack("x3 A*",$file) . "\n";
94                 push @buff1, $file;
95             }
96             close XGET;
97 #           open FILE, "<$file";
98 #            while (<FILE>) {
99 #                if ($_=~/_\(\"/o || $_=~/ngettext\(\"/o){
100 #                    $file = unpack("x3 A*",$file) . "\n";
101 #                    push @buff1, $file;
102 #                    last;
103 #                }
104 #            }
105         }
106
107         @bufff1 = sort (@buff1);
108
109         @bufff2 = sort (@buf2);
110
111         my %in2;
112         foreach (@bufff2) {
113             chomp;
114             $in2{$_} = 1;
115         }
116
117         my %in1;
118         foreach (@bufff1) {
119             chomp;
120             $in1{$_} = 1;
121         }
122
123         foreach (@bufff1) {
124             chomp;
125             if (!exists($in2{$_})) {
126                 push @result, $_ . "\n";
127             }
128         }
129
130         foreach (@bufff2) {
131             chomp;
132             if (! -f "../" . $_) {
133                 push @deletedfiles, $_ . "\n"; 
134             }
135         }
136         
137         foreach (@bufff2) {
138             if (!exists($in1{$_})) {
139                 push @noi18nfiles, $_ . "\n";
140             }
141         }
142
143         if(@result){
144             open OUT, ">POTFILES.in.missing";
145             print OUT @result;
146             print "\nHere are the missing files:\n\n", @result, "\n";
147             print "File POTFILES.in.missing is being placed in directory...\n";
148             print "Please add the files that should be ignored in POTFILES.ignore\n";
149         }
150         else{
151             unlink("POTFILES.in.missing");
152         }
153             
154         if(@deletedfiles){
155             open OUT, ">POTFILES.in.deleted";
156             print OUT @deletedfiles;
157             print "\nHere are the deleted files:\n\n", @deletedfiles, "\n";
158             print "File POTFILES.in.deleted is being placed in directory...\n";
159             print "Please delete the files from POTFILES.in or POTFILES.ignore\n";
160         }
161         else{
162             unlink("POTFILES.in.deleted");
163         }
164
165         if(@noi18nfiles){
166             open OUT, ">POTFILES.in.noi18n";
167             print OUT @noi18nfiles;
168             print "\nHere are the files which currently have no i18n strings:\n\n", 
169             @noi18nfiles, "\n";
170             print "File POTFILES.in.noi18n is being placed in directory...\n";
171             print "Please delete the files from POTFILES.in or POTFILES.ignore\n";
172             print "or ignore the files.\n";
173         }
174         else{
175             unlink("POTFILES.in.noi18n");
176         }
177
178         if( ! @result && ! @deletedfiles ) {
179             print "\nWell, it's all perfect! Congratulation!\n";
180         }
181     }
182
183
184     else{
185         print "update.pl: invalid option -- $LANG\n";
186         print "Try `update.pl --help' for more information.\n";
187     }
188     exit;
189     }
190
191 elsif(-s "$LANG.po"){
192
193     print "Building the $PACKAGE.pot ...";
194
195     $c="xgettext --default-domain\=$PACKAGE --directory\=\.\."
196       ." --add-comments --keyword\=\_ --keyword\=N\_"
197       ." --files-from\=\.\/POTFILES\.in ";  
198     $c1="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
199        ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)";
200
201     if(($ret=system($c . " && " . $c1))==0) {
202         print "...done\n";
203     }
204     else {
205         print "...failed\n";
206     }
207
208     if($ret==0) {
209         print "\nNow merging $LANG.po with $PACKAGE.pot, and creating an updated $LANG.po ...\n";
210
211     
212         $d="if msgmerge $LANG.po $PACKAGE.pot -o $LANG.new.po; then " .
213             "  mv -f $LANG.new.po $LANG.po; " .
214             "  msgfmt --statistics  -c -v -o /dev/null $LANG.po; " .
215             "else " .
216             "  echo \"msgmerge failed!\"; " .
217             "  rm -f $LANG.new.po; ".
218             "fi";
219
220         $ret=system($d);
221
222         exit $ret;
223     }
224 }
225
226 else{
227     print "update.pl:  sorry $LANG.po does not exist!\n";
228     print "Try `update.pl --help' for more information.\n";    
229     exit;
230 }