3 #############################################################################
5 ## Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
6 ## Contact: http://www.qt-project.org/
8 ## This file is part of the translations of the Qt Toolkit.
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## GNU Lesser General Public License Usage
12 ## This file may be used under the terms of the GNU Lesser General Public
13 ## License version 2.1 as published by the Free Software Foundation and
14 ## appearing in the file LICENSE.LGPL included in the packaging of this
15 ## file. Please review the following information to ensure the GNU Lesser
16 ## General Public License version 2.1 requirements will be met:
17 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ## In addition, as a special exception, Nokia gives you certain additional
20 ## rights. These rights are described in the Nokia Qt LGPL Exception
21 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ## GNU General Public License Usage
24 ## Alternatively, this file may be used under the terms of the GNU General
25 ## Public License version 3.0 as published by the Free Software Foundation
26 ## and appearing in the file LICENSE.GPL included in the packaging of this
27 ## file. Please review the following information to ensure the GNU General
28 ## Public License version 3.0 requirements will be met:
29 ## http://www.gnu.org/copyleft/gpl.html.
32 ## Alternatively, this file may be used in accordance with the terms and
33 ## conditions contained in a signed written agreement between you and Nokia.
42 #############################################################################
44 # See Qt I18N documentation for usage information.
46 use POSIX qw(strftime);
48 $projectid='PROJECT VERSION';
49 $datetime = strftime "%Y-%m-%d %X %Z", localtime;
50 $charset='iso-8859-1';
51 $translator='FULLNAME <EMAIL@ADDRESS>';
52 $revision_date='YYYY-MM-DD';
55 $noop_mark = "QT_TR_NOOP";
56 $scoped_mark = "qApp->translate";
57 $noop_scoped_mark = "QT_TRANSLATE_NOOP";
60 '# This is a Qt message file in .po format. Each msgid starts with
61 # a scope. This scope should *NOT* be translated - eg. translating
62 # from French to English, "Foo::Bar" would be translated to "Pub",
66 "Project-Id-Version: '.$projectid.'\n"
67 "POT-Creation-Date: '.$datetime.'\n"
68 "PO-Revision-Date: '.$revision_date.'\n"
69 "Last-Translator: '.$translator.'\n"
70 "Content-Type: text/plain; charset='.$charset.'\n"
80 print STDERR "Usage: findtr sourcefile ... >project.po\n";
86 my ($file, $line, $scope, $msgid) = @_;
88 $msgid =~ s/$esc:$esc:$esc/::/gs;
89 $msgid =~ s|$esc/$esc/$esc|//|gs;
92 $msgid =~ s/\n\n+/\n/gs;
93 $msgid = "\"\"\n$msgid" if $msgid =~ /\n/s;
94 print "#: $file:$line\n";
95 $msgid =~ s/^"//; #"emacs bug
96 print "msgid \"${scope}::$msgid\n";
97 #print "msgstr \"$msgid\n";
98 print "msgstr \"\"\n";
111 foreach $file ( @ARGV ) {
112 next unless open( I, "< $file" );
114 $source = join( "", <I> );
116 # Find esc. Avoid bad case 1/// -> 1/1/1/1 -> ///1
118 while ( $source =~ m!(?:$esc/$esc/$esc)|(?:$esc///)
119 |(?:$esc:$esc:$esc)|(?:$esc:\:\:)! ) {
123 # Hide quoted :: in practically all strings
124 $source =~ s/\"([^"\n]*)::([^"\n]*)\"/\"$1$esc:$esc:$esc$2\"/g;
126 # Hide quoted // in practically all strings
127 $source =~ s|\"([^"\n]*)//([^"\n]*)\"|\"$1$esc/$esc/$esc$2\"|g;
130 # strip comments -- does not handle "/*" in strings
131 while( $source =~ s|/\*(.*?)\*/|justlines($1)|ges ) { }
132 while( $source =~ s|//(.*?)\n|\n|g ) { }
136 # Some doublequotes are "escaped" to help vim syntax highlight
138 # $1 = scope; $2 = parameters etc.
140 # Scoped function name ($1 is scope).
143 # Parameters etc up to open-curly - no semicolons
149 # $3 - one-argument msgid
152 (?:$real_mark|$noop_mark)
155 \(\s*((?:"(?:[^"]|[^\\]\\")*"\s*)+)\)
158 # $4,$5 - two-argument msgid
160 # One of the scoped marks
161 (?:$scoped_mark|$noop_scoped_mark)
165 # The scope parameter
168 # The msgid parameter
169 \s*((?:\"(?:[^"]|[^\\]\\")*"\s*)+) #"emacs
173 # $6,$7 - scoped one-argument msgid
181 \(\s*((?:"(?:[^"]|[^\\]\\")*"\s*)+)\)
185 @lines = split /^/m, "$`";
187 if ( defined( $1 ) ) {
188 if ( $scope ne $1 ) {
192 $etc =~ s/"(?:[^"]|[^\\]\\")"//g;
194 @open = split /\(/m, $etc;
195 @close = split /\)/m, $etc;
196 if ( $#open == $#close ) {
203 if ( defined( $3 ) ) {
204 $this_scope = $scope;
206 } elsif ( defined( $4 ) ) {
209 } elsif ( defined( $6 ) ) {
219 # Might still be non-unique eg. tr("A" "B") vs. tr("A" "B").
221 $location{"${this_scope}::${msgid}"} = "$file:$line";
225 for $scoped_msgid ( sort keys %location ) {
226 ($scope,$msgid) = $scoped_msgid =~ m/([^:]*)::(.*)/s;
227 ($file,$line) = $location{$scoped_msgid} =~ m/([^:]*):(.*)/s;
228 outmsg($file,$line,$scope,$msgid);