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