update.pl 4.7 KB

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