1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: languages.pm,v $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer
::languages
;
34 use installer
::converter
;
35 use installer
::existence
;
36 use installer
::exiter
;
37 use installer
::globals
;
38 use installer
::remover
;
39 use installer
::ziplist
;
41 #############################################################################
42 # Analyzing the laguage list parameter and language list from zip list file
43 #############################################################################
45 sub analyze_languagelist
47 my $first = $installer::globals
::languagelist
;
49 $first =~ s/\_/\,/g; # substituting "_" by ",", in case of dmake definition 01_49
51 # Products are separated by a "#", if defined in zip-list by a "|". But "get_info_about_languages"
52 # substitutes already "|" to "#". This procedure only knows "#" as product separator.
53 # Different languages for one product are separated by ",". But on the command line the "_" is used.
54 # Therefore "_" is replaced by "," at the beginning of this procedure.
56 while ($first =~ /^(\S+)\#(\S+?)$/) # Minimal matching, to keep the order of languages
60 unshift(@installer::globals
::languageproducts
, $last);
63 unshift(@installer::globals
::languageproducts
, $first);
66 ####################################################
67 # Reading languages from zip list file
68 ####################################################
70 sub get_info_about_languages
72 my ( $allsettingsarrayref ) = @_;
76 $languagelistref = installer
::ziplist
::getinfofromziplist
($allsettingsarrayref, "languages");
77 $installer::globals
::languagelist
= $$languagelistref;
79 if ( $installer::globals
::languagelist
eq "" ) # not defined on command line and not in product list
81 installer
::exiter
::exit_program
("ERROR: Languages not defined on command line (-l) and not in product list!", "get_info_about_languages");
84 # Adapting the separator format from zip list.
85 # | means new product, , (comma) means more than one language in one product
86 # On the command line, | is difficult to use. Therefore this script uses hashes
88 $installer::globals
::languagelist
=~ s/\|/\#/g;
90 analyze_languagelist
();
93 #############################################################################
94 # Checking whether all elements of an array A are also member of array B
95 #############################################################################
97 sub all_elements_of_array1_in_array2
99 my ($array1, $array2) = @_;
101 my $array2_contains_all_elements_of_array1 = 1;
103 for ( my $i = 0; $i <= $#{$array1}; $i++ )
105 if (! installer
::existence
::exists_in_array
(${$array1}[$i], $array2))
107 $array2_contains_all_elements_of_array1 = 0;
112 return $array2_contains_all_elements_of_array1;
115 #############################################
116 # All languages defined for one product
117 #############################################
119 sub get_all_languages_for_one_product
121 my ( $languagestring, $allvariables ) = @_;
123 my @languagearray = ();
125 my $last = $languagestring;
127 $installer::globals
::ismultilingual
= 0; # setting the global variable $ismultilingual !
128 if ( $languagestring =~ /\,/ ) { $installer::globals
::ismultilingual
= 1; }
130 while ( $last =~ /^\s*(.+?)\,(.+)\s*$/) # "$" for minimal matching, comma separated list
134 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$first);
135 push(@languagearray, "$first");
138 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$last);
139 push(@languagearray, "$last");
141 if ( $installer::globals
::iswindowsbuild
)
143 my $furthercheck = 1;
145 # For some languages (that are not supported by Windows, english needs to be added to the installation set
146 # Languages saved in "@installer::globals::noMSLocaleLangs"
148 if ( all_elements_of_array1_in_array2
(\
@languagearray, \
@installer::globals
::noMSLocaleLangs
) )
150 my $officestartlanguage = $languagearray[0];
151 unshift(@languagearray, "en-US"); # am Anfang einfügen!
152 $installer::globals
::ismultilingual
= 1;
153 $installer::globals
::added_english
= 1;
154 $installer::globals
::set_office_start_language
= 1;
155 # setting the variable PRODUCTLANGUAGE, needed for Linguistic-ForceDefaultLanguage.xcu
156 $allvariables->{'PRODUCTLANGUAGE'} = $officestartlanguage;
160 # In bilingual installation sets, in which english is the first language,
161 # the Office start language shall be the second language.
165 if (( $#languagearray == 1 ) && ( $languagearray[0] eq "en-US" ))
167 my $officestartlanguage = $languagearray[1];
168 $installer::globals
::set_office_start_language
= 1;
169 # setting the variable PRODUCTLANGUAGE, needed for Linguistic-ForceDefaultLanguage.xcu
170 $allvariables->{'PRODUCTLANGUAGE'} = $officestartlanguage;
175 return \
@languagearray;
178 ####################################################################################
179 # FAKE: The languages string may contain only "de", "en-US", instead of "01", ...
180 # But this has to be removed as soon as possible.
181 # In the future the languages are determined with "en-US" instead "01"
182 # already on the command line and in the zip list file.
183 ####################################################################################
185 sub fake_languagesstring
187 my ($stringref) = @_;
189 # ATTENTION: This function has to be removed as soon as possible!
191 $$stringref =~ s/01/en-US/;
192 $$stringref =~ s/03/pt/;
193 $$stringref =~ s/07/ru/;
194 $$stringref =~ s/30/el/;
195 $$stringref =~ s/31/nl/;
196 $$stringref =~ s/33/fr/;
197 $$stringref =~ s/34/es/;
198 $$stringref =~ s/35/fi/;
199 $$stringref =~ s/36/hu/;
200 $$stringref =~ s/37/ca/;
201 $$stringref =~ s/39/it/;
202 $$stringref =~ s/42/cs/;
203 $$stringref =~ s/43/sk/;
204 $$stringref =~ s/44/en-GB/;
205 $$stringref =~ s/45/da/;
206 $$stringref =~ s/46/sv/;
207 $$stringref =~ s/47/no/;
208 $$stringref =~ s/48/pl/;
209 $$stringref =~ s/49/de/;
210 $$stringref =~ s/55/pt-BR/;
211 $$stringref =~ s/66/th/;
212 $$stringref =~ s/77/et/;
213 $$stringref =~ s/81/ja/;
214 $$stringref =~ s/82/ko/;
215 $$stringref =~ s/86/zh-CN/;
216 $$stringref =~ s/88/zh-TW/;
217 $$stringref =~ s/90/tr/;
218 $$stringref =~ s/91/hi-IN/;
219 $$stringref =~ s/96/ar/;
220 $$stringref =~ s/97/he/;
223 ##########################################################
224 # Converting the language array into a string for output
225 ##########################################################
227 sub get_language_string
229 my ($languagesref) = @_;
233 for ( my $i = 0; $i <= $#{$languagesref}; $i++ )
235 $newstring = $newstring . ${$languagesref}[$i] . "_";
238 # remove ending underline
240 $newstring =~ s/\_\s*$//;
245 ##########################################################
246 # Analyzing the languages in the languages array and
247 # returning the most important language
248 ##########################################################
250 sub get_default_language
252 my ($languagesref) = @_;
254 return ${$languagesref}[0]; # ToDo, only returning the first language
257 #############################################################
258 # Contains the installation set one of the asian languages?
259 #############################################################
261 sub detect_asian_language
263 my ($languagesref) = @_;
265 my $containsasia = 0;
267 for ( my $i = 0; $i <= $#{$languagesref}; $i++ )
269 my $onelang = ${$languagesref}[$i];
270 $onelang =~ s/\s*$//;
272 for ( my $j = 0; $j <= $#installer::globals
::asianlanguages
; $j++ )
274 my $asialang = $installer::globals
::asianlanguages
[$j];
275 $asialang =~ s/\s*$//;
277 if ( $onelang eq $asialang )
284 if ( $containsasia ) { last; }
287 return $containsasia;
290 #############################################################
291 # Contains the installation set only asian languages?
292 #############################################################
294 sub contains_only_asian_languages
296 my ($languagesref) = @_;
300 for ( my $i = 0; $i <= $#{$languagesref}; $i++ )
302 my $onelang = ${$languagesref}[$i];
303 $onelang =~ s/\s*$//;
305 if (! installer
::existence
::exists_in_array
($onelang, \
@installer::globals
::asianlanguages
))
315 ################################################################
316 # Contains the installation set one of the western languages
317 ################################################################
319 sub detect_western_language
321 my ($languagesref) = @_;
323 my $containswestern = 1;
325 if ( contains_only_asian_languages
($languagesref) ) { $containswestern = 0; }
327 return $containswestern;
330 ################################################################
331 # Determining the language used by the Java installer
332 ################################################################
334 sub get_java_language
336 my ( $language ) = @_;
338 # my $javalanguage = "";
340 # if ( $language eq "en-US" ) { $javalanguage = "en_US"; }
341 # elsif ( $language eq "ar" ) { $javalanguage = "ar_AR"; }
342 # elsif ( $language eq "bg" ) { $javalanguage = "bg_BG"; }
343 # elsif ( $language eq "ca" ) { $javalanguage = "ca_CA"; }
344 # elsif ( $language eq "cs" ) { $javalanguage = "cs_CS"; }
345 # elsif ( $language eq "da" ) { $javalanguage = "da_DA"; }
346 # elsif ( $language eq "de" ) { $javalanguage = "de"; }
347 # elsif ( $language eq "de" ) { $javalanguage = "de_DE"; }
348 # elsif ( $language eq "et" ) { $javalanguage = "et_ET"; }
349 # elsif ( $language eq "el" ) { $javalanguage = "el_EL"; }
350 # elsif ( $language eq "fi" ) { $javalanguage = "fi_FI"; }
351 # elsif ( $language eq "fr" ) { $javalanguage = "fr_FR"; }
352 # elsif ( $language eq "hu" ) { $javalanguage = "hu_HU"; }
353 # elsif ( $language eq "he" ) { $javalanguage = "he_HE"; }
354 # elsif ( $language eq "it" ) { $javalanguage = "it_IT"; }
355 # elsif ( $language eq "nl" ) { $javalanguage = "nl_NL"; }
356 # elsif ( $language eq "es" ) { $javalanguage = "es_ES"; }
357 # elsif ( $language eq "sv" ) { $javalanguage = "sv_SV"; }
358 # elsif ( $language eq "sk" ) { $javalanguage = "sk_SK"; }
359 # elsif ( $language eq "pl" ) { $javalanguage = "pl_PL"; }
360 # elsif ( $language eq "pt-BR" ) { $javalanguage = "pt_BR"; }
361 # elsif ( $language eq "ru" ) { $javalanguage = "ru_RU"; }
362 # elsif ( $language eq "tr" ) { $javalanguage = "tr_TR"; }
363 # elsif ( $language eq "ja" ) { $javalanguage = "ja"; }
364 # elsif ( $language eq "ja" ) { $javalanguage = "ja_JP"; }
365 # elsif ( $language eq "ko" ) { $javalanguage = "ko_KR"; }
366 # elsif ( $language eq "th" ) { $javalanguage = "th_TH"; }
367 # elsif ( $language eq "zh-CN" ) { $javalanguage = "zh_CN"; }
368 # elsif ( $language eq "zh-TW" ) { $javalanguage = "zh_TW"; }
370 # languages not defined yet
371 # if ( $javalanguage eq "" )
373 # $javalanguage = $language;
374 # $javalanguage =~ s/\-/\_/;
377 $javalanguage = $language;
378 $javalanguage =~ s/\-/\_/;
380 return $javalanguage;