tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / solenv / bin / modules / installer / languagepack.pm
blob134e0e6c2b9824d3d5e0f7c02f3fac6cbbc84b3e
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer::languagepack;
21 use strict;
22 use warnings;
24 use installer::converter;
25 use installer::files;
26 use installer::globals;
27 use installer::logger;
28 use installer::pathanalyzer;
29 use installer::scpzipfiles;
30 use installer::scriptitems;
31 use installer::systemactions;
32 use installer::worker;
34 ####################################################
35 # Selecting all files with the correct language
36 ####################################################
38 sub select_language_items
40 my ( $itemsref, $languagesarrayref, $itemname ) = @_;
42 installer::logger::include_header_into_logfile("Selecting languages for language pack. Item: $itemname");
44 my @itemsarray = ();
46 for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
48 my $oneitem = ${$itemsref}[$i];
50 my $ismultilingual = $oneitem->{'ismultilingual'};
52 if (!($ismultilingual))
54 # Files with style "LANGUAGEPACK" and "FORCELANGUAGEPACK" also have to be included into the language pack.
55 # Files with style "LANGUAGEPACK" are only included into language packs.
56 # Files with style "FORCELANGUAGEPACK" are included into language packs and non language packs. They are
57 # forced, because otherwise they may not be included into languagepacks.
59 my $styles = "";
60 if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
62 if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); }
64 next; # single language files are not included into language pack
67 my $specificlanguage = "";
68 if ( $oneitem->{'specificlanguage'} ) { $specificlanguage = $oneitem->{'specificlanguage'}; }
70 for ( my $j = 0; $j <= $#{$languagesarrayref}; $j++ ) # iterating over all languages
72 my $onelanguage = ${$languagesarrayref}[$j];
73 my $locallang = $onelanguage;
74 $locallang =~ s/-/_/;
76 if ( $specificlanguage eq $onelanguage )
78 push(@itemsarray, $oneitem);
83 return \@itemsarray;
86 sub replace_languagestring_variable
88 my ($onepackageref, $languagestringref) = @_;
90 my $key;
92 foreach $key (keys %{$onepackageref})
94 my $value = $onepackageref->{$key};
95 $value =~ s/\%LANGUAGESTRING/$$languagestringref/g;
96 $onepackageref->{$key} = $value;
100 #########################################################
101 # Including the license text into the script template
102 #########################################################
104 sub put_license_file_into_script
106 my ($scriptfile, $licensefile) = @_;
108 my $infoline = "Adding licensefile into language pack script\n";
109 push( @installer::globals::logfileinfo, $infoline);
111 my $includestring = "";
113 for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
115 $includestring = $includestring . ${$licensefile}[$i];
118 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
120 ${$scriptfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/;
124 #########################################################
125 # Creating a tar.gz file from a Solaris package
126 #########################################################
128 sub create_tar_gz_file
130 my ($installdir, $packagename, $packagestring) = @_;
132 $packagename =~ s/\.rpm\s*$//;
133 my $targzname = $packagename . ".tar.gz";
134 my $systemcall = "cd $installdir; tar -cf - $packagestring | $installer::globals::packertool > $targzname";
135 installer::logger::print_message( "... $systemcall ...\n" );
137 my $returnvalue = system($systemcall);
139 my $infoline = "Systemcall: $systemcall\n";
140 push( @installer::globals::logfileinfo, $infoline);
142 if ($returnvalue)
144 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
145 push( @installer::globals::logfileinfo, $infoline);
147 else
149 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
150 push( @installer::globals::logfileinfo, $infoline);
153 return $targzname;
156 #########################################################
157 # Determining the name of the package file
158 #########################################################
160 sub get_packagename_from_packagelist
162 my ( $alldirs, $allvariables, $languagestringref ) = @_;
164 my $localproductname = $allvariables->{'PRODUCTNAME'};
165 $localproductname = lc($localproductname);
166 $localproductname =~ s/ //g;
167 $localproductname =~ s/-/_/g;
169 my $packagename = $localproductname . "_" . $$languagestringref;
171 return $packagename;
174 #########################################################
175 # Determining the name of the package file or the rpm
176 # in the installation directory. For language packs
177 # there is only one file in this directory
178 #########################################################
180 sub determine_packagename
182 my ( $installdir, $allvariables, $languagestringref ) = @_;
184 my $packagename = "";
185 my $allnames = "";
187 if ( $installer::globals::isrpmbuild )
189 # determining the rpm file in directory $installdir
191 my $fileextension = "rpm";
192 my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $installdir);
193 if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
194 my $rpmsav = [@{$rpmfiles}];
195 for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
197 $packagename = get_packagename_from_packagelist($rpmfiles, $allvariables, $languagestringref);
199 my $packagestring = installer::converter::convert_array_to_space_separated_string($rpmfiles);
200 $packagename = create_tar_gz_file($installdir, $packagename, $packagestring); # only one file
201 for ( my $i = 0; $i <= $#{$rpmsav}; $i++ )
203 my $onefile = $installdir . $installer::globals::separator . ${$rpmsav}[$i];
204 unlink($onefile);
207 $allnames = $rpmfiles;
210 if ( $installer::globals::issolarisbuild )
212 # determining the Solaris package file in directory $installdir
213 my $alldirs = installer::systemactions::get_all_directories($installdir);
215 if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
216 my $alldirssav = [@{$alldirs}];
217 for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); }
219 $packagename = get_packagename_from_packagelist($alldirs, $allvariables, $languagestringref);
220 my $packagestring = installer::converter::convert_array_to_space_separated_string($alldirs);
221 $packagename = create_tar_gz_file($installdir, $packagename, $packagestring); # only a file (not a directory) can be included into the shell script
222 for ( my $i = 0; $i <= $#{$alldirssav}; $i++ ) { installer::systemactions::remove_complete_directory(${$alldirssav}[$i], 1); }
223 $allnames = $alldirs;
226 my $infoline = "Found package in installation directory $installdir : $packagename\n";
227 push( @installer::globals::logfileinfo, $infoline);
229 return ( $packagename, $allnames);
232 #########################################################
233 # Including the name of the package file or the rpm
234 # into the script template
235 #########################################################
237 sub put_packagename_into_script
239 my ($scriptfile, $packagename, $allnames) = @_;
241 my $localpackagename = $packagename;
242 $localpackagename =~ s/\.tar\.gz//; # making "OOOopenoffice-it-ea.tar.gz" to "OOOopenoffice-it-ea"
243 my $infoline = "Adding packagename $localpackagename into language pack script\n";
244 push( @installer::globals::logfileinfo, $infoline);
246 my $installline = "";
248 if ( $installer::globals::issolarisbuild ) { $installline = " /usr/sbin/pkgadd -d \$outdir -a \$adminfile"; }
250 if ( $installer::globals::isrpmbuild ) { $installline = " rpm --prefix \$PRODUCTINSTALLLOCATION --replacepkgs -i"; }
252 for ( my $i = 0; $i <= $#{$allnames}; $i++ )
254 if ( $installer::globals::issolarisbuild ) { $installline = $installline . " ${$allnames}[$i]"; }
256 if ( $installer::globals::isrpmbuild ) { $installline = $installline . " \$outdir/${$allnames}[$i]"; }
259 for ( my $j = 0; $j <= $#{$scriptfile}; $j++ )
261 ${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/;
265 ##################################################################
266 # Including the lowercase product name into the script template
267 ##################################################################
269 sub put_productname_into_script
271 my ($scriptfile, $variableshashref) = @_;
273 my $productname = $variableshashref->{'PRODUCTNAME'};
274 $productname = lc($productname);
275 $productname =~ s/\.//g; # openoffice.org -> openofficeorg
277 my $infoline = "Adding productname $productname into language pack script\n";
278 push( @installer::globals::logfileinfo, $infoline);
280 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
282 ${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
286 ##################################################################
287 # Including the full product name into the script template
288 # (name and version)
289 ##################################################################
291 sub put_fullproductname_into_script
293 my ($scriptfile, $variableshashref) = @_;
295 my $productname = $variableshashref->{'PRODUCTNAME'};
296 my $productversion = "";
297 if ( $variableshashref->{'PRODUCTVERSION'} ) { $productversion = $variableshashref->{'PRODUCTVERSION'}; };
298 my $fullproductname = $productname . " " . $productversion;
300 my $infoline = "Adding full productname \"$fullproductname\" into language pack script\n";
301 push( @installer::globals::logfileinfo, $infoline);
303 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
305 ${$scriptfile}[$i] =~ s/FULLPRODUCTNAMELONGPLACEHOLDER/$fullproductname/;
309 ##################################################################
310 # Including the name of the search package (-core01)
311 # into the script template
312 ##################################################################
314 sub put_searchpackage_into_script
316 my ($scriptfile, $variableshashref) = @_;
318 my $basispackageprefix = $variableshashref->{'BASISPACKAGEPREFIX'};
319 my $productversion = $variableshashref->{'PRODUCTVERSION'};
321 if ( $installer::globals::issolarisbuild ) { $productversion =~ s/\.//g; } # "3.0" -> "30"
323 my $infoline = "Adding basis package prefix $basispackageprefix into language pack script\n";
324 push( @installer::globals::logfileinfo, $infoline);
326 $infoline = "Adding basis package version $productversion into language pack script\n";
327 push( @installer::globals::logfileinfo, $infoline);
329 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
331 ${$scriptfile}[$i] =~ s/BASISPACKAGEPREFIXPLACEHOLDER/$basispackageprefix/;
332 ${$scriptfile}[$i] =~ s/PRODUCTVERSIONPLACEHOLDER/$productversion/;
337 #########################################################
338 # Including the linenumber into the script template
339 #########################################################
341 sub put_linenumber_into_script
343 my ( $scriptfile, $licensefile, $allnames ) = @_;
345 my $linenumber = $#{$scriptfile} + $#{$licensefile} + 3; # also adding the content of the license file!
347 my $infoline = "Adding linenumber $linenumber into language pack script\n";
348 push( @installer::globals::logfileinfo, $infoline);
350 for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
352 ${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
356 #########################################################
357 # Determining the name of the new scriptfile
358 #########################################################
360 sub determine_scriptfile_name
362 my ( $packagename ) = @_;
364 my $scriptfilename = $packagename;
366 $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/;
368 my $infoline = "Setting language pack script file name to $scriptfilename\n";
369 push( @installer::globals::logfileinfo, $infoline);
371 return $scriptfilename;
374 #########################################################
375 # Saving the script file in the installation directory
376 #########################################################
378 sub save_script_file
380 my ($installdir, $newscriptfilename, $scriptfile) = @_;
382 $newscriptfilename = $installdir . $installer::globals::separator . $newscriptfilename;
383 installer::files::save_file($newscriptfilename, $scriptfile);
385 my $infoline = "Saving script file $newscriptfilename\n";
386 push( @installer::globals::logfileinfo, $infoline);
388 return $newscriptfilename;
391 #########################################################
392 # Including the binary package into the script
393 #########################################################
395 sub include_package_into_script
397 my ( $scriptfilename, $installdir, $packagename ) = @_;
399 my $longpackagename = $installdir . $installer::globals::separator . $packagename;
400 my $systemcall = "cat $longpackagename >>$scriptfilename";
402 my $returnvalue = system($systemcall);
404 my $infoline = "Systemcall: $systemcall\n";
405 push( @installer::globals::logfileinfo, $infoline);
407 if ($returnvalue)
409 $infoline = "ERROR: Could not execute \"$systemcall\"!\n";
410 push( @installer::globals::logfileinfo, $infoline);
412 else
414 $infoline = "Success: Executed \"$systemcall\" successfully!\n";
415 push( @installer::globals::logfileinfo, $infoline);
418 chmod 0775, $scriptfilename;
422 #########################################################
423 # Removing the binary package
424 #########################################################
426 sub remove_package
428 my ( $installdir, $packagename ) = @_;
430 my $remove_package = 1;
432 if ( $ENV{'DONT_REMOVE_PACKAGE'} ) { $remove_package = 0; }
434 if ( $remove_package )
436 my $longpackagename = $installdir . $installer::globals::separator . $packagename;
437 unlink $longpackagename;
439 my $infoline = "Removing package: $longpackagename \n";
440 push( @installer::globals::logfileinfo, $infoline);
444 ####################################################
445 # Unix language packs, that are not part of
446 # multilingual installation sets, need a
447 # shell script installer
448 ####################################################
450 sub build_installer_for_languagepack
452 my ($installdir, $allvariableshashref, $includepatharrayref, $languagesarrayref, $languagestringref) = @_;
454 installer::logger::print_message( "... creating shell script installer ...\n" );
456 installer::logger::include_header_into_logfile("Creating shell script installer:");
458 # find and read setup script template
460 my $scriptfilename = $ENV{'SRCDIR'} . "/setup_native/scripts/langpackscript.sh";
461 if (! -f $scriptfilename) { installer::exiter::exit_program("ERROR: Could not find script file $scriptfilename!", "build_installer_for_languagepack"); }
462 my $scriptfile = installer::files::read_file($scriptfilename);
464 my $infoline = "Found script file $scriptfilename: $scriptfile \n";
465 push( @installer::globals::logfileinfo, $infoline);
467 # find and read english license file
468 my $licenselanguage = "en-US"; # always english !
469 my $licensefilename = "LICENSE";
470 my $licenseincludepatharrayref = installer::worker::get_language_specific_include_paths($includepatharrayref, $licenselanguage);
472 my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $licenseincludepatharrayref, 0);
473 if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "build_installer_for_languagepack"); }
474 my $licensefile = installer::files::read_file($$licenseref);
476 $infoline = "Found licensefile $licensefilename: $$licenseref \n";
477 push( @installer::globals::logfileinfo, $infoline);
479 # including variables into license file
480 installer::scpzipfiles::replace_all_ziplistvariables_in_file($licensefile, $allvariableshashref);
482 # add license text into script template
483 put_license_file_into_script($scriptfile, $licensefile);
485 # add rpm or package file name into script template
486 my ( $packagename, $allnames) = determine_packagename($installdir, $allvariableshashref, $languagestringref);
487 put_packagename_into_script($scriptfile, $packagename, $allnames);
489 # add product name into script template
490 put_productname_into_script($scriptfile, $allvariableshashref);
492 # add product name into script template
493 put_fullproductname_into_script($scriptfile, $allvariableshashref);
495 # add product name into script template
496 put_searchpackage_into_script($scriptfile, $allvariableshashref);
498 # replace linenumber in script template
499 put_linenumber_into_script($scriptfile, $licensefile, $allnames);
501 # saving the script file
502 my $newscriptfilename = determine_scriptfile_name($packagename);
503 $newscriptfilename = save_script_file($installdir, $newscriptfilename, $scriptfile);
505 # include rpm or package into script
506 include_package_into_script($newscriptfilename, $installdir, $packagename);
508 # remove rpm or package
509 remove_package($installdir, $packagename);