summaryrefslogtreecommitdiffstats
path: root/kregexpeditor/extractrc-from-regexp
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
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /kregexpeditor/extractrc-from-regexp
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.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/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kregexpeditor/extractrc-from-regexp')
-rwxr-xr-xkregexpeditor/extractrc-from-regexp85
1 files changed, 85 insertions, 0 deletions
diff --git a/kregexpeditor/extractrc-from-regexp b/kregexpeditor/extractrc-from-regexp
new file mode 100755
index 0000000..70c30ad
--- /dev/null
+++ b/kregexpeditor/extractrc-from-regexp
@@ -0,0 +1,85 @@
+#! /usr/bin/perl
+# This file is a modified version of extractrc, with the only addition that it Title|Description in the textstring regexp.
+#
+# 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.
+
+$filename = "";
+@filenames = ();
+
+sub writeoutstring($)
+{
+ print STDOUT "i18n(\"@_[0]\"); // $filename \n";
+}
+
+while (defined ($ARGV[0]))
+{
+ $_ = shift;
+ $filename = $_; # maybe check for 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]|[tT]itle|[dD]escription|string|whatsthis|tooltip)>';
+
+ # The 'database' property contains strings that shouldn't be translated
+ if ($inskippedprop == 0 && ($string =~ /<property name=\"database\"/)) {
+ $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/\"/\\\"/g;
+ writeoutstring($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;
+}
+
+}