1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22 23 24package installer::languages; 25 26use installer::converter; 27use installer::existence; 28use installer::exiter; 29use installer::globals; 30use installer::remover; 31use installer::ziplist; 32use Digest::MD5; 33 34use strict; 35 36 37=head2 analyze_languagelist() 38 39 Convert $installer::globals::languagelist into $installer::globals::languageproduct. 40 41 That is now just a replacement of '_' with ','. 42 43 $installer::globals::languageproduct (specified by the -l option 44 on the command line) can contain multiple languages separated by 45 '_' to specify multilingual builds. 46 47 Separation by '#' to build multiple languages (single or 48 multilingual) in one make_installer.pl run is not supported 49 anymore. Call make_installer.pl with all languages separately instead: 50 make_installer.pl -l L1#L2 51 -> 52 make_installer.pl -l L1 53 make_installer.pl -l L2 54 55=cut 56sub analyze_languagelist() 57{ 58 my $languageproduct = $installer::globals::languagelist; 59 60 $languageproduct =~ s/\_/\,/g; # substituting "_" by ",", in case of dmake definition 01_49 61 62 if ($languageproduct =~ /\#/) 63 { 64 installer::exiter::exit_program( 65 "building more than one language (or language set) is not supported anymore\n" 66 ."please replace one call of 'make_installer.pl -l language1#language2'\n" 67 ."with two calls 'make_installer.pl -l language1' and 'make_installer.pl -l language2'", 68 "installer::language::analyze_languagelist"); 69 } 70 71 $installer::globals::languageproduct = $languageproduct; 72} 73 74 75 76 77=head2 get_language_directory_name ($language_string) 78 79 Create a directory name that contains the given set of languages. 80 When $language_string exceeds a certain length then it is shortened. 81 82=cut 83sub get_language_directory_name ($) 84{ 85 my ($language_string) = @_; 86 87 if (length($language_string) > $installer::globals::max_lang_length) 88 { 89 my $number_of_languages = ($language_string =~ tr/_//); 90 my $digest = new Digest::MD5(); 91 $digest->add($language_string); 92 my $short_digest = substr($digest->hexdigest(), 0, 8); 93 return "lang_" . $number_of_languages . "_id_" . $short_digest; 94 } 95 else 96 { 97 return $language_string; 98 } 99} 100 101 102 103 104#################################################### 105# Reading languages from zip list file 106#################################################### 107 108sub get_info_about_languages 109{ 110 my ( $allsettingsarrayref ) = @_; 111 112 my $languagelistref; 113 114 $languagelistref = installer::ziplist::getinfofromziplist($allsettingsarrayref, "languages"); 115 $installer::globals::languagelist = $$languagelistref; 116 117 if ( $installer::globals::languagelist eq "" ) # not defined on command line and not in product list 118 { 119 installer::exiter::exit_program("ERROR: Languages not defined on command line (-l) and not in product list!", "get_info_about_languages"); 120 } 121 122 # Adapting the separator format from zip list. 123 # | means new product, , (comma) means more than one language in one product 124 # On the command line, | is difficult to use. Therefore this script uses hashes 125 126 $installer::globals::languagelist =~ s/\|/\#/g; 127 128 analyze_languagelist(); 129} 130 131############################################################################# 132# Checking whether all elements of an array A are also member of array B 133############################################################################# 134 135sub all_elements_of_array1_in_array2 136{ 137 my ($array1, $array2) = @_; 138 139 my $array2_contains_all_elements_of_array1 = 1; 140 141 for ( my $i = 0; $i <= $#{$array1}; $i++ ) 142 { 143 if (! installer::existence::exists_in_array(${$array1}[$i], $array2)) 144 { 145 $array2_contains_all_elements_of_array1 = 0; 146 last; 147 } 148 } 149 150 return $array2_contains_all_elements_of_array1; 151} 152 153############################################# 154# All languages defined for one product 155############################################# 156 157=head2 get_all_languages_for_one_product($languagestring, $allvariables) 158 159 $languagestring can be one or more language names, separated by ','. 160 161 $installer::globals::ismultilingual is set to 1 when $languagestring contains more than one languages. 162 163=cut 164sub get_all_languages_for_one_product ($$) 165{ 166 my ( $languagestring, $allvariables ) = @_; 167 168 169 $installer::globals::ismultilingual = ($languagestring =~ /\,/ ) ? 1 : 0; 170 171 my $languages = $languagestring; 172 $languages =~ s/\s+//g; 173 my @languagearray = split(/,/, $languages); 174 175 if ( $installer::globals::iswindowsbuild ) 176 { 177 my $furthercheck = 1; 178 179 # For some languages (that are not supported by Windows, english needs to be added to the installation set 180 # Languages saved in "@installer::globals::noMSLocaleLangs" 181 182 if ( all_elements_of_array1_in_array2(\@languagearray, \@installer::globals::noMSLocaleLangs) ) 183 { 184 my $officestartlanguage = $languagearray[0]; 185 unshift(@languagearray, "en-US"); # am Anfang einf�gen! 186 $installer::globals::ismultilingual = 1; 187 $installer::globals::added_english = 1; 188 $installer::globals::set_office_start_language = 1; 189 # setting the variable PRODUCTLANGUAGE, needed for Linguistic-ForceDefaultLanguage.xcu 190 $allvariables->{'PRODUCTLANGUAGE'} = $officestartlanguage; 191 $furthercheck = 0; 192 } 193 194 # In bilingual installation sets, in which english is the first language, 195 # the Office start language shall be the second language. 196 197 if ( $furthercheck ) 198 { 199 if (( $#languagearray == 1 ) && ( $languagearray[0] eq "en-US" )) 200 { 201 my $officestartlanguage = $languagearray[1]; 202 $installer::globals::set_office_start_language = 1; 203 # setting the variable PRODUCTLANGUAGE, needed for Linguistic-ForceDefaultLanguage.xcu 204 $allvariables->{'PRODUCTLANGUAGE'} = $officestartlanguage; 205 } 206 } 207 } 208 209 return \@languagearray; 210} 211 212#################################################################################### 213# FAKE: The languages string may contain only "de", "en-US", instead of "01", ... 214# But this has to be removed as soon as possible. 215# In the future the languages are determined with "en-US" instead "01" 216# already on the command line and in the zip list file. 217#################################################################################### 218 219sub fake_languagesstring 220{ 221 my ($stringref) = @_; 222 223 # ATTENTION: This function has to be removed as soon as possible! 224 225 $$stringref =~ s/01/en-US/; 226 $$stringref =~ s/03/pt/; 227 $$stringref =~ s/07/ru/; 228 $$stringref =~ s/30/el/; 229 $$stringref =~ s/31/nl/; 230 $$stringref =~ s/33/fr/; 231 $$stringref =~ s/34/es/; 232 $$stringref =~ s/35/fi/; 233 $$stringref =~ s/36/hu/; 234 $$stringref =~ s/37/ca/; 235 $$stringref =~ s/39/it/; 236 $$stringref =~ s/42/cs/; 237 $$stringref =~ s/43/sk/; 238 $$stringref =~ s/44/en-GB/; 239 $$stringref =~ s/45/da/; 240 $$stringref =~ s/46/sv/; 241 $$stringref =~ s/47/no/; 242 $$stringref =~ s/48/pl/; 243 $$stringref =~ s/49/de/; 244 $$stringref =~ s/55/pt-BR/; 245 $$stringref =~ s/66/th/; 246 $$stringref =~ s/77/et/; 247 $$stringref =~ s/81/ja/; 248 $$stringref =~ s/82/ko/; 249 $$stringref =~ s/86/zh-CN/; 250 $$stringref =~ s/88/zh-TW/; 251 $$stringref =~ s/90/tr/; 252 $$stringref =~ s/91/hi-IN/; 253 $$stringref =~ s/96/ar/; 254 $$stringref =~ s/97/he/; 255} 256 257########################################################## 258# Converting the language array into a string for output 259########################################################## 260 261sub get_language_string 262{ 263 my ($languagesref) = @_; 264 265 my $newstring = ""; 266 267 for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) 268 { 269 $newstring = $newstring . ${$languagesref}[$i] . "_"; 270 } 271 272 # remove ending underline 273 274 $newstring =~ s/\_\s*$//; 275 276 return \$newstring; 277} 278 279########################################################## 280# Analyzing the languages in the languages array and 281# returning the most important language 282########################################################## 283 284sub get_default_language 285{ 286 my ($languagesref) = @_; 287 288 return ${$languagesref}[0]; # ToDo, only returning the first language 289} 290 291############################################################# 292# Contains the installation set one of the asian languages? 293############################################################# 294 295sub detect_asian_language 296{ 297 my ($languagesref) = @_; 298 299 my $containsasia = 0; 300 301 for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) 302 { 303 my $onelang = ${$languagesref}[$i]; 304 $onelang =~ s/\s*$//; 305 306 for ( my $j = 0; $j <= $#installer::globals::asianlanguages; $j++ ) 307 { 308 my $asialang = $installer::globals::asianlanguages[$j]; 309 $asialang =~ s/\s*$//; 310 311 if ( $onelang eq $asialang ) 312 { 313 $containsasia = 1; 314 last; 315 } 316 } 317 318 if ( $containsasia ) { last; } 319 } 320 321 return $containsasia; 322} 323 324############################################################# 325# Contains the installation set only asian languages? 326############################################################# 327 328sub contains_only_asian_languages 329{ 330 my ($languagesref) = @_; 331 332 my $onlyasian = 1; 333 334 for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) 335 { 336 my $onelang = ${$languagesref}[$i]; 337 $onelang =~ s/\s*$//; 338 339 if (! installer::existence::exists_in_array($onelang, \@installer::globals::asianlanguages)) 340 { 341 $onlyasian = 0; 342 last; 343 } 344 } 345 346 return $onlyasian; 347} 348 349################################################################ 350# Contains the installation set one of the western languages 351################################################################ 352 353sub detect_western_language 354{ 355 my ($languagesref) = @_; 356 357 my $containswestern = 1; 358 359 if ( contains_only_asian_languages($languagesref) ) { $containswestern = 0; } 360 361 return $containswestern; 362} 363 364################################################################ 365# Determining the language used by the Java installer 366################################################################ 367 368sub get_java_language 369{ 370 my ( $language ) = @_; 371 372 # my $javalanguage = ""; 373 374 # if ( $language eq "en-US" ) { $javalanguage = "en_US"; } 375 # elsif ( $language eq "ar" ) { $javalanguage = "ar_AR"; } 376 # elsif ( $language eq "bg" ) { $javalanguage = "bg_BG"; } 377 # elsif ( $language eq "ca" ) { $javalanguage = "ca_CA"; } 378 # elsif ( $language eq "cs" ) { $javalanguage = "cs_CS"; } 379 # elsif ( $language eq "da" ) { $javalanguage = "da_DA"; } 380 # elsif ( $language eq "de" ) { $javalanguage = "de"; } 381 # elsif ( $language eq "de" ) { $javalanguage = "de_DE"; } 382 # elsif ( $language eq "et" ) { $javalanguage = "et_ET"; } 383 # elsif ( $language eq "el" ) { $javalanguage = "el_EL"; } 384 # elsif ( $language eq "fi" ) { $javalanguage = "fi_FI"; } 385 # elsif ( $language eq "fr" ) { $javalanguage = "fr_FR"; } 386 # elsif ( $language eq "hu" ) { $javalanguage = "hu_HU"; } 387 # elsif ( $language eq "he" ) { $javalanguage = "he_HE"; } 388 # elsif ( $language eq "it" ) { $javalanguage = "it_IT"; } 389 # elsif ( $language eq "nl" ) { $javalanguage = "nl_NL"; } 390 # elsif ( $language eq "es" ) { $javalanguage = "es_ES"; } 391 # elsif ( $language eq "sv" ) { $javalanguage = "sv_SV"; } 392 # elsif ( $language eq "sk" ) { $javalanguage = "sk_SK"; } 393 # elsif ( $language eq "pl" ) { $javalanguage = "pl_PL"; } 394 # elsif ( $language eq "pt-BR" ) { $javalanguage = "pt_BR"; } 395 # elsif ( $language eq "ru" ) { $javalanguage = "ru_RU"; } 396 # elsif ( $language eq "tr" ) { $javalanguage = "tr_TR"; } 397 # elsif ( $language eq "ja" ) { $javalanguage = "ja"; } 398 # elsif ( $language eq "ja" ) { $javalanguage = "ja_JP"; } 399 # elsif ( $language eq "ko" ) { $javalanguage = "ko_KR"; } 400 # elsif ( $language eq "th" ) { $javalanguage = "th_TH"; } 401 # elsif ( $language eq "zh-CN" ) { $javalanguage = "zh_CN"; } 402 # elsif ( $language eq "zh-TW" ) { $javalanguage = "zh_TW"; } 403 404 # languages not defined yet 405 # if ( $javalanguage eq "" ) 406 # { 407 # $javalanguage = $language; 408 # $javalanguage =~ s/\-/\_/; 409 # } 410 411 my $javalanguage = $language; 412 $javalanguage =~ s/\-/\_/; 413 414 return $javalanguage; 415} 416 417 418 419=head2 get_key_language ($languages) 420 421 Determine the key language from the array of @$languages. 422 423 If there is only one language then that is the key language. 424 425 If there are two languages and one is en-US and was automatically 426 added, then the other language is the key language. 427 428 When there is more than one language and the case above does not 429 apply then return either 'multiasia' or 'multiwestern' as key 430 language, depending on whether one of the asian language parts 431 'jp', 'ko', 'zh' appear. 432 433=cut 434sub get_key_language ($) 435{ 436 my ($languages) = @_; 437 438 my $language_count = scalar @$languages; 439 440 if ($language_count == 1) 441 { 442 return $languages->[0]; 443 } 444 else 445 { 446 if ($installer::globals::added_english && $language_count==1) 447 { 448 # Only multilingual because of added English. 449 return $languages->[1]; 450 } 451 else 452 { 453 if ($languages->[1] =~ /(jp|ko|zh)/) 454 { 455 return "multiasia"; 456 } 457 else 458 { 459 return "multiwestern"; 460 } 461 } 462 } 463} 464 465 466 467 468=head2 get_normalized_language ($language) 469 470 Transform "..._<language>" into "<language>". 471 The ... part, if it exists, is typically en-US. 472 473 If $language does not contain a '_' then $language is returned unmodified. 474 475=cut 476sub get_normalized_language ($) 477{ 478 my ($language) = @_; 479 480 if (ref($language) eq "ARRAY") 481 { 482 if (scalar @$language > 1) 483 { 484 if ($language->[0] eq "en-US") 485 { 486 return $language->[1]; 487 } 488 else 489 { 490 return $language->[0]; 491 } 492 } 493 else 494 { 495 return join("_", @$language); 496 } 497 } 498 elsif ($language =~ /^.*?_(.*)$/) 499 { 500 return $1; 501 } 502 else 503 { 504 return $language; 505 } 506} 507 5081; 509