Update ooo320-m1
[ooovba.git] / sysui / desktop / share / translate.pl
blob8ae555792bdd07d2f67d0711221c4c00f3904826
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
5 #*************************************************************************
7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 #
9 # Copyright 2008 by Sun Microsystems, Inc.
11 # OpenOffice.org - a multi-platform office productivity suite
13 # $RCSfile: translate.pl,v $
15 # $Revision: 1.7 $
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 #*********************************************************************
39 # main
42 my ($prefix, $ext, $key);
43 $productname = "OpenOffice.org";
44 $workdir = ".";
46 while ($_ = $ARGV[0], /^-/) {
47 shift;
48 last if /^--$/;
49 if (/^-p/) {
50 $productname = $ARGV[0];
51 shift;
53 if (/^-d/) {
54 $workdir = $ARGV[0];
55 shift;
57 if (/^--key/) {
58 $key = $ARGV[0];
59 shift;
61 if (/^--prefix/) {
62 $prefix = $ARGV[0];
63 shift;
65 if (/^--ext/) {
66 $ext = $ARGV[0];
67 shift;
71 # open input file
72 unless (open(SOURCE, $ARGV[0])) {
73 print STDERR "Can't open $ARGV[0] file: $!\n";
74 return;
78 # For every section in the specified ulf file there should exist
79 # a template file in $workdir ..
80 while (<SOURCE>) {
81 $line = $_;
83 if ( "[" eq substr($line, 0, 1) ) {
84 # Pass the tail of the template to the output file
85 while (<TEMPLATE>) {
86 print OUTFILE;
89 close(TEMPLATE);
91 if (close(OUTFILE)) {
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
99 # templates exist
100 unless(open(TEMPLATE, $outfile)) {
101 print STDERR "Warning: No template found for item $_: $outfile: $!\n";
102 next;
105 # open output file
106 unless (open(OUTFILE, "> $outfile.tmp")) {
107 print STDERR "Can't create output file $outfile.tmp: $!\n";
108 exit -1;
111 # Pass the head of the template to the output file
112 KEY: while (<TEMPLATE>) {
113 print OUTFILE;
114 last KEY if (/$key/);
117 } else {
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;
131 $locale=~s/-/_/;
132 if ($ext eq "desktop") {
133 print OUTFILE "$key\[$locale\]=$value\n";
134 } else {
135 print OUTFILE "\t\[$locale\]$key=$value\n";
141 while (<TEMPLATE>) {
142 print OUTFILE;
145 if (close(OUTFILE)) {
146 system "mv -f $outfile.tmp $outfile\n";
149 close(TEMPLATE);