separated_to_hash.pl 953 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #! /usr/bin/perl -w
  2. use strict;
  3. use Data::Dumper;
  4. my $lang = shift @ARGV;
  5. my $separator = quotemeta ('||qg::fd||');
  6. my $in_msgid = 1;
  7. my $text = '';
  8. my $msgid = '';
  9. my $LANGUAGES;
  10. while (<STDIN>)
  11. {
  12. my $separated = 0;
  13. if (/^(.*)$separator$/)
  14. {
  15. $text .= $1;
  16. $separated = 1;
  17. }
  18. else
  19. {
  20. $text .= $_;
  21. }
  22. #print STDERR " --> ($separated) ($in_msgid)\n";
  23. if ($separated)
  24. {
  25. if ($in_msgid)
  26. {
  27. $msgid = $text;
  28. $in_msgid = 0;
  29. }
  30. else
  31. {
  32. #print "\n$msgid === $text|\n";
  33. #$LANGUAGES->{$lang}->{$msgid} = $text if ($text !~ /^Project-Id-Version/);
  34. $LANGUAGES->{$lang}->{$msgid} = $text if ($msgid ne '');
  35. $in_msgid = 1;
  36. }
  37. $text = '';
  38. }
  39. }
  40. $Data::Dumper::Sortkeys = 1;
  41. print "# Automatically generated file. Edit the .po file instead.\n";
  42. print "" . Data::Dumper->Dump([$LANGUAGES->{$lang}], [ "LANGUAGES->{'$lang'}" ]);