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