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