1:
2eval 'exec perl -wS $0 ${1+"$@"}'
3    if 0;
4
5#**************************************************************
6#
7#  Licensed to the Apache Software Foundation (ASF) under one
8#  or more contributor license agreements.  See the NOTICE file
9#  distributed with this work for additional information
10#  regarding copyright ownership.  The ASF licenses this file
11#  to you under the Apache License, Version 2.0 (the
12#  "License"); you may not use this file except in compliance
13#  with the License.  You may obtain a copy of the License at
14#
15#    http://www.apache.org/licenses/LICENSE-2.0
16#
17#  Unless required by applicable law or agreed to in writing,
18#  software distributed under the License is distributed on an
19#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20#  KIND, either express or implied.  See the License for the
21#  specific language governing permissions and limitations
22#  under the License.
23#
24#**************************************************************
25
26
27
28use warnings;
29use strict 'vars';
30
31my $my_lang = 'en-US';
32my $plist = 'Info.plist';
33my $lines = 0;
34
35while ($_ = $ARGV[0], /^-/) {
36  shift;
37  last if /^--$/;
38  if (/^-l/) {
39    $my_lang = $ARGV[0];
40    shift;
41  } elsif (/^-p/) {
42    $plist = $ARGV[0];
43    shift;
44  }
45}
46
47# open input file (Info.plist)
48unless (open(SOURCE, $plist)) {
49  print STDERR "Can't open $plist file: $!\n";
50  return;
51}
52
53# XML::Parser not installed by default on MacOS X
54my (%documents,$key,$icon,$name);
55
56$name = "";
57
58while (<SOURCE>) {
59  if ( /<\/dict>/ ) {
60    $documents{$icon} = $name if length $name > 0;
61    $key = $icon = $name = "";
62  } elsif ( /<key>(.*)<\/key>/ ) {
63    $key = $1;
64  } elsif ( /<string>(.*)<\/string>/ ) {
65    if ( $key eq 'CFBundleTypeIconFile' ) {
66      $icon = $1;
67      $icon =~ s/\.icns$//;
68    } elsif ( $key eq 'CFBundleTypeName' ) {
69      $name = $1;
70    }
71  }
72}
73
74close (SOURCE);
75
76print_lang($my_lang);
77print_lang('en-US') unless $lines > 0;
78
79sub print_lang
80{
81  my ($this_lang) = @_;
82
83  # open input file (documents.ulf)
84  unless (open(SOURCE, $ARGV[0])) {
85    print STDERR "Can't open $ARGV[0] file: $!\n";
86    return;
87  }
88
89  my $last_section;
90
91  while (<SOURCE>) {
92
93    if ( /\[(.*)\]/ ) {
94      $last_section = $1;
95    } else {
96      # split locale = "value" into 2 strings
97      my ($lang, $value) = split ' = ';
98
99      if ( $lang ne $_ && $lang eq $this_lang && exists $documents{$last_section} ) {
100        # replacing product variable doesn't work inside zip files and also not for UTF-16
101        next if /%PRODUCTNAME/;
102#        s/%PRODUCTNAME/\${FILEFORMATNAME} \${FILEFORMATVERSION}/g;
103        s/$lang/"$documents{$last_section}"/;
104        s/\n/;\n/;
105        print;
106        $lines += 1;
107      }
108    }
109  }
110
111  close (SOURCE);
112}
113