3 #*************************************************************************
5 # OpenOffice.org - a multi-platform office productivity suite
7 # $RCSfile: translate_res_file.pl,v $
11 # last change: $Author: andreschnabel $ $Date: 2007/02/18 12:01:54 $
13 # The Contents of this file are made available subject to
14 # the terms of GNU Lesser General Public License Version 2.1.
17 # GNU Lesser General Public License Version 2.1
18 # =============================================
19 # Copyright 2005 by Sun Microsystems, Inc.
20 # 901 San Antonio Road, Palo Alto, CA 94303, USA
22 # This library is free software; you can redistribute it and/or
23 # modify it under the terms of the GNU Lesser General Public
24 # License version 2.1, as published by the Free Software Foundation.
26 # This library is distributed in the hope that it will be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 # Lesser General Public License for more details.
31 # You should have received a copy of the GNU Lesser General Public
32 # License along with this library; if not, write to the Free Software
33 # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
36 #*************************************************************************
39 # This Perl sciprt translates *.res files of qatesttool into human
41 #*************************************************************************
46 $0 - translates
*.res files of qatesttool into readable format
52 --help prints this message
.
53 --testtoolrc
=filename specifies
.testtoolrc
(default: \
$HOME/.testtoolrc
)
54 --with
-filename inserts filename
:linenumber
:, which helps users go there with emacs
55 --lang
=language specifies language
defined in app
.srs
(default: \
$LANG)
56 --app_srs
=filename specifies resource file app
.srs
(default: ./app
.srs
)
57 --with
-color outputs colored translated messages using ANSI color sequence code
60 This Perl sciprt translates
*.res files produced by qatesttool
61 into human readable text file format
.
64 perl translate_res_file
.pl topten
.res
70 $Opt_With_Filename = 0;
73 use Env
qw( LANG HOME );
90 %LogTypeColor = qw( 0 none
102 my ($file, $lineno, $line) = @_;
103 my ($id, $arg1, $arg2, $arg3) =
104 ($line =~ m
/\
%ResId=([0-9]+)\
%
107 (?
:\
%Arg3=(.+?
)\
%)?
/x
);
108 my $text = $Resource{$id};
110 $text =~ s/\(\$Arg1\)/$arg1/ if ($text =~ m/\(\$Arg1\)/);
111 $text =~ s/\(\$Arg2\)/$arg2/ if ($text =~ m/\(\$Arg2\)/);
112 $text =~ s/\(\$Arg3\)/$arg3/ if ($text =~ m/\(\$Arg3\)/);
116 print STDERR
"$file:$lineno: Unknown String: $line\n";
122 my ($line, $lineno, $log_type);
123 open FH
, "$file" or die "$!: $file, stopped";
125 unless (m/\A[0-9]+;/) {
133 my ($type, $_filename, $_lineno, $start, $end, $text) = split(m/;/, $_, 6);
134 $text = "" unless defined $text;
135 $text =~ s/(\%ResId=.+%)/ substitution($file, $lineno, $1) /e;
139 $log_type = $LogType{$type} || "Unknown LogType";
140 if (defined $_filename and $_filename ne "") {
141 $_filename =~ s/\A\~-//g;
142 $_filename =~ s/\A\~/$BaseDir\//g
if defined $BaseDir;
143 $_filename =~ s{\\}{/}g;
144 print "$_filename:$_lineno: " if $Opt_With_Filename;
146 if ($With_Color and $LogTypeColor{$type} ne "none") {
147 print colored
("$log_type: $text", $LogTypeColor{$type});
151 print "$log_type: $text\n";
160 open FH
, "<", $file or do {
161 warn "Warning: $!: $file; BaseDir substitution will be suppressed;";
165 if (m/\ABaseDir=(.*)/) {
168 $dir =~ s/(\r|\n)+\Z//;
179 my ($id, $text, $fallback);
181 unless (defined $lang) {
182 $lang = $LANG || "C";
184 $lang = substr($lang, 0, 2);
185 $lang = "en-US" if $lang eq "en" or $lang eq "C";
188 open FH
, $file or die "Error: $!: $file, stopped";
191 if (m/\AString\s+([0-9]+)/) {
199 $text = $fallback unless defined $text;
203 $Resource{$id} = $text;
204 #print "$id\t$text\n";
208 if (m/Text = "(.+?)";\Z/) {
212 if (m/Text\[ (.+?) \] = "(.+?)";\Z/) {
214 $fallback = $text if ($x eq "en-US");
215 $text = $2 if ($x eq $lang);
223 my $testtoolrc = "$HOME/.testtoolrc";
225 my $app_srs = "app.srs";
226 my $result = GetOptions
( "help" => \
$opt_help,
227 "testtoolrc=s" => \
$testtoolrc,
228 "with-filename" => \
$Opt_With_Filename,
229 "language=s" => \
$language,
230 "app_srs=s" => \
$app_srs,
231 "with-color" => \
$With_Color,
233 if (scalar(@ARGV) <= 0 or !$result or $opt_help) {
238 $BaseDir = getBaseDir
($testtoolrc);
239 load_app_srs
($app_srs, $language);
240 foreach $file (@ARGV) {