summaryrefslogtreecommitdiffstats
path: root/kommander/working/extractkmdr
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite9ae80694875f869892f13f4fcaf1170a00dea41 (patch)
treeaa2f8d8a217e2d376224c8d46b7397b68d35de2d /kommander/working/extractkmdr
downloadtdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.tar.gz
tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kommander/working/extractkmdr')
-rwxr-xr-xkommander/working/extractkmdr112
1 files changed, 112 insertions, 0 deletions
diff --git a/kommander/working/extractkmdr b/kommander/working/extractkmdr
new file mode 100755
index 00000000..ea1da6ff
--- /dev/null
+++ b/kommander/working/extractkmdr
@@ -0,0 +1,112 @@
+#! /usr/bin/perl
+#
+# This script extracts messages from designer (.ui) and XMLGIU (.rc) files
+# and writes on standard output (usually redirected to rc.cpp)
+# the equivalent i18n() calls so that xgettext can parse them.
+
+# known flags:
+# --tag=name : extract also the tag name
+# --contect=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 ( <FILE> ) {
+ $linenr++;
+ if ($linenr == 1 && ($_ !~ /^<!DOCTYPE/) && ($_ !~ /^<\?xml/)) {
+ last READING;
+ }
+
+ $string .= "\\n" . $_;
+ chomp($string);
+
+ $textstring = '([tT][eE][xX][tT]|title|string|whatsthis|tooltip|label' . $extratags .')>';
+
+ # The 'database' property contains strings that shouldn't be translated
+ if ($inskippedprop == 0 && ($string =~ /<property name=\"database\"/ || $string =~ /<property name=\"populationText\"/ || $string=~ /<property name=\"associations\"/)) {
+ $inskippedprop = 1;
+ } elsif ($inskippedprop == 1 && ($string =~ /<\/property/)) {
+ $inskippedprop = 0;
+ $string = "";
+ }
+
+ if ($inskippedprop == 0 && $intext == 0) {
+ if ($string =~ /<$textstring/) {
+ $string =~ s/^.*<$textstring//;
+ $intext = 1;
+ $starting_linenr = $linenr;
+ } else {
+ $string = "";
+ }
+ }
+
+ if (($intext == 1) && ($string =~ /<\/$textstring/)) {
+ my $text = $string;
+ $text =~ s/<\/$textstring.*$//;
+ $text =~ s/&lt;/</g;
+ $text =~ s/&gt;/>/g;
+ $text =~ s/&amp;/&/g;
+ $text =~ s/\\([^n])/\\\\$1/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 <text> floating $filename\n";
+ }
+ }
+
+}
+
+if ($intext == 1) {
+ print STDERR "parsing error in $filename $linenr\n";
+ exit 1;
+}
+
+}