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