2 eval 'exec perl -wS $0 ${1+"$@"}'
5 #*************************************************************************
7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 # Copyright 2008 by Sun Microsystems, Inc.
11 # OpenOffice.org - a multi-platform office productivity suite
13 # $RCSfile: translate.pl,v $
17 # This file is part of OpenOffice.org.
19 # OpenOffice.org is free software: you can redistribute it and/or modify
20 # it under the terms of the GNU Lesser General Public License version 3
21 # only, as published by the Free Software Foundation.
23 # OpenOffice.org is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 # GNU Lesser General Public License version 3 for more details
27 # (a copy is included in the LICENSE file that accompanied this code).
29 # You should have received a copy of the GNU Lesser General Public License
30 # version 3 along with OpenOffice.org. If not, see
31 # <http://www.openoffice.org/license.html>
32 # for a copy of the LGPLv3 License.
34 #*************************************************************************
37 #*********************************************************************
42 my ($prefix, $ext, $key);
43 $productname = "OpenOffice.org";
46 while ($_ = $ARGV[0], /^-/) {
50 $productname = $ARGV[0];
72 unless (open(SOURCE
, $ARGV[0])) {
73 print STDERR
"Can't open $ARGV[0] file: $!\n";
78 # For every section in the specified ulf file there should exist
79 # a template file in $workdir ..
83 if ( "[" eq substr($line, 0, 1) ) {
84 # Pass the tail of the template to the output file
92 system "mv -f $outfile.tmp $outfile\n";
95 $_ = substr($line, 1, index($line,"]")-1);
96 $outfile = "$workdir/$prefix$_.$ext";
98 # open the template file - ignore sections for which no
100 unless(open(TEMPLATE
, $outfile)) {
101 print STDERR
"Warning: No template found for item $_: $outfile: $!\n";
106 unless (open(OUTFILE
, "> $outfile.tmp")) {
107 print STDERR
"Can't create output file $outfile.tmp: $!\n";
111 # Pass the head of the template to the output file
112 KEY
: while (<TEMPLATE
>) {
114 last KEY
if (/$key/);
118 # split locale = "value" into 2 strings
119 ($locale, $value) = split(' = ', $line);
121 if ( $locale ne $line ) {
122 # replace en-US with en
123 $locale=~s/en-US/en/;
125 # use just anything inside the ""
126 $value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
128 # replace resource placeholder
129 $value=~s/%PRODUCTNAME/$productname/g;
132 if ($ext eq "desktop") {
133 print OUTFILE
"$key\[$locale\]=$value\n";
135 print OUTFILE
"\t\[$locale\]$key=$value\n";
145 if (close(OUTFILE
)) {
146 system "mv -f $outfile.tmp $outfile\n";