2 eval 'exec perl -wS $0 ${1+"$@"}'
6 # This file is part of the LibreOffice project.
8 # This Source Code Form is subject to the terms of the Mozilla Public
9 # License, v. 2.0. If a copy of the MPL was not distributed with this
10 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 # This file incorporates work covered by the following license notice:
14 # Licensed to the Apache Software Foundation (ASF) under one or more
15 # contributor license agreements. See the NOTICE file distributed
16 # with this work for additional information regarding copyright
17 # ownership. The ASF licenses this file to you under the Apache
18 # License, Version 2.0 (the "License"); you may not use this file
19 # except in compliance with the License. You may obtain a copy of
20 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 my ($prefix, $ext, $key);
24 my $productname = "LibreOffice";
27 while ($_ = $ARGV[0], /^-/) {
31 $productname = $ARGV[0];
52 # hack for unity section
54 if ( $outkey eq "UnityQuicklist" ) {
61 unless (open(SOURCE
, $ARGV[0])) {
62 print STDERR
"Can't open $ARGV[0] file: $!\n";
66 # currently read template
73 if ( "[" eq substr($line, 0, 1) ) {
74 $template = substr($line, 1, index($line,"]")-1);
76 # For every section in the specified ulf file there should exist
77 # a template file in $workdir ..
78 $entry{'outfile'} = "$workdir/$prefix$template.$ext";
80 $entry{'translations'} = \
%translations;
81 $templates{$template} = \
%entry;
83 # split locale = "value" into 2 strings
84 my ($locale, $value) = split(' = ', $line);
86 if ( $locale ne $line ) {
87 # replace en-US with en
90 # use just anything inside the ""
91 $value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
93 # replace resource placeholder
94 $value=~s/%PRODUCTNAME/$productname/g;
98 $templates{$template}->{'translations'}->{$locale} = $value;
106 foreach $template (keys %templates) {
107 my $outfile = $templates{$template}->{'outfile'};
108 print "processing template $template in $outfile\n";
110 # open the template file - ignore sections for which no
112 unless(open(TEMPLATE
, $outfile)) {
113 print STDERR
"Warning: No template found for item $_: $outfile: $!\n";
118 unless (open(OUTFILE
, "> $outfile.tmp")) {
119 print STDERR
"Can't create output file $outfile.tmp: $!\n";
123 # emit the template to the output file
126 $keyline =~ s/^$key/$outkey/;
127 print OUTFILE
$keyline;
129 my $translations = $templates{$template}->{'translations'};
130 foreach my $locale (keys %{$translations}) {
131 my $value = $translations->{$locale};
132 print "locale is $locale\n";
133 print "value is $value\n";
135 if ($ext eq "desktop") {
136 print OUTFILE
"$outkey\[$locale\]=$value\n";
138 print OUTFILE
"\t\[$locale\]$outkey=$value\n";
147 if (close(OUTFILE
)) {
148 system "mv -f $outfile.tmp $outfile\n";