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