xref: /trunk/main/sysui/desktop/macosx/gen_strings.pl (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir:
2*cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
3*cdf0e10cSrcweir    if 0;
4*cdf0e10cSrcweir
5*cdf0e10cSrcweir#*************************************************************************
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
12*cdf0e10cSrcweir#
13*cdf0e10cSrcweir# This file is part of OpenOffice.org.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
16*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
17*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
18*cdf0e10cSrcweir#
19*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
20*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
21*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
23*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
24*cdf0e10cSrcweir#
25*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
26*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
27*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
28*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
29*cdf0e10cSrcweir#
30*cdf0e10cSrcweir#*************************************************************************
31*cdf0e10cSrcweir
32*cdf0e10cSrcweiruse warnings;
33*cdf0e10cSrcweiruse strict 'vars';
34*cdf0e10cSrcweir
35*cdf0e10cSrcweirmy $my_lang = 'en-US';
36*cdf0e10cSrcweirmy $plist = 'Info.plist';
37*cdf0e10cSrcweirmy $lines = 0;
38*cdf0e10cSrcweir
39*cdf0e10cSrcweirwhile ($_ = $ARGV[0], /^-/) {
40*cdf0e10cSrcweir  shift;
41*cdf0e10cSrcweir  last if /^--$/;
42*cdf0e10cSrcweir  if (/^-l/) {
43*cdf0e10cSrcweir    $my_lang = $ARGV[0];
44*cdf0e10cSrcweir    shift;
45*cdf0e10cSrcweir  } elsif (/^-p/) {
46*cdf0e10cSrcweir    $plist = $ARGV[0];
47*cdf0e10cSrcweir    shift;
48*cdf0e10cSrcweir  }
49*cdf0e10cSrcweir}
50*cdf0e10cSrcweir
51*cdf0e10cSrcweir# open input file (Info.plist)
52*cdf0e10cSrcweirunless (open(SOURCE, $plist)) {
53*cdf0e10cSrcweir  print STDERR "Can't open $plist file: $!\n";
54*cdf0e10cSrcweir  return;
55*cdf0e10cSrcweir}
56*cdf0e10cSrcweir
57*cdf0e10cSrcweir# XML::Parser not installed by default on MacOS X
58*cdf0e10cSrcweirmy (%documents,$key,$icon,$name);
59*cdf0e10cSrcweir
60*cdf0e10cSrcweir$name = "";
61*cdf0e10cSrcweir
62*cdf0e10cSrcweirwhile (<SOURCE>) {
63*cdf0e10cSrcweir  if ( /<\/dict>/ ) {
64*cdf0e10cSrcweir    $documents{$icon} = $name if length $name > 0;
65*cdf0e10cSrcweir    $key = $icon = $name = "";
66*cdf0e10cSrcweir  } elsif ( /<key>(.*)<\/key>/ ) {
67*cdf0e10cSrcweir    $key = $1;
68*cdf0e10cSrcweir  } elsif ( /<string>(.*)<\/string>/ ) {
69*cdf0e10cSrcweir    if ( $key eq 'CFBundleTypeIconFile' ) {
70*cdf0e10cSrcweir      $icon = $1;
71*cdf0e10cSrcweir      $icon =~ s/\.icns$//;
72*cdf0e10cSrcweir    } elsif ( $key eq 'CFBundleTypeName' ) {
73*cdf0e10cSrcweir      $name = $1;
74*cdf0e10cSrcweir    }
75*cdf0e10cSrcweir  }
76*cdf0e10cSrcweir}
77*cdf0e10cSrcweir
78*cdf0e10cSrcweirclose (SOURCE);
79*cdf0e10cSrcweir
80*cdf0e10cSrcweirprint_lang($my_lang);
81*cdf0e10cSrcweirprint_lang('en-US') unless $lines > 0;
82*cdf0e10cSrcweir
83*cdf0e10cSrcweirsub print_lang
84*cdf0e10cSrcweir{
85*cdf0e10cSrcweir  my ($this_lang) = @_;
86*cdf0e10cSrcweir
87*cdf0e10cSrcweir  # open input file (documents.ulf)
88*cdf0e10cSrcweir  unless (open(SOURCE, $ARGV[0])) {
89*cdf0e10cSrcweir    print STDERR "Can't open $ARGV[0] file: $!\n";
90*cdf0e10cSrcweir    return;
91*cdf0e10cSrcweir  }
92*cdf0e10cSrcweir
93*cdf0e10cSrcweir  my $last_section;
94*cdf0e10cSrcweir
95*cdf0e10cSrcweir  while (<SOURCE>) {
96*cdf0e10cSrcweir
97*cdf0e10cSrcweir    if ( /\[(.*)\]/ ) {
98*cdf0e10cSrcweir      $last_section = $1;
99*cdf0e10cSrcweir    } else {
100*cdf0e10cSrcweir      # split locale = "value" into 2 strings
101*cdf0e10cSrcweir      my ($lang, $value) = split ' = ';
102*cdf0e10cSrcweir
103*cdf0e10cSrcweir      if ( $lang ne $_ && $lang eq $this_lang && exists $documents{$last_section} ) {
104*cdf0e10cSrcweir        # replacing product variable doesn't work inside zip files and also not for UTF-16
105*cdf0e10cSrcweir        next if /%PRODUCTNAME/;
106*cdf0e10cSrcweir#        s/%PRODUCTNAME/\${FILEFORMATNAME} \${FILEFORMATVERSION}/g;
107*cdf0e10cSrcweir        s/$lang/"$documents{$last_section}"/;
108*cdf0e10cSrcweir        s/\n/;\n/;
109*cdf0e10cSrcweir        print;
110*cdf0e10cSrcweir        $lines += 1;
111*cdf0e10cSrcweir      }
112*cdf0e10cSrcweir    }
113*cdf0e10cSrcweir  }
114*cdf0e10cSrcweir
115*cdf0e10cSrcweir  close (SOURCE);
116*cdf0e10cSrcweir}
117