4 # See Qt I18N documentation for usage information.
6 use POSIX qw(strftime);
8 $projectid='PROJECT VERSION';
9 $datetime = strftime "%Y-%m-%d %X %Z", localtime;
10 $charset='iso-8859-1';
11 $translator='FULLNAME <EMAIL@ADDRESS>';
12 $revision_date='YYYY-MM-DD';
15 $noop_mark = "QT_TR_NOOP";
16 $scoped_mark = "qApp->translate";
17 $noop_scoped_mark = "QT_TRANSLATE_NOOP";
20 '# This is a Qt message file in .po format. Each msgid starts with
21 # a scope. This scope should *NOT* be translated - eg. translating
22 # from French to English, "Foo::Bar" would be translated to "Pub",
26 "Project-Id-Version: '.$projectid.'\n"
27 "POT-Creation-Date: '.$datetime.'\n"
28 "PO-Revision-Date: '.$revision_date.'\n"
29 "Last-Translator: '.$translator.'\n"
30 "Content-Type: text/plain; charset='.$charset.'\n"
40 print STDERR "Usage: findtr sourcefile ... >project.po\n";
46 my ($file, $line, $scope, $msgid) = @_;
48 $msgid =~ s/$esc:$esc:$esc/::/gs;
49 $msgid =~ s|$esc/$esc/$esc|//|gs;
52 $msgid =~ s/\n\n+/\n/gs;
53 $msgid = "\"\"\n$msgid" if $msgid =~ /\n/s;
54 print "#: $file:$line\n";
55 $msgid =~ s/^"//; #"emacs bug
56 print "msgid \"${scope}::$msgid\n";
57 #print "msgstr \"$msgid\n";
58 print "msgstr \"\"\n";
71 foreach $file ( @ARGV ) {
72 next unless open( I, "< $file" );
74 $source = join( "", <I> );
76 # Find esc. Avoid bad case 1/// -> 1/1/1/1 -> ///1
78 while ( $source =~ m!(?:$esc/$esc/$esc)|(?:$esc///)
79 |(?:$esc:$esc:$esc)|(?:$esc:\:\:)! ) {
83 # Hide quoted :: in practically all strings
84 $source =~ s/\"([^"\n]*)::([^"\n]*)\"/\"$1$esc:$esc:$esc$2\"/g;
86 # Hide quoted // in practically all strings
87 $source =~ s|\"([^"\n]*)//([^"\n]*)\"|\"$1$esc/$esc/$esc$2\"|g;
90 # strip comments -- does not handle "/*" in strings
91 while( $source =~ s|/\*(.*?)\*/|justlines($1)|ges ) { }
92 while( $source =~ s|//(.*?)\n|\n|g ) { }
96 # Some doublequotes are "escaped" to help vim syntax highlight
98 # $1 = scope; $2 = parameters etc.
100 # Scoped function name ($1 is scope).
103 # Parameters etc up to open-curly - no semicolons
109 # $3 - one-argument msgid
112 (?:$real_mark|$noop_mark)
115 \(\s*((?:"(?:[^"]|[^\\]\\")*"\s*)+)\)
118 # $4,$5 - two-argument msgid
120 # One of the scoped marks
121 (?:$scoped_mark|$noop_scoped_mark)
125 # The scope parameter
128 # The msgid parameter
129 \s*((?:\"(?:[^"]|[^\\]\\")*"\s*)+) #"emacs
133 # $6,$7 - scoped one-argument msgid
141 \(\s*((?:"(?:[^"]|[^\\]\\")*"\s*)+)\)
145 @lines = split /^/m, "$`";
147 if ( defined( $1 ) ) {
148 if ( $scope ne $1 ) {
152 $etc =~ s/"(?:[^"]|[^\\]\\")"//g;
154 @open = split /\(/m, $etc;
155 @close = split /\)/m, $etc;
156 if ( $#open == $#close ) {
163 if ( defined( $3 ) ) {
164 $this_scope = $scope;
166 } elsif ( defined( $4 ) ) {
169 } elsif ( defined( $6 ) ) {
179 # Might still be non-unique eg. tr("A" "B") vs. tr("A" "B").
181 $location{"${this_scope}::${msgid}"} = "$file:$line";
185 for $scoped_msgid ( sort keys %location ) {
186 ($scope,$msgid) = $scoped_msgid =~ m/([^:]*)::(.*)/s;
187 ($file,$line) = $location{$scoped_msgid} =~ m/([^:]*):(.*)/s;
188 outmsg($file,$line,$scope,$msgid);