update.pl 4.7 KB

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