Bump version to 21.06.18.1
[LibreOffice.git] / sysui / desktop / macosx / gen_strings.pl
blob9c6ffee7d28b0b4ecc9908588dc2369fb50e7446
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
6 # This file is part of the LibreOffice project.
8 # This Source Code Form is subject to the terms of the Mozilla Public
9 # License, v. 2.0. If a copy of the MPL was not distributed with this
10 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 # This file incorporates work covered by the following license notice:
14 # Licensed to the Apache Software Foundation (ASF) under one or more
15 # contributor license agreements. See the NOTICE file distributed
16 # with this work for additional information regarding copyright
17 # ownership. The ASF licenses this file to you under the Apache
18 # License, Version 2.0 (the "License"); you may not use this file
19 # except in compliance with the License. You may obtain a copy of
20 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 use warnings;
24 use strict 'vars';
26 my $my_lang = 'en-US';
27 my $plist = 'Info.plist';
28 my $lines = 0;
30 while ($_ = $ARGV[0], /^-/) {
31 shift;
32 last if /^--$/;
33 if (/^-l/) {
34 $my_lang = $ARGV[0];
35 shift;
36 } elsif (/^-p/) {
37 $plist = $ARGV[0];
38 shift;
42 # open input file (Info.plist)
43 unless (open(SOURCE, $plist)) {
44 print STDERR "Can't open $plist file: $!\n";
45 return;
48 # XML::Parser not installed by default on MacOS X
49 my (%documents,$key,$icon,$name);
51 $name = "";
53 while (<SOURCE>) {
54 if ( /<\/dict>/ ) {
55 $documents{$icon} = $name if length $name > 0;
56 $key = $icon = $name = "";
57 } elsif ( /<key>(.*)<\/key>/ ) {
58 $key = $1;
59 } elsif ( /<string>(.*)<\/string>/ ) {
60 if ( $key eq 'CFBundleTypeIconFile' ) {
61 $icon = $1;
62 $icon =~ s/\.icns$//;
63 } elsif ( $key eq 'CFBundleTypeName' ) {
64 $name = $1;
69 close (SOURCE);
71 print_lang($my_lang);
72 print_lang('en-US') unless $lines > 0;
74 sub print_lang
76 my ($this_lang) = @_;
78 # open input file (documents.ulf)
79 unless (open(SOURCE, $ARGV[0])) {
80 print STDERR "Can't open $ARGV[0] file: $!\n";
81 return;
84 my $last_section;
86 while (<SOURCE>) {
88 if ( /\[(.*)\]/ ) {
89 $last_section = $1;
90 } else {
91 # split locale = "value" into 2 strings
92 my ($lang, $value) = split ' = ';
94 if ( $lang ne $_ && $lang eq $this_lang && exists $documents{$last_section} ) {
95 # replacing product variable doesn't work inside zip files and also not for UTF-16
96 next if /%PRODUCTNAME/;
97 s/$lang/"$documents{$last_section}"/;
98 s/\n/;\n/;
99 print;
100 $lines += 1;
105 close (SOURCE);