merged tag ooo/OOO330_m14
[LibreOffice.git] / sysui / desktop / share / translate.pl
blob0c3ee55b10ce6ef8b4884bb4f69924895420892d
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
5 #*************************************************************************
7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 # Copyright 2000, 2010 Oracle and/or its affiliates.
11 # OpenOffice.org - a multi-platform office productivity suite
13 # This file is part of OpenOffice.org.
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.
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).
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.
30 #*************************************************************************
33 #*********************************************************************
35 # main
38 my ($prefix, $ext, $key);
39 $productname = "OpenOffice.org";
40 $workdir = ".";
42 while ($_ = $ARGV[0], /^-/) {
43 shift;
44 last if /^--$/;
45 if (/^-p/) {
46 $productname = $ARGV[0];
47 shift;
49 if (/^-d/) {
50 $workdir = $ARGV[0];
51 shift;
53 if (/^--key/) {
54 $key = $ARGV[0];
55 shift;
57 if (/^--prefix/) {
58 $prefix = $ARGV[0];
59 shift;
61 if (/^--ext/) {
62 $ext = $ARGV[0];
63 shift;
67 # open input file
68 unless (open(SOURCE, $ARGV[0])) {
69 print STDERR "Can't open $ARGV[0] file: $!\n";
70 return;
74 # For every section in the specified ulf file there should exist
75 # a template file in $workdir ..
76 while (<SOURCE>) {
77 $line = $_;
79 if ( "[" eq substr($line, 0, 1) ) {
80 # Pass the tail of the template to the output file
81 while (<TEMPLATE>) {
82 print OUTFILE;
85 close(TEMPLATE);
87 if (close(OUTFILE)) {
88 system "mv -f $outfile.tmp $outfile\n";
91 $_ = substr($line, 1, index($line,"]")-1);
92 $outfile = "$workdir/$prefix$_.$ext";
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;
101 # open output file
102 unless (open(OUTFILE, "> $outfile.tmp")) {
103 print STDERR "Can't create output file $outfile.tmp: $!\n";
104 exit -1;
107 # Pass the head of the template to the output file
108 KEY: while (<TEMPLATE>) {
109 print OUTFILE;
110 last KEY if (/$key/);
113 } else {
114 # split locale = "value" into 2 strings
115 ($locale, $value) = split(' = ', $line);
117 if ( $locale ne $line ) {
118 # replace en-US with en
119 $locale=~s/en-US/en/;
121 # use just anything inside the ""
122 $value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
124 # replace resource placeholder
125 $value=~s/%PRODUCTNAME/$productname/g;
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";
137 while (<TEMPLATE>) {
138 print OUTFILE;
141 if (close(OUTFILE)) {
142 system "mv -f $outfile.tmp $outfile\n";
145 close(TEMPLATE);