]> Pileus Git - ~andy/gtk/blob - po/update.pl
Trivial doc adjustment.
[~andy/gtk] / po / update.pl
1 #!/usr/bin/perl -w
2
3 #  GNOME po update utility.
4 #  (C) 2000 The Free Software Foundation
5 #
6 #  Author(s): Kenneth Christiansen
7
8
9 $VERSION = "1.2.5 beta 2";
10 $LANG    = $ARGV[0];
11 $PACKAGE  = "gtk20";
12
13 if (! $LANG){
14     print "update.pl:  missing file arguments\n";
15     print "Try `update.pl --help' for more information.\n";
16     exit;
17 }
18
19 if ($LANG=~/^-(.)*/){
20
21     if ("$LANG" eq "--version" || "$LANG" eq "-V"){
22         print "GNOME PO Updater $VERSION\n";
23         print "Written by Kenneth Christiansen <kenneth\@gnome.org>, 2000.\n\n";
24         print "Copyright (C) 2000 Free Software Foundation, Inc.\n";
25         print "This is free software; see the source for copying conditions.  There is NO\n";
26         print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
27         exit;
28     }
29
30
31     elsif ($LANG eq "--help" || "$LANG" eq "-H"){
32         print "Usage: ./update.pl [OPTIONS] ...LANGCODE\n";
33         print "Updates pot files and merge them with the translations.\n\n";
34         print "  -V, --version                shows the version\n";
35         print "  -H, --help                   shows this help page\n";
36         print "  -P, --pot                    only generates the potfile\n";
37         print "  -M, --maintain               search for missing files in POTFILES.in\n";
38         print "\nExamples of use:\n";
39         print "update.sh --pot    just creates a new pot file from the source\n";
40         print "update.sh da       created new pot file and updated the da.po file\n\n";
41         print "Report bugs to <kenneth\@gnome.org>.\n";
42         exit;
43     }
44
45     elsif($LANG eq "--pot" || "$LANG" eq "-P"){
46                 
47         shift;
48         $REALPACKAGE = shift;
49         if (!$REALPACKAGE) {
50             $REALPACKAGE = $PACKAGE;
51         }
52
53         print "Building the $REALPACKAGE.pot ...";
54
55         $b="xgettext --default-domain\=$PACKAGE --directory\=\.\."
56           ." --add-comments --keyword\=\_ --keyword\=N\_"
57           ." --files-from\=\.\/POTFILES\.in ";
58         $b1="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
59            ."&& mv $PACKAGE\.po \.\/$REALPACKAGE\.pot \)";
60          
61         `$b`;
62         `$b1`;
63
64         print "...done\n";
65
66         exit;
67     }
68         
69     elsif ($LANG eq "--maintain" || "$LANG" eq "-M"){
70
71         $a="find ../ -print | egrep '.*\\.(c|y|cc|c++|h|gob)' ";
72
73         open(BUF2, "POTFILES.in") || die "update.pl:  there's not POTFILES.in!!!\n";
74         print "Searching for missing _(\" \") entries...\n";
75         open(BUF1, "$a|");
76
77
78         @buf2 = <BUF2>;
79         @buf1 = <BUF1>;
80
81         if (-s "POTFILES.ignore"){
82             open FILE, "POTFILES.ignore";
83             while (<FILE>) {
84                 if ($_=~/^[^#]/o){
85                     push @bup, $_;
86                 }
87             }
88             print "POTFILES.ignore found! Ignoring files...\n";
89             @buf2 = (@bup, @buf2);
90         }
91
92         foreach my $file (@buf1){
93             open FILE, "<$file";
94             while (<FILE>) {
95                 if ($_=~/_\(\"/o){
96                     $file = unpack("x3 A*",$file) . "\n";
97                     push @buff1, $file;
98                     last;
99                 }
100             }
101         }
102
103         @bufff1 = sort (@buff1);
104
105         @bufff2 = sort (@buf2);
106
107         my %in2;
108         foreach (@bufff2) {
109             $in2{$_} = 1;
110         }
111
112         foreach (@bufff1){
113             if (!exists($in2{$_})){
114                 push @result, $_ }
115             }
116
117         if(@result){
118             open OUT, ">POTFILES.in.missing";
119             print OUT @result;
120             print "\nHere are the results:\n\n", @result, "\n";
121             print "File POTFILES.in.missing is being placed in directory...\n";
122             print "Please add the files that should be ignored in POTFILES.ignore\n";
123         }
124         else{
125             print "\nWell, it's all perfect! Congratulation!\n";
126         }         
127     }
128
129
130     else{
131         print "update.pl: invalid option -- $LANG\n";
132         print "Try `update.pl --help' for more information.\n";
133     }
134     exit;
135     }
136
137 elsif(-s "$LANG.po"){
138
139     print "Building the $PACKAGE.pot ...";
140
141     $c="xgettext --default-domain\=$PACKAGE --directory\=\.\."
142       ." --add-comments --keyword\=\_ --keyword\=N\_"
143       ." --files-from\=\.\/POTFILES\.in ";  
144     $c1="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
145        ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)";
146
147     `$c`;
148     `$c1`;
149
150     print "...done";
151
152     print "\nNow merging $LANG.po with $PACKAGE.pot, and creating an updated $LANG.po ...\n";
153
154     
155     $d="mv $LANG.po $LANG.po.old && msgmerge $LANG.po.old $PACKAGE.pot -o $LANG.po";
156
157     $f="msgfmt --statistics $LANG.po";
158
159     `$d`;
160     `$f`;
161
162     unlink "messages";
163     unlink "$LANG.po.old";
164
165     exit;
166 }
167
168 else{
169     print "update.pl:  sorry $LANG.po does not exist!\n";
170     print "Try `update.pl --help' for more information.\n";    
171     exit;
172 }