1*cdf0e10cSrcweir#************************************************************************* 2*cdf0e10cSrcweir# 3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# This file is part of OpenOffice.org. 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir# 15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir# 21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir# 26*cdf0e10cSrcweir#************************************************************************* 27*cdf0e10cSrcweir 28*cdf0e10cSrcweirpackage installer::languages; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweiruse installer::converter; 31*cdf0e10cSrcweiruse installer::existence; 32*cdf0e10cSrcweiruse installer::exiter; 33*cdf0e10cSrcweiruse installer::globals; 34*cdf0e10cSrcweiruse installer::remover; 35*cdf0e10cSrcweiruse installer::ziplist; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir############################################################################# 38*cdf0e10cSrcweir# Analyzing the laguage list parameter and language list from zip list file 39*cdf0e10cSrcweir############################################################################# 40*cdf0e10cSrcweir 41*cdf0e10cSrcweirsub analyze_languagelist 42*cdf0e10cSrcweir{ 43*cdf0e10cSrcweir my $first = $installer::globals::languagelist; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir $first =~ s/\_/\,/g; # substituting "_" by ",", in case of dmake definition 01_49 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir # Products are separated by a "#", if defined in zip-list by a "|". But "get_info_about_languages" 48*cdf0e10cSrcweir # substitutes already "|" to "#". This procedure only knows "#" as product separator. 49*cdf0e10cSrcweir # Different languages for one product are separated by ",". But on the command line the "_" is used. 50*cdf0e10cSrcweir # Therefore "_" is replaced by "," at the beginning of this procedure. 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir while ($first =~ /^(\S+)\#(\S+?)$/) # Minimal matching, to keep the order of languages 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir $first = $1; 55*cdf0e10cSrcweir my $last = $2; 56*cdf0e10cSrcweir unshift(@installer::globals::languageproducts, $last); 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir unshift(@installer::globals::languageproducts, $first); 60*cdf0e10cSrcweir} 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir#################################################### 63*cdf0e10cSrcweir# Reading languages from zip list file 64*cdf0e10cSrcweir#################################################### 65*cdf0e10cSrcweir 66*cdf0e10cSrcweirsub get_info_about_languages 67*cdf0e10cSrcweir{ 68*cdf0e10cSrcweir my ( $allsettingsarrayref ) = @_; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir my $languagelistref; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir $languagelistref = installer::ziplist::getinfofromziplist($allsettingsarrayref, "languages"); 73*cdf0e10cSrcweir $installer::globals::languagelist = $$languagelistref; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir if ( $installer::globals::languagelist eq "" ) # not defined on command line and not in product list 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir installer::exiter::exit_program("ERROR: Languages not defined on command line (-l) and not in product list!", "get_info_about_languages"); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir # Adapting the separator format from zip list. 81*cdf0e10cSrcweir # | means new product, , (comma) means more than one language in one product 82*cdf0e10cSrcweir # On the command line, | is difficult to use. Therefore this script uses hashes 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir $installer::globals::languagelist =~ s/\|/\#/g; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir analyze_languagelist(); 87*cdf0e10cSrcweir} 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir############################################################################# 90*cdf0e10cSrcweir# Checking whether all elements of an array A are also member of array B 91*cdf0e10cSrcweir############################################################################# 92*cdf0e10cSrcweir 93*cdf0e10cSrcweirsub all_elements_of_array1_in_array2 94*cdf0e10cSrcweir{ 95*cdf0e10cSrcweir my ($array1, $array2) = @_; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir my $array2_contains_all_elements_of_array1 = 1; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$array1}; $i++ ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if (! installer::existence::exists_in_array(${$array1}[$i], $array2)) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir $array2_contains_all_elements_of_array1 = 0; 104*cdf0e10cSrcweir last; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir return $array2_contains_all_elements_of_array1; 109*cdf0e10cSrcweir} 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir############################################# 112*cdf0e10cSrcweir# All languages defined for one product 113*cdf0e10cSrcweir############################################# 114*cdf0e10cSrcweir 115*cdf0e10cSrcweirsub get_all_languages_for_one_product 116*cdf0e10cSrcweir{ 117*cdf0e10cSrcweir my ( $languagestring, $allvariables ) = @_; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir my @languagearray = (); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir my $last = $languagestring; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir $installer::globals::ismultilingual = 0; # setting the global variable $ismultilingual ! 124*cdf0e10cSrcweir if ( $languagestring =~ /\,/ ) { $installer::globals::ismultilingual = 1; } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir while ( $last =~ /^\s*(.+?)\,(.+)\s*$/) # "$" for minimal matching, comma separated list 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir my $first = $1; 129*cdf0e10cSrcweir $last = $2; 130*cdf0e10cSrcweir installer::remover::remove_leading_and_ending_whitespaces(\$first); 131*cdf0e10cSrcweir push(@languagearray, "$first"); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir installer::remover::remove_leading_and_ending_whitespaces(\$last); 135*cdf0e10cSrcweir push(@languagearray, "$last"); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir if ( $installer::globals::iswindowsbuild ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir my $furthercheck = 1; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir # For some languages (that are not supported by Windows, english needs to be added to the installation set 142*cdf0e10cSrcweir # Languages saved in "@installer::globals::noMSLocaleLangs" 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir if ( all_elements_of_array1_in_array2(\@languagearray, \@installer::globals::noMSLocaleLangs) ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir my $officestartlanguage = $languagearray[0]; 147*cdf0e10cSrcweir unshift(@languagearray, "en-US"); # am Anfang einf�gen! 148*cdf0e10cSrcweir $installer::globals::ismultilingual = 1; 149*cdf0e10cSrcweir $installer::globals::added_english = 1; 150*cdf0e10cSrcweir $installer::globals::set_office_start_language = 1; 151*cdf0e10cSrcweir # setting the variable PRODUCTLANGUAGE, needed for Linguistic-ForceDefaultLanguage.xcu 152*cdf0e10cSrcweir $allvariables->{'PRODUCTLANGUAGE'} = $officestartlanguage; 153*cdf0e10cSrcweir $furthercheck = 0; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir # In bilingual installation sets, in which english is the first language, 157*cdf0e10cSrcweir # the Office start language shall be the second language. 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir if ( $furthercheck ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir if (( $#languagearray == 1 ) && ( $languagearray[0] eq "en-US" )) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir my $officestartlanguage = $languagearray[1]; 164*cdf0e10cSrcweir $installer::globals::set_office_start_language = 1; 165*cdf0e10cSrcweir # setting the variable PRODUCTLANGUAGE, needed for Linguistic-ForceDefaultLanguage.xcu 166*cdf0e10cSrcweir $allvariables->{'PRODUCTLANGUAGE'} = $officestartlanguage; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir return \@languagearray; 172*cdf0e10cSrcweir} 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir#################################################################################### 175*cdf0e10cSrcweir# FAKE: The languages string may contain only "de", "en-US", instead of "01", ... 176*cdf0e10cSrcweir# But this has to be removed as soon as possible. 177*cdf0e10cSrcweir# In the future the languages are determined with "en-US" instead "01" 178*cdf0e10cSrcweir# already on the command line and in the zip list file. 179*cdf0e10cSrcweir#################################################################################### 180*cdf0e10cSrcweir 181*cdf0e10cSrcweirsub fake_languagesstring 182*cdf0e10cSrcweir{ 183*cdf0e10cSrcweir my ($stringref) = @_; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir # ATTENTION: This function has to be removed as soon as possible! 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir $$stringref =~ s/01/en-US/; 188*cdf0e10cSrcweir $$stringref =~ s/03/pt/; 189*cdf0e10cSrcweir $$stringref =~ s/07/ru/; 190*cdf0e10cSrcweir $$stringref =~ s/30/el/; 191*cdf0e10cSrcweir $$stringref =~ s/31/nl/; 192*cdf0e10cSrcweir $$stringref =~ s/33/fr/; 193*cdf0e10cSrcweir $$stringref =~ s/34/es/; 194*cdf0e10cSrcweir $$stringref =~ s/35/fi/; 195*cdf0e10cSrcweir $$stringref =~ s/36/hu/; 196*cdf0e10cSrcweir $$stringref =~ s/37/ca/; 197*cdf0e10cSrcweir $$stringref =~ s/39/it/; 198*cdf0e10cSrcweir $$stringref =~ s/42/cs/; 199*cdf0e10cSrcweir $$stringref =~ s/43/sk/; 200*cdf0e10cSrcweir $$stringref =~ s/44/en-GB/; 201*cdf0e10cSrcweir $$stringref =~ s/45/da/; 202*cdf0e10cSrcweir $$stringref =~ s/46/sv/; 203*cdf0e10cSrcweir $$stringref =~ s/47/no/; 204*cdf0e10cSrcweir $$stringref =~ s/48/pl/; 205*cdf0e10cSrcweir $$stringref =~ s/49/de/; 206*cdf0e10cSrcweir $$stringref =~ s/55/pt-BR/; 207*cdf0e10cSrcweir $$stringref =~ s/66/th/; 208*cdf0e10cSrcweir $$stringref =~ s/77/et/; 209*cdf0e10cSrcweir $$stringref =~ s/81/ja/; 210*cdf0e10cSrcweir $$stringref =~ s/82/ko/; 211*cdf0e10cSrcweir $$stringref =~ s/86/zh-CN/; 212*cdf0e10cSrcweir $$stringref =~ s/88/zh-TW/; 213*cdf0e10cSrcweir $$stringref =~ s/90/tr/; 214*cdf0e10cSrcweir $$stringref =~ s/91/hi-IN/; 215*cdf0e10cSrcweir $$stringref =~ s/96/ar/; 216*cdf0e10cSrcweir $$stringref =~ s/97/he/; 217*cdf0e10cSrcweir} 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir########################################################## 220*cdf0e10cSrcweir# Converting the language array into a string for output 221*cdf0e10cSrcweir########################################################## 222*cdf0e10cSrcweir 223*cdf0e10cSrcweirsub get_language_string 224*cdf0e10cSrcweir{ 225*cdf0e10cSrcweir my ($languagesref) = @_; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir my $newstring = ""; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir $newstring = $newstring . ${$languagesref}[$i] . "_"; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir # remove ending underline 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir $newstring =~ s/\_\s*$//; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir return \$newstring; 239*cdf0e10cSrcweir} 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir########################################################## 242*cdf0e10cSrcweir# Analyzing the languages in the languages array and 243*cdf0e10cSrcweir# returning the most important language 244*cdf0e10cSrcweir########################################################## 245*cdf0e10cSrcweir 246*cdf0e10cSrcweirsub get_default_language 247*cdf0e10cSrcweir{ 248*cdf0e10cSrcweir my ($languagesref) = @_; 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir return ${$languagesref}[0]; # ToDo, only returning the first language 251*cdf0e10cSrcweir} 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir############################################################# 254*cdf0e10cSrcweir# Contains the installation set one of the asian languages? 255*cdf0e10cSrcweir############################################################# 256*cdf0e10cSrcweir 257*cdf0e10cSrcweirsub detect_asian_language 258*cdf0e10cSrcweir{ 259*cdf0e10cSrcweir my ($languagesref) = @_; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir my $containsasia = 0; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir my $onelang = ${$languagesref}[$i]; 266*cdf0e10cSrcweir $onelang =~ s/\s*$//; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir for ( my $j = 0; $j <= $#installer::globals::asianlanguages; $j++ ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir my $asialang = $installer::globals::asianlanguages[$j]; 271*cdf0e10cSrcweir $asialang =~ s/\s*$//; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir if ( $onelang eq $asialang ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir $containsasia = 1; 276*cdf0e10cSrcweir last; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir if ( $containsasia ) { last; } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir return $containsasia; 284*cdf0e10cSrcweir} 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir############################################################# 287*cdf0e10cSrcweir# Contains the installation set only asian languages? 288*cdf0e10cSrcweir############################################################# 289*cdf0e10cSrcweir 290*cdf0e10cSrcweirsub contains_only_asian_languages 291*cdf0e10cSrcweir{ 292*cdf0e10cSrcweir my ($languagesref) = @_; 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir my $onlyasian = 1; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir my $onelang = ${$languagesref}[$i]; 299*cdf0e10cSrcweir $onelang =~ s/\s*$//; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir if (! installer::existence::exists_in_array($onelang, \@installer::globals::asianlanguages)) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir $onlyasian = 0; 304*cdf0e10cSrcweir last; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir return $onlyasian; 309*cdf0e10cSrcweir} 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir################################################################ 312*cdf0e10cSrcweir# Contains the installation set one of the western languages 313*cdf0e10cSrcweir################################################################ 314*cdf0e10cSrcweir 315*cdf0e10cSrcweirsub detect_western_language 316*cdf0e10cSrcweir{ 317*cdf0e10cSrcweir my ($languagesref) = @_; 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir my $containswestern = 1; 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir if ( contains_only_asian_languages($languagesref) ) { $containswestern = 0; } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir return $containswestern; 324*cdf0e10cSrcweir} 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir################################################################ 327*cdf0e10cSrcweir# Determining the language used by the Java installer 328*cdf0e10cSrcweir################################################################ 329*cdf0e10cSrcweir 330*cdf0e10cSrcweirsub get_java_language 331*cdf0e10cSrcweir{ 332*cdf0e10cSrcweir my ( $language ) = @_; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir # my $javalanguage = ""; 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir # if ( $language eq "en-US" ) { $javalanguage = "en_US"; } 337*cdf0e10cSrcweir # elsif ( $language eq "ar" ) { $javalanguage = "ar_AR"; } 338*cdf0e10cSrcweir # elsif ( $language eq "bg" ) { $javalanguage = "bg_BG"; } 339*cdf0e10cSrcweir # elsif ( $language eq "ca" ) { $javalanguage = "ca_CA"; } 340*cdf0e10cSrcweir # elsif ( $language eq "cs" ) { $javalanguage = "cs_CS"; } 341*cdf0e10cSrcweir # elsif ( $language eq "da" ) { $javalanguage = "da_DA"; } 342*cdf0e10cSrcweir # elsif ( $language eq "de" ) { $javalanguage = "de"; } 343*cdf0e10cSrcweir # elsif ( $language eq "de" ) { $javalanguage = "de_DE"; } 344*cdf0e10cSrcweir # elsif ( $language eq "et" ) { $javalanguage = "et_ET"; } 345*cdf0e10cSrcweir # elsif ( $language eq "el" ) { $javalanguage = "el_EL"; } 346*cdf0e10cSrcweir # elsif ( $language eq "fi" ) { $javalanguage = "fi_FI"; } 347*cdf0e10cSrcweir # elsif ( $language eq "fr" ) { $javalanguage = "fr_FR"; } 348*cdf0e10cSrcweir # elsif ( $language eq "hu" ) { $javalanguage = "hu_HU"; } 349*cdf0e10cSrcweir # elsif ( $language eq "he" ) { $javalanguage = "he_HE"; } 350*cdf0e10cSrcweir # elsif ( $language eq "it" ) { $javalanguage = "it_IT"; } 351*cdf0e10cSrcweir # elsif ( $language eq "nl" ) { $javalanguage = "nl_NL"; } 352*cdf0e10cSrcweir # elsif ( $language eq "es" ) { $javalanguage = "es_ES"; } 353*cdf0e10cSrcweir # elsif ( $language eq "sv" ) { $javalanguage = "sv_SV"; } 354*cdf0e10cSrcweir # elsif ( $language eq "sk" ) { $javalanguage = "sk_SK"; } 355*cdf0e10cSrcweir # elsif ( $language eq "pl" ) { $javalanguage = "pl_PL"; } 356*cdf0e10cSrcweir # elsif ( $language eq "pt-BR" ) { $javalanguage = "pt_BR"; } 357*cdf0e10cSrcweir # elsif ( $language eq "ru" ) { $javalanguage = "ru_RU"; } 358*cdf0e10cSrcweir # elsif ( $language eq "tr" ) { $javalanguage = "tr_TR"; } 359*cdf0e10cSrcweir # elsif ( $language eq "ja" ) { $javalanguage = "ja"; } 360*cdf0e10cSrcweir # elsif ( $language eq "ja" ) { $javalanguage = "ja_JP"; } 361*cdf0e10cSrcweir # elsif ( $language eq "ko" ) { $javalanguage = "ko_KR"; } 362*cdf0e10cSrcweir # elsif ( $language eq "th" ) { $javalanguage = "th_TH"; } 363*cdf0e10cSrcweir # elsif ( $language eq "zh-CN" ) { $javalanguage = "zh_CN"; } 364*cdf0e10cSrcweir # elsif ( $language eq "zh-TW" ) { $javalanguage = "zh_TW"; } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir # languages not defined yet 367*cdf0e10cSrcweir # if ( $javalanguage eq "" ) 368*cdf0e10cSrcweir # { 369*cdf0e10cSrcweir # $javalanguage = $language; 370*cdf0e10cSrcweir # $javalanguage =~ s/\-/\_/; 371*cdf0e10cSrcweir # } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir $javalanguage = $language; 374*cdf0e10cSrcweir $javalanguage =~ s/\-/\_/; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir return $javalanguage; 377*cdf0e10cSrcweir} 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir1; 380