summaryrefslogtreecommitdiffstats
path: root/pot/extractrc
blob: ab9c5ca6f38065620ca6f0e09def00ba0ee2ce7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/perl

#  NOTE: this script is part of the KDE SDK and added to KDevelop to support KDE 2 application development.
#  The original is located in the KDE CVS module tdesdk/scripts. It gets installed in the same directory as
#  the KDevelop binary to be in your PATH.
#
#  What it does is extract the strings in an application´s .rc file, e.g. testappui.rc, and writes into the pot file
#  where the translations are build with (po-files)
#
#  Added to KDevelop 2000-10-29, Ralf Nolden (nolden@kde.org)

$linenr = 0;
$filename = "";
@filenames = ();

sub writeoutstring($)
{
   print STDOUT "i18n(\"@_[0]\");\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;

open(FILE, $filename);
while ( <FILE> ) {
   $linenr++;

   $string .= $_;   
   chomp($string);
 
   $textstring = '([tT][eE][xX][tT]|string)>';

   if ($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; 
     writeoutstring($text); 
     $string =~ s/^.*<\/$textstring//;
     $intext = 0;
	 if ($linenr != $starting_linenr) {
		print STDERR "there is <text> floating\n";
     }
   }

}

if ($intext == 1) {
 print STDERR "parsing error in $filename $linenr\n";
 exit 1;
}

}