KioskTool – tool to configure the TDE kiosk framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extractxml 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #! /usr/bin/perl
  2. #
  3. # This script extracts messages from kiosk_data.xml
  4. # and writes on standard output (usually redirected to rc.cpp)
  5. # the equivalent i18n() calls so that xgettext can parse them.
  6. #
  7. # It is based on extractrc but differs in the following ways:
  8. # *) Extracts <caption> and <description> tags
  9. # *) Performs equivalent of QString::simplifyWhiteSpace on all strings
  10. #
  11. # known flags:
  12. # --tag=name : extract also the tag name
  13. # --context=name : give all i18n calls a context name: i18n( "name",...)
  14. $filename = "";
  15. @filenames = ();
  16. sub writeoutstring
  17. {
  18. print STDOUT "i18n(\"";
  19. if (@_[0])
  20. {
  21. # We have a I18N context
  22. print STDOUT @_[0];
  23. print STDOUT "\",\"";
  24. }
  25. print STDOUT @_[1];
  26. print STDOUT "\"); // $filename \n";
  27. }
  28. $extratags = "";
  29. $context = ""; # I18N context
  30. ARGUMENTS: while (defined ($ARGV[0]))
  31. {
  32. $_ = shift;
  33. if (/^--tag=(\w+)/) # --tag=name
  34. {
  35. $extratags .= "|" . $1;
  36. next ARGUMENTS;
  37. }
  38. elsif (/^--context=(\w+)/) # --context=name
  39. {
  40. $context = $1;
  41. next ARGUMENTS;
  42. }
  43. $filename = $_; # maybe check for more options
  44. if (! $filename) {
  45. print STDERR "no file to open\n";
  46. exit 1;
  47. }
  48. $string = "";
  49. $intext = 0;
  50. $linenr = 0;
  51. $inskippedprop = 0;
  52. open(FILE, $filename);
  53. READING: while ( <FILE> ) {
  54. $linenr++;
  55. if ($linenr == 1 && ($_ !~ /^<!DOCTYPE/) && ($_ !~ /^<\?xml/)) {
  56. last READING;
  57. }
  58. $string .= "\\n" . $_;
  59. chomp($string);
  60. $textstring = '(caption|description' . $extratags .')>';
  61. # The 'database' property contains strings that shouldn't be translated
  62. if ($inskippedprop == 0 && ($string =~ /<property name=\"database\"/ || $string=~ /<property name=\"associations\"/)) {
  63. $inskippedprop = 1;
  64. } elsif ($inskippedprop == 1 && ($string =~ /<\/property/)) {
  65. $inskippedprop = 0;
  66. $string = "";
  67. }
  68. if ($inskippedprop == 0 && $intext == 0) {
  69. if ($string =~ /<$textstring/) {
  70. $string =~ s/^.*<$textstring//;
  71. $intext = 1;
  72. $starting_linenr = $linenr;
  73. } else {
  74. $string = "";
  75. }
  76. }
  77. if (($intext == 1) && ($string =~ /<\/$textstring/)) {
  78. my $text = $string;
  79. $text =~ s/<\/$textstring.*$//;
  80. $text =~ s/&lt;/</g;
  81. $text =~ s/&gt;/>/g;
  82. $text =~ s/&amp;/&/g;
  83. $text =~ s/\\n/ /g;
  84. $text =~ s/\\([^n])/\\\\$1/g;
  85. $text =~ s/\"/\\\"/g;
  86. $text =~ s/ +/ /g;
  87. $text =~ s/^ //g;
  88. $text =~ s/ $//g;
  89. writeoutstring($context, $text);
  90. $string =~ s/^.*<\/$textstring//;
  91. $intext = 0;
  92. # Text can be multiline in .ui files (possibly), but we warn about it in XMLGUI .rc files.
  93. if ($linenr != $starting_linenr && $filename =~ m/\.rc$/) {
  94. print STDERR "there is <text> floating $filename\n";
  95. }
  96. }
  97. }
  98. if ($intext == 1) {
  99. print STDERR "parsing error in $filename $linenr\n";
  100. exit 1;
  101. }
  102. }