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