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 .
24 # Translates multiple .desktop files at once with strings from .ulf
25 # files; if you add new translateable .ulf files please add them to
26 # l10ntools/source/localize.cxx
29 my ($prefix, $ext, $key);
30 my $productname = "LibreOffice";
34 while ($_ = $ARGV[0], /^-/) {
38 $productname = $ARGV[0];
57 if (/^--template-dir/) {
58 $template_dir = $ARGV[0];
63 if (!defined $template_dir) {
64 $template_dir = "$workdir/$prefix";
67 # hack for unity section
69 if ( $outkey eq "UnityQuicklist" ) {
76 unless (open(SOURCE
, $ARGV[0])) {
77 die "Can't open $ARGV[0] file: $!\n";
80 # currently read template
87 if ( "[" eq substr($line, 0, 1) ) {
88 $template = substr($line, 1, index($line,"]")-1);
90 # For every section in the specified ulf file there should exist
91 # a template file in $workdir ..
92 $entry{'outfile'} = "$template_dir$template.$ext";
94 $entry{'translations'} = \
%translations;
95 $templates{$template} = \
%entry;
97 # split locale = "value" into 2 strings
98 my ($locale, $value) = split(' = ', $line);
100 if ( $locale ne $line ) {
101 # replace en-US with en
102 $locale=~s/en-US/en/;
104 # use just anything inside the ""
105 $value = substr($value, index($value, "\"") + 1, rindex($value, "\"") - 1);
107 # replace resource placeholder
108 $value=~s/%PRODUCTNAME/$productname/g;
112 $templates{$template}->{'translations'}->{$locale} = $value;
121 foreach $template (keys %templates) {
122 my $outfile = $templates{$template}->{'outfile'};
124 # open the template file - ignore sections for which no
126 if (open(TEMPLATE
, $outfile)) {
128 } elsif ($ext eq 'str') { # string files processed one by one
131 die "Warning: No template found for item '$template' : '$outfile' : '$_': $!\n";
135 unless (open(OUTFILE
, "> $outfile.tmp")) {
136 print STDERR
"Can't create output file $outfile.tmp: $!\n";
140 # emit the template to the output file
143 $keyline =~ s/^$key/$outkey/;
144 print OUTFILE
$keyline;
146 my $translations = $templates{$template}->{'translations'};
147 foreach my $locale (keys %{$translations}) {
148 my $value = $translations->{$locale};
149 # print "locale is $locale\n";
150 # print "value is $value\n";
152 if ($ext eq "desktop" || $ext eq "str") {
153 print OUTFILE
"$outkey\[$locale\]=$value\n";
155 print OUTFILE
"\t\[$locale\]$outkey=$value\n";
164 if (close(OUTFILE
)) {
165 system "mv -f $outfile.tmp $outfile\n";
169 if ($ext eq 'str' && $processed == 0) {
170 die "Warning: No matching templates processed";