xref: /aoo4110/main/sysui/desktop/share/translate.pl (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielski:
2*b1cdbd2cSJim Jagielskieval 'exec perl -wS $0 ${1+"$@"}'
3*b1cdbd2cSJim Jagielski	if 0;
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski#**************************************************************
6*b1cdbd2cSJim Jagielski#
7*b1cdbd2cSJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
8*b1cdbd2cSJim Jagielski#  or more contributor license agreements.  See the NOTICE file
9*b1cdbd2cSJim Jagielski#  distributed with this work for additional information
10*b1cdbd2cSJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
11*b1cdbd2cSJim Jagielski#  to you under the Apache License, Version 2.0 (the
12*b1cdbd2cSJim Jagielski#  "License"); you may not use this file except in compliance
13*b1cdbd2cSJim Jagielski#  with the License.  You may obtain a copy of the License at
14*b1cdbd2cSJim Jagielski#
15*b1cdbd2cSJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
16*b1cdbd2cSJim Jagielski#
17*b1cdbd2cSJim Jagielski#  Unless required by applicable law or agreed to in writing,
18*b1cdbd2cSJim Jagielski#  software distributed under the License is distributed on an
19*b1cdbd2cSJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20*b1cdbd2cSJim Jagielski#  KIND, either express or implied.  See the License for the
21*b1cdbd2cSJim Jagielski#  specific language governing permissions and limitations
22*b1cdbd2cSJim Jagielski#  under the License.
23*b1cdbd2cSJim Jagielski#
24*b1cdbd2cSJim Jagielski#**************************************************************
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski#*********************************************************************
30*b1cdbd2cSJim Jagielski#
31*b1cdbd2cSJim Jagielski# main
32*b1cdbd2cSJim Jagielski#
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielskimy ($prefix, $ext, $key);
35*b1cdbd2cSJim Jagielski$productname = "OpenOffice";
36*b1cdbd2cSJim Jagielski$workdir = ".";
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielskiwhile ($_ = $ARGV[0], /^-/) {
39*b1cdbd2cSJim Jagielski    shift;
40*b1cdbd2cSJim Jagielski    last if /^--$/;
41*b1cdbd2cSJim Jagielski    if (/^-p/) {
42*b1cdbd2cSJim Jagielski        $productname = $ARGV[0];
43*b1cdbd2cSJim Jagielski        shift;
44*b1cdbd2cSJim Jagielski    }
45*b1cdbd2cSJim Jagielski    if (/^-d/) {
46*b1cdbd2cSJim Jagielski        $workdir = $ARGV[0];
47*b1cdbd2cSJim Jagielski        shift;
48*b1cdbd2cSJim Jagielski    }
49*b1cdbd2cSJim Jagielski    if (/^--key/) {
50*b1cdbd2cSJim Jagielski        $key = $ARGV[0];
51*b1cdbd2cSJim Jagielski        shift;
52*b1cdbd2cSJim Jagielski    }
53*b1cdbd2cSJim Jagielski    if (/^--prefix/) {
54*b1cdbd2cSJim Jagielski        $prefix = $ARGV[0];
55*b1cdbd2cSJim Jagielski        shift;
56*b1cdbd2cSJim Jagielski    }
57*b1cdbd2cSJim Jagielski    if (/^--ext/) {
58*b1cdbd2cSJim Jagielski        $ext = $ARGV[0];
59*b1cdbd2cSJim Jagielski        shift;
60*b1cdbd2cSJim Jagielski    }
61*b1cdbd2cSJim Jagielski}
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski# open input file
64*b1cdbd2cSJim Jagielskiunless (open(SOURCE, $ARGV[0])) {
65*b1cdbd2cSJim Jagielski    print STDERR "Can't open $ARGV[0] file: $!\n";
66*b1cdbd2cSJim Jagielski    return;
67*b1cdbd2cSJim Jagielski}
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski
70*b1cdbd2cSJim Jagielski# For every section in the specified ulf file there should exist
71*b1cdbd2cSJim Jagielski# a template file in $workdir ..
72*b1cdbd2cSJim Jagielskiwhile (<SOURCE>) {
73*b1cdbd2cSJim Jagielski    $line = $_;
74*b1cdbd2cSJim Jagielski
75*b1cdbd2cSJim Jagielski    if ( "[" eq substr($line, 0, 1) ) {
76*b1cdbd2cSJim Jagielski        # Pass the tail of the template to the output file
77*b1cdbd2cSJim Jagielski        while (<TEMPLATE>) {
78*b1cdbd2cSJim Jagielski            print OUTFILE;
79*b1cdbd2cSJim Jagielski        }
80*b1cdbd2cSJim Jagielski
81*b1cdbd2cSJim Jagielski        close(TEMPLATE);
82*b1cdbd2cSJim Jagielski
83*b1cdbd2cSJim Jagielski        if (close(OUTFILE)) {
84*b1cdbd2cSJim Jagielski            system "mv -f $outfile.tmp $outfile\n";
85*b1cdbd2cSJim Jagielski        }
86*b1cdbd2cSJim Jagielski
87*b1cdbd2cSJim Jagielski        $_ = substr($line, 1, index($line,"]")-1);
88*b1cdbd2cSJim Jagielski        $outfile = "$workdir/$prefix$_.$ext";
89*b1cdbd2cSJim Jagielski
90*b1cdbd2cSJim Jagielski        # open the template file - ignore sections for which no
91*b1cdbd2cSJim Jagielski        # templates exist
92*b1cdbd2cSJim Jagielski        unless(open(TEMPLATE, $outfile)) {
93*b1cdbd2cSJim Jagielski            print STDERR "Warning: No template found for item $_: $outfile: $!\n";
94*b1cdbd2cSJim Jagielski            next;
95*b1cdbd2cSJim Jagielski        }
96*b1cdbd2cSJim Jagielski
97*b1cdbd2cSJim Jagielski    	# open output file
98*b1cdbd2cSJim Jagielski        unless (open(OUTFILE, "> $outfile.tmp")) {
99*b1cdbd2cSJim Jagielski            print STDERR "Can't create output file $outfile.tmp: $!\n";
100*b1cdbd2cSJim Jagielski    	    exit -1;
101*b1cdbd2cSJim Jagielski        }
102*b1cdbd2cSJim Jagielski
103*b1cdbd2cSJim Jagielski        # Pass the head of the template to the output file
104*b1cdbd2cSJim JagielskiKEY:    while (<TEMPLATE>) {
105*b1cdbd2cSJim Jagielski            print OUTFILE;
106*b1cdbd2cSJim Jagielski            last KEY if (/$key/);
107*b1cdbd2cSJim Jagielski        }
108*b1cdbd2cSJim Jagielski
109*b1cdbd2cSJim Jagielski    } else {
110*b1cdbd2cSJim Jagielski        # split locale = "value" into 2 strings
111*b1cdbd2cSJim Jagielski        ($locale, $value) = split(' = ', $line);
112*b1cdbd2cSJim Jagielski
113*b1cdbd2cSJim Jagielski        if ( $locale ne $line ) {
114*b1cdbd2cSJim Jagielski            # replace en-US with en
115*b1cdbd2cSJim Jagielski            $locale=~s/en-US/en/;
116*b1cdbd2cSJim Jagielski
117*b1cdbd2cSJim Jagielski            # use just anything inside the ""
118*b1cdbd2cSJim Jagielski            $value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim Jagielski            # replace resource placeholder
121*b1cdbd2cSJim Jagielski            $value=~s/%PRODUCTNAME/$productname/g;
122*b1cdbd2cSJim Jagielski
123*b1cdbd2cSJim Jagielski            $locale=~s/-/_/;
124*b1cdbd2cSJim Jagielski            if ($ext eq "desktop") {
125*b1cdbd2cSJim Jagielski                print OUTFILE "$key\[$locale\]=$value\n";
126*b1cdbd2cSJim Jagielski            } else {
127*b1cdbd2cSJim Jagielski                print OUTFILE  "\t\[$locale\]$key=$value\n";
128*b1cdbd2cSJim Jagielski            }
129*b1cdbd2cSJim Jagielski        }
130*b1cdbd2cSJim Jagielski    }
131*b1cdbd2cSJim Jagielski}
132*b1cdbd2cSJim Jagielski
133*b1cdbd2cSJim Jagielskiwhile (<TEMPLATE>) {
134*b1cdbd2cSJim Jagielski    print OUTFILE;
135*b1cdbd2cSJim Jagielski}
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim Jagielskiif (close(OUTFILE)) {
138*b1cdbd2cSJim Jagielski    system "mv -f $outfile.tmp $outfile\n";
139*b1cdbd2cSJim Jagielski}
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielskiclose(TEMPLATE);
142