#! /usr/bin/perl
#
# This script extracts messages from kiosk_data.xml
# and writes on standard output (usually redirected to rc.cpp)
# the equivalent i18n() calls so that xgettext can parse them.
#
# It is based on extractrc but differs in the following ways:
# *) Extracts
and tags
# *) Performs equivalent of QString::simplifyWhiteSpace on all strings
#
# known flags:
# --tag=name : extract also the tag name
# --context=name : give all i18n calls a context name: i18n( "name",...)
$filename = "";
@filenames = ();
sub writeoutstring
{
print STDOUT "i18n(\"";
if (@_[0])
{
# We have a I18N context
print STDOUT @_[0];
print STDOUT "\",\"";
}
print STDOUT @_[1];
print STDOUT "\"); // $filename \n";
}
$extratags = "";
$context = ""; # I18N context
ARGUMENTS: while (defined ($ARGV[0]))
{
$_ = shift;
if (/^--tag=(\w+)/) # --tag=name
{
$extratags .= "|" . $1;
next ARGUMENTS;
}
elsif (/^--context=(\w+)/) # --context=name
{
$context = $1;
next ARGUMENTS;
}
$filename = $_; # maybe check for more options
if (! $filename) {
print STDERR "no file to open\n";
exit 1;
}
$string = "";
$intext = 0;
$linenr = 0;
$inskippedprop = 0;
open(FILE, $filename);
READING: while ( ) {
$linenr++;
if ($linenr == 1 && ($_ !~ /^';
# The 'database' property contains strings that shouldn't be translated
if ($inskippedprop == 0 && ($string =~ //g;
$text =~ s/&/&/g;
$text =~ s/\\n/ /g;
$text =~ s/\\([^n])/\\\\$1/g;
$text =~ s/\"/\\\"/g;
$text =~ s/ +/ /g;
$text =~ s/^ //g;
$text =~ s/ $//g;
writeoutstring($context, $text);
$string =~ s/^.*<\/$textstring//;
$intext = 0;
# Text can be multiline in .ui files (possibly), but we warn about it in XMLGUI .rc files.
if ($linenr != $starting_linenr && $filename =~ m/\.rc$/) {
print STDERR "there is floating $filename\n";
}
}
}
if ($intext == 1) {
print STDERR "parsing error in $filename $linenr\n";
exit 1;
}
}