/[cvs]/eggdrop1.9/po/update.pl
ViewVC logotype

Contents of /eggdrop1.9/po/update.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Thu Dec 18 02:23:39 2003 UTC (15 years, 3 months ago) by wcc
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +8 -1 lines
File MIME type: text/x-perl
* Gettext stuff.

1 #!/usr/bin/perl -w
2
3 #
4 # GNOME PO Update Utility
5 #
6 # $Id: update.pl,v 1.3 2003/02/26 01:51:13 wcc Exp $
7 #
8 # Copyright (C) 2000 Free Software Foundation.
9 #
10 # This script is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; either version 2 of the
13 # License, or (at your option) any later version.
14 #
15 # This script is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this library; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #
24 # Authors: Kenneth Christiansen <kenneth@gnu.org>
25 #
26
27 # NOTICE: Please remember to change the variable $PACKAGE to reflect
28 # the package this script is used within.
29
30 $PACKAGE="eggdrop";
31
32 use File::Basename;
33
34 # Declare global variables
35 #-------------------------
36 my $VERSION = "1.5beta5";
37 my $LANG = $ARGV[0];
38
39 # Always print as the first thing
40 #--------------------------------
41 $| = 1;
42
43 # Figure out what package that is in use
44 #---------------------------------------
45 #open FILE, "../configure.in";
46 # while (<FILE>) {
47 # next if /^dnl/; #ignore comments
48 # if ($_=~/AM_INIT_AUTOMAKE\((.*),(.*)\)/o){
49 # $PACKAGE=$1;
50 # last; #stop when found
51 # }
52 # if ($_=~/PACKAGE\((.*)\)/o){
53 # $PACKAGE=$1;
54 # last; #stop when found
55 # }
56 # }
57 #close FILE;
58
59
60 # Give error if script is run without an argument
61 #------------------------------------------------
62 if (! $LANG){
63 print "update.pl: missing file arguments\n";
64 print "Try `update.pl --help' for more information.\n";
65 exit;
66 }
67
68 # Use the supplied arguments
69 #---------------------------
70 if ($LANG=~/^-(.)*/){
71
72 if ("$LANG" eq "--version" || "$LANG" eq "-V"){
73 &Version;
74 }
75 elsif ($LANG eq "--help" || "$LANG" eq "-H"){
76 &Help;
77 }
78 elsif ($LANG eq "--dist" || "$LANG" eq "-D"){
79 &Merging;
80 }
81 elsif ($LANG eq "--pot" || "$LANG" eq "-P"){
82
83 # Check for .headerlock file, so the Makefile
84 # will not generate the header files twise
85 #--------------------------------------------
86 if (-e ".headerlock"){
87 &GeneratePot;
88 }else{
89 &GenHeaders;
90 &GeneratePot;}
91 exit;
92 }
93 elsif ($LANG eq "--headers" || "$LANG" eq "-S"){
94 &GenHeaders;
95 exit;
96 }
97 elsif ($LANG eq "--maintain" || "$LANG" eq "-M"){
98 &Maintain;
99 }
100 else {
101 &InvalidOption;
102 }
103
104 } else {
105
106 # Run standard procedure
107 #-----------------------
108 if(-s "$LANG.po"){
109 &GenHeaders;
110 &GeneratePot;
111 &Merging;
112 &Status;
113 }
114
115 # Report error if the language file supplied
116 # to the command line is non-existent
117 #-------------------------------------------
118 else {
119 &NotExisting;
120 }
121 }
122
123 sub Version{
124
125 # Print version information
126 #--------------------------
127 print "GNOME PO Updater $VERSION\n";
128 print "Written by Kenneth Christiansen <kenneth\@gnome.org>, 2000.\n\n";
129 print "Copyright (C) 2000 Free Software Foundation, Inc.\n";
130 print "This is free software; see the source for copying conditions. There is NO\n";
131 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
132 exit;
133 }
134
135 sub Help{
136
137 # Print usage information
138 #------------------------
139 print "Usage: ./update.pl [OPTIONS] ...LANGCODE\n";
140 print "Updates pot files and merge them with the translations.\n\n";
141 print " -H, --help shows this help page\n";
142 print " -P, --pot generate the pot file only\n";
143 print " -S, --headers generate the XML headerfiles in POTFILES.in\n";
144 print " -M, --maintain search for missing files in POTFILES.in\n";
145 print " -V, --version shows the version\n";
146 print "\nExamples of use:\n";
147 print "update.sh --pot just creates a new pot file from the source\n";
148 print "update.sh da created new pot file and updated the da.po file\n\n";
149 print "Report bugs to <kenneth\@gnome.org>.\n";
150 exit;
151 }
152
153 sub Maintain{
154
155 # Search and fine, all translatable files
156 # ---------------------------------------
157 $i18nfiles="find ../ -print | egrep '.*\\.(c|y|cc|c++|h|gob)' ";
158
159 open(BUF2, "POTFILES.in") || die "update.pl: there's no POTFILES.in!!!\n";
160
161 print "Searching for missing _(\" \") entries...\n";
162
163 open(BUF1, "$i18nfiles|");
164
165 @buf1_1 = <BUF1>;
166 @buf1_2 = <BUF2>;
167
168 # Check if we should ignore some found files, when
169 # comparing with POTFILES.in
170 #-------------------------------------------------
171 if (-s ".potignore"){
172 open FILE, ".potignore";
173 while (<FILE>) {
174 if ($_=~/^[^#]/o){
175 push @bup, $_;
176 }
177 }
178 print "Found .potignore: Ignoring files...\n";
179 @buf1_2 = (@bup, @buf1_2);
180 }
181
182 foreach my $file (@buf1_1){
183 open FILE, "<$file";
184 while (<FILE>) {
185 if ($_=~/_\(\"/o){
186 $file = unpack("x3 A*",$file) . "\n";
187 push @buf2_1, $file;
188 last;
189 }
190 }
191 }
192
193 @buf3_1 = sort (@buf2_1);
194 @buf3_2 = sort (@buf1_2);
195
196 my %in2;
197 foreach (@buf3_2) {
198 $in2{$_} = 1;
199 }
200
201 foreach (@buf3_1){
202 if (!exists($in2{$_})){
203 push @result, $_
204 }
205 }
206
207 # Save file with information about the files missing
208 # if any, and give information about this proceedier
209 #---------------------------------------------------
210 if(@result){
211 open OUT, ">missing";
212 print OUT @result;
213 print "\nHere is the result:\n\n", @result, "\n";
214 print "The file \"missing\" has been placed in the current directory.\n";
215 print "Files supposed to be ignored should be placed in \".potignore\"\n";
216 }
217
218 # If there is nothing to complain about, notice the user
219 #-------------------------------------------------------
220 else{
221 print "\nWell, it's all perfect! Congratulation!\n";
222 }
223 }
224
225 sub InvalidOption{
226
227 # Handle invalid arguments
228 #-------------------------
229 print "update.pl: invalid option -- $LANG\n";
230 print "Try `update.pl --help' for more information.\n";
231 }
232
233 sub GenHeaders{
234
235 # Generate the .h header files, so we can allow glade and
236 # xml translation support
237 #--------------------------------------------------------
238 if(-s "ui-extract.pl"){
239
240 print "Found ui-extract.pl script\nRunning ui-extract...\n";
241
242 open FILE, "<POTFILES.in";
243 while (<FILE>) {
244
245 # Find .xml files in POTFILES.in and generate the
246 # files with help from the ui-extract.pl script
247 #--------------------------------------------------
248 if ($_=~ /(.*)(\.xml)/o){
249 $filename = "../$1.xml";
250 $xmlfiles="perl \.\/ui-extract.pl --local $filename";
251 system($xmlfiles);
252 }
253
254 # Find .glade files in POTFILES.in and generate
255 # the files with help from the ui-extract.pl script
256 #--------------------------------------------------
257 elsif ($_=~ /(.*)(\.glade)/o){
258 $filename = "../$1.glade";
259 $xmlfiles="perl \.\/ui-extract.pl --local $filename";
260 system($xmlfiles);
261 }
262 }
263 close FILE;
264
265 # Create .headerlock file, so the script will know
266 # that we already passed this section. This is required
267 # since the individual sections can be reaced at different
268 # times by the Makefile
269 #---------------------------------------------------------
270 system("touch .headerlock");
271 }
272 }
273
274 sub GeneratePot{
275
276 # Generate the potfiles from the POTFILES.in file
277 #------------------------------------------------
278
279 print "Building the $PACKAGE.pot...\n";
280
281 system ("mv POTFILES.in POTFILES.in.old");
282
283 open INFILE, "<POTFILES.in.old";
284 open OUTFILE, ">POTFILES.in";
285 while (<INFILE>) {
286 if ($_ =~ /\.(glade|xml)$/) {
287 s/\.glade$/\.glade\.h/;
288 s/\.xml$/\.xml\.h/;
289 $_ = basename($_);
290 $_ = "po/tmp/$_\n";
291 }
292 print OUTFILE $_;
293 }
294 close OUTFILE;
295 close INFILE;
296
297 $GETTEXT ="xgettext --default-domain\=$PACKAGE --directory\=\.\."
298 ." --add-comments --keyword\=\_ --keyword\=N\_ --keyword\=P\_:1,2"
299 ." --files-from\=\.\/POTFILES\.in"
300 ." --copyright-holder=\"Eggheads Development Team\"";
301 $GTEST ="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
302 ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)";
303 $SED ="cat $PACKAGE\.pot \| "
304 ."sed -e \'s/# SOME DESCRIPTIVE TITLE./# $PACKAGE\.pot/g\' "
305 ."-e \'s/# Copyright (C) YEAR Eggheads Development Team/# Copyright (C) 2004 Eggheads Development Team/g\' "
306 ."-e \'s/# This file is distributed under the same license as the PACKAGE package\./# This file is distributed under the same license as the Eggdrop package\./g\' "
307 ."-e \'s/# FIRST AUTHOR <EMAIL\@ADDRESS>, YEAR\.//g\' "
308 ."> $PACKAGE\.pot_ && mv $PACKAGE\.pot_ $PACKAGE\.pot";
309
310 system($GETTEXT);
311 system($GTEST);
312 system($SED);
313 print "Wrote $PACKAGE.pot\n";
314 system("mv POTFILES.in.old POTFILES.in");
315
316 # If .headerlock file is found, it means that the potfiles
317 # already has been generated. If so delete the generated
318 # .h header files. The reason for this approach with a
319 # file as a marker is due to that the Makefile runs the
320 # scripts in turns
321 #---------------------------------------------------------
322
323 if(-e ".headerlock"){
324 unlink(".headerlock");
325
326 print "Removing generated header (.h) files...";
327 system("rm ./tmp/ -rf");
328 }
329 print "done\n";
330 }
331
332 sub Merging{
333
334 if ($ARGV[1]){
335 $LANG = $ARGV[1];
336 } else {
337 $LANG = $ARGV[0];
338 }
339
340 if ($ARGV[0] ne "--dist" && $ARGV[0] ne "-D") {
341 print "Merging $LANG.po with $PACKAGE.pot...";
342 }
343
344 $MERGE="cp $LANG.po $LANG.po.old && msgmerge $LANG.po.old $PACKAGE.pot -o $LANG.po";
345
346 system($MERGE);
347
348 if ($ARGV[0] ne "--dist" && $ARGV[0] ne "-D") {
349 print "\n\n";
350 }
351
352 # Remove the "messages" trash file generated
353 # by gettext, aswell as the backup file
354 #-------------------------------------------
355 unlink "messages";
356 unlink "$LANG.po.old";
357 }
358
359 sub NotExisting{
360
361 # Report error if supplied language
362 # file is non-existant
363 #----------------------------------
364 print "update.pl: sorry, $LANG.po does not exist!\n";
365 print "Try `update.pl --help' for more information.\n";
366 exit;
367 }
368
369 sub Status{
370
371 # Print status information about the po file
372 #-------------------------------------------
373 $STATUS="msgfmt --statistics $LANG.po";
374
375 system($STATUS);
376 print "\n";
377 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23