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