5180
+ 鐃緒申 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 = "gaim";
+ 鐃緒申 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 }