Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sysui / desktop / share / translate.pl
blob200f6a8bbe8e311e8a2436bc9b7f528a880e5717
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
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";
25 my $workdir = ".";
27 while ($_ = $ARGV[0], /^-/) {
28 shift;
29 last if /^--$/;
30 if (/^-p/) {
31 $productname = $ARGV[0];
32 shift;
34 if (/^-d/) {
35 $workdir = $ARGV[0];
36 shift;
38 if (/^--key/) {
39 $key = $ARGV[0];
40 shift;
42 if (/^--prefix/) {
43 $prefix = $ARGV[0];
44 shift;
46 if (/^--ext/) {
47 $ext = $ARGV[0];
48 shift;
52 # hack for unity section
53 my $outkey = $key;
54 if ( $outkey eq "UnityQuicklist" ) {
55 $outkey = "Name";
58 my %templates;
60 # open input file
61 unless (open(SOURCE, $ARGV[0])) {
62 print STDERR "Can't open $ARGV[0] file: $!\n";
63 return;
66 # currently read template
67 my $template;
69 # read ulf file
70 while (<SOURCE>) {
71 my $line = $_;
73 if ( "[" eq substr($line, 0, 1) ) {
74 $template = substr($line, 1, index($line,"]")-1);
75 my %entry;
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";
79 my %translations;
80 $entry{'translations'} = \%translations;
81 $templates{$template} = \%entry;
82 } else {
83 # split locale = "value" into 2 strings
84 my ($locale, $value) = split(' = ', $line);
86 if ( $locale ne $line ) {
87 # replace en-US with en
88 $locale=~s/en-US/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;
96 $locale=~s/-/_/;
98 $templates{$template}->{'translations'}->{$locale} = $value;
103 close(SOURCE);
105 # process templates
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
111 # templates exist
112 unless(open(TEMPLATE, $outfile)) {
113 print STDERR "Warning: No template found for item $_: $outfile: $!\n";
114 exit -1;
117 # open output file
118 unless (open(OUTFILE, "> $outfile.tmp")) {
119 print STDERR "Can't create output file $outfile.tmp: $!\n";
120 exit -1;
123 # emit the template to the output file
124 while (<TEMPLATE>) {
125 my $keyline = $_;
126 $keyline =~ s/^$key/$outkey/;
127 print OUTFILE $keyline;
128 if (/$key/) {
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";
134 if ($value) {
135 if ($ext eq "desktop") {
136 print OUTFILE "$outkey\[$locale\]=$value\n";
137 } else {
138 print OUTFILE "\t\[$locale\]$outkey=$value\n";
145 close(TEMPLATE);
147 if (close(OUTFILE)) {
148 system "mv -f $outfile.tmp $outfile\n";