merge the formfield patch from ooo-build
[ooovba.git] / sysui / desktop / macosx / gen_strings.pl
blobed85d3e7468a678ee671a3d4c4a5aa4f40ca6151
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
5 #*************************************************************************
7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 #
9 # Copyright 2008 by Sun Microsystems, Inc.
11 # OpenOffice.org - a multi-platform office productivity suite
13 # $RCSfile: gen_strings.pl,v $
15 # $Revision: 1.4 $
17 # This file is part of OpenOffice.org.
19 # OpenOffice.org is free software: you can redistribute it and/or modify
20 # it under the terms of the GNU Lesser General Public License version 3
21 # only, as published by the Free Software Foundation.
23 # OpenOffice.org is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 # GNU Lesser General Public License version 3 for more details
27 # (a copy is included in the LICENSE file that accompanied this code).
29 # You should have received a copy of the GNU Lesser General Public License
30 # version 3 along with OpenOffice.org. If not, see
31 # <http://www.openoffice.org/license.html>
32 # for a copy of the LGPLv3 License.
34 #*************************************************************************
36 use warnings;
37 use strict 'vars';
39 my $my_lang = 'en-US';
40 my $plist = 'Info.plist';
41 my $lines = 0;
43 while ($_ = $ARGV[0], /^-/) {
44 shift;
45 last if /^--$/;
46 if (/^-l/) {
47 $my_lang = $ARGV[0];
48 shift;
49 } elsif (/^-p/) {
50 $plist = $ARGV[0];
51 shift;
55 # open input file (Info.plist)
56 unless (open(SOURCE, $plist)) {
57 print STDERR "Can't open $plist file: $!\n";
58 return;
61 # XML::Parser not installed by default on MacOS X
62 my (%documents,$key,$icon,$name);
64 $name = "";
66 while (<SOURCE>) {
67 if ( /<\/dict>/ ) {
68 $documents{$icon} = $name if length $name > 0;
69 $key = $icon = $name = "";
70 } elsif ( /<key>(.*)<\/key>/ ) {
71 $key = $1;
72 } elsif ( /<string>(.*)<\/string>/ ) {
73 if ( $key eq 'CFBundleTypeIconFile' ) {
74 $icon = $1;
75 $icon =~ s/\.icns$//;
76 } elsif ( $key eq 'CFBundleTypeName' ) {
77 $name = $1;
82 close (SOURCE);
84 print_lang($my_lang);
85 print_lang('en-US') unless $lines > 0;
87 sub print_lang
89 my ($this_lang) = @_;
91 # open input file (documents.ulf)
92 unless (open(SOURCE, $ARGV[0])) {
93 print STDERR "Can't open $ARGV[0] file: $!\n";
94 return;
97 my $last_section;
99 while (<SOURCE>) {
101 if ( /\[(.*)\]/ ) {
102 $last_section = $1;
103 } else {
104 # split locale = "value" into 2 strings
105 my ($lang, $value) = split ' = ';
107 if ( $lang ne $_ && $lang eq $this_lang && exists $documents{$last_section} ) {
108 # replacing product variable doesn't work inside zip files and also not for UTF-16
109 next if /%PRODUCTNAME/;
110 # s/%PRODUCTNAME/\${FILEFORMATNAME} \${FILEFORMATVERSION}/g;
111 s/$lang/"$documents{$last_section}"/;
112 s/\n/;\n/;
113 print;
114 $lines += 1;
119 close (SOURCE);