xref: /aoo41x/main/sysui/desktop/share/translate.pl (revision cdf0e10c)
1:
2eval 'exec perl -wS $0 ${1+"$@"}'
3	if 0;
4
5#*************************************************************************
6#
7# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8#
9# Copyright 2000, 2010 Oracle and/or its affiliates.
10#
11# OpenOffice.org - a multi-platform office productivity suite
12#
13# This file is part of OpenOffice.org.
14#
15# OpenOffice.org is free software: you can redistribute it and/or modify
16# it under the terms of the GNU Lesser General Public License version 3
17# only, as published by the Free Software Foundation.
18#
19# OpenOffice.org is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22# GNU Lesser General Public License version 3 for more details
23# (a copy is included in the LICENSE file that accompanied this code).
24#
25# You should have received a copy of the GNU Lesser General Public License
26# version 3 along with OpenOffice.org.  If not, see
27# <http://www.openoffice.org/license.html>
28# for a copy of the LGPLv3 License.
29#
30#*************************************************************************
31
32
33#*********************************************************************
34#
35# main
36#
37
38my ($prefix, $ext, $key);
39$productname = "OpenOffice.org";
40$workdir = ".";
41
42while ($_ = $ARGV[0], /^-/) {
43    shift;
44    last if /^--$/;
45    if (/^-p/) {
46        $productname = $ARGV[0];
47        shift;
48    }
49    if (/^-d/) {
50        $workdir = $ARGV[0];
51        shift;
52    }
53    if (/^--key/) {
54        $key = $ARGV[0];
55        shift;
56    }
57    if (/^--prefix/) {
58        $prefix = $ARGV[0];
59        shift;
60    }
61    if (/^--ext/) {
62        $ext = $ARGV[0];
63        shift;
64    }
65}
66
67# open input file
68unless (open(SOURCE, $ARGV[0])) {
69    print STDERR "Can't open $ARGV[0] file: $!\n";
70    return;
71}
72
73
74# For every section in the specified ulf file there should exist
75# a template file in $workdir ..
76while (<SOURCE>) {
77    $line = $_;
78
79    if ( "[" eq substr($line, 0, 1) ) {
80        # Pass the tail of the template to the output file
81        while (<TEMPLATE>) {
82            print OUTFILE;
83        }
84
85        close(TEMPLATE);
86
87        if (close(OUTFILE)) {
88            system "mv -f $outfile.tmp $outfile\n";
89        }
90
91        $_ = substr($line, 1, index($line,"]")-1);
92        $outfile = "$workdir/$prefix$_.$ext";
93
94        # open the template file - ignore sections for which no
95        # templates exist
96        unless(open(TEMPLATE, $outfile)) {
97            print STDERR "Warning: No template found for item $_: $outfile: $!\n";
98            next;
99        }
100
101    	# open output file
102        unless (open(OUTFILE, "> $outfile.tmp")) {
103            print STDERR "Can't create output file $outfile.tmp: $!\n";
104    	    exit -1;
105        }
106
107        # Pass the head of the template to the output file
108KEY:    while (<TEMPLATE>) {
109            print OUTFILE;
110            last KEY if (/$key/);
111        }
112
113    } else {
114        # split locale = "value" into 2 strings
115        ($locale, $value) = split(' = ', $line);
116
117        if ( $locale ne $line ) {
118            # replace en-US with en
119            $locale=~s/en-US/en/;
120
121            # use just anything inside the ""
122            $value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
123
124            # replace resource placeholder
125            $value=~s/%PRODUCTNAME/$productname/g;
126
127            $locale=~s/-/_/;
128            if ($ext eq "desktop") {
129                print OUTFILE "$key\[$locale\]=$value\n";
130            } else {
131                print OUTFILE  "\t\[$locale\]$key=$value\n";
132            }
133        }
134    }
135}
136
137while (<TEMPLATE>) {
138    print OUTFILE;
139}
140
141if (close(OUTFILE)) {
142    system "mv -f $outfile.tmp $outfile\n";
143}
144
145close(TEMPLATE);
146