Warning, /education/analitza/extractplots is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env perl 0002 0003 # Copyright (c) 2012 Pino Toscano <pino@kde.org> 0004 0005 sub usage 0006 { 0007 warn <<"EOF"; 0008 0009 extractplots [OPTIONS] FILENAMES... 0010 0011 This script extract descriptions from Analitza plots and 0012 writes on standard output (usually redirected to rc.cpp) the equivalent 0013 tr() calls so that xgettext can parse them. 0014 0015 --context=name : Give tr() calls a context name: tr(text, "name") 0016 --help|? : Display this summary 0017 0018 EOF 0019 0020 exit; 0021 } 0022 0023 ########################################################################################### 0024 0025 use strict; 0026 use warnings; 0027 use Getopt::Long; 0028 0029 sub escape_to_c($) { 0030 my $text = shift; 0031 0032 $text =~ s/\\/\\\\/g; # escape \ 0033 $text =~ s/\"/\\\"/g; # escape " 0034 0035 return $text; 0036 } 0037 0038 ########################################################################################### 0039 0040 GetOptions ("context=s" => \my $opt_context, # tr() context 0041 "help|?" => \&usage ); 0042 0043 unless (@ARGV) 0044 { 0045 warn "No filename specified"; 0046 exit; 0047 } 0048 0049 ########################################################################################### 0050 0051 sub out_message { 0052 my ($ctxt, $text, @cmnts) = @_; 0053 for my $cmnt (@cmnts) { 0054 print qq|// $cmnt\n|; 0055 } 0056 if (defined $text) { 0057 $text = escape_to_c($text); 0058 if (defined $ctxt) { 0059 $ctxt = escape_to_c($ctxt); 0060 print qq|QObject::tr("$text", "$ctxt");\n|; 0061 } else { 0062 print qq|QObject::tr("$text");\n|; 0063 } 0064 } 0065 } 0066 0067 for my $file_name (@ARGV) 0068 { 0069 my $fh; 0070 0071 unless (open $fh, "<", $file_name) 0072 { 0073 next; 0074 } 0075 0076 while (<$fh>) 0077 { 0078 my $string = $_; 0079 if ($string =~ /.*\/\/ *([^ ]*) *\/\/.*/) 0080 { 0081 my @comments = (); 0082 0083 (my $norm_fname = $file_name) =~ s/^\.\///; 0084 push @comments, "i18n: file: $norm_fname:$."; 0085 out_message($opt_context, $1, @comments); 0086 } 0087 } 0088 0089 close $fh or warn "Failed to close: '$file_name': $!"; 0090 }