]> Pileus Git - ~andy/gtk/blob - po/update.pl
Module name has changed for gtk20.
[~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         print "Building the $PACKAGE.pot ...";
48
49         $b="xgettext --default-domain\=$PACKAGE --directory\=\.\."
50           ." --add-comments --keyword\=\_ --keyword\=N\_"
51           ." --files-from\=\.\/POTFILES\.in ";
52         $b1="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
53            ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)";
54          
55         `$b`;
56         `$b1`;
57
58         print "...done\n";
59
60         exit;
61     }
62         
63     elsif ($LANG eq "--maintain" || "$LANG" eq "-M"){
64
65         $a="find ../ -print | egrep '.*\\.(c|y|cc|c++|h|gob)' ";
66
67         open(BUF2, "POTFILES.in") || die "update.pl:  there's not POTFILES.in!!!\n";
68         print "Searching for missing _(\" \") entries...\n";
69         open(BUF1, "$a|");
70
71
72         @buf2 = <BUF2>;
73         @buf1 = <BUF1>;
74
75         if (-s "POTFILES.ignore"){
76             open FILE, "POTFILES.ignore";
77             while (<FILE>) {
78                 if ($_=~/^[^#]/o){
79                     push @bup, $_;
80                 }
81             }
82             print "POTFILES.ignore found! Ignoring files...\n";
83             @buf2 = (@bup, @buf2);
84         }
85
86         foreach my $file (@buf1){
87             open FILE, "<$file";
88             while (<FILE>) {
89                 if ($_=~/_\(\"/o){
90                     $file = unpack("x3 A*",$file) . "\n";
91                     push @buff1, $file;
92                     last;
93                 }
94             }
95         }
96
97         @bufff1 = sort (@buff1);
98
99         @bufff2 = sort (@buf2);
100
101         my %in2;
102         foreach (@bufff2) {
103             $in2{$_} = 1;
104         }
105
106         foreach (@bufff1){
107             if (!exists($in2{$_})){
108                 push @result, $_ }
109             }
110
111         if(@result){
112             open OUT, ">POTFILES.in.missing";
113             print OUT @result;
114             print "\nHere are the results:\n\n", @result, "\n";
115             print "File POTFILES.in.missing is being placed in directory...\n";
116             print "Please add the files that should be ignored in POTFILES.ignore\n";
117         }
118         else{
119             print "\nWell, it's all perfect! Congratulation!\n";
120         }         
121     }
122
123
124     else{
125         print "update.pl: invalid option -- $LANG\n";
126         print "Try `update.pl --help' for more information.\n";
127     }
128     exit;
129     }
130
131 elsif(-s "$LANG.po"){
132
133     print "Building the $PACKAGE.pot ...";
134
135     $c="xgettext --default-domain\=$PACKAGE --directory\=\.\."
136       ." --add-comments --keyword\=\_ --keyword\=N\_"
137       ." --files-from\=\.\/POTFILES\.in ";  
138     $c1="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
139        ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)";
140
141     `$c`;
142     `$c1`;
143
144     print "...done";
145
146     print "\nNow merging $LANG.po with $PACKAGE.pot, and creating an updated $LANG.po ...\n";
147
148     
149     $d="mv $LANG.po $LANG.po.old && msgmerge $LANG.po.old $PACKAGE.pot -o $LANG.po";
150
151     $f="msgfmt --statistics $LANG.po";
152
153     `$d`;
154     `$f`;
155
156     unlink "messages";
157     unlink "$LANG.po.old";
158
159     exit;
160 }
161
162 else{
163     print "update.pl:  sorry $LANG.po does not exist!\n";
164     print "Try `update.pl --help' for more information.\n";    
165     exit;
166 }