Debian Codegraph @

solenv/bin/modules/installer/languages.pm

raw
1 #
2 # This file is part of the LibreOffice project.
3 #
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 #
8 # This file incorporates work covered by the following license notice:
9 #
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 #
18
19 package installer::languages;
20
21 use strict;
22 use warnings;
23
24 use installer::converter;
25 use installer::exiter;
26 use installer::globals;
27 use installer::remover;
28 use installer::ziplist;
29
30 #############################################################################
31 # Analyzing the language list parameter and language list from zip list file
32 #############################################################################
33
34 sub analyze_languagelist
35 {
36 my $first = $installer::globals::languagelist;
37
38 $first =~ s/\_/\,/g; # substituting "_" by ",", in case of dmake definition 01_49
39
40 # Products are separated by a "#", if defined in zip-list by a "|". But "get_info_about_languages"
41 # substitutes already "|" to "#". This procedure only knows "#" as product separator.
42 # Different languages for one product are separated by ",". But on the command line the "_" is used.
43 # Therefore "_" is replaced by "," at the beginning of this procedure.
44
45 while ($first =~ /^(\S+)\#(\S+?)$/) # Minimal matching, to keep the order of languages
46 {
47 $first = $1;
48 my $last = $2;
49 unshift(@installer::globals::languageproducts, $last);
50 }
51
52 unshift(@installer::globals::languageproducts, $first);
53 }
54
55 ####################################################
56 # Reading languages from zip list file
57 ####################################################
58
59 sub get_info_about_languages
60 {
61 my ( $allsettingsarrayref ) = @_;
62
63 my $languagelistref;
64
65 $languagelistref = installer::ziplist::getinfofromziplist($allsettingsarrayref, "languages");
66 $installer::globals::languagelist = $$languagelistref;
67
68 if ( $installer::globals::languagelist eq "" ) # not defined on command line and not in product list
69 {
70 installer::exiter::exit_program("ERROR: Languages not defined on command line (-l) and not in product list!", "get_info_about_languages");
71 }
72
73 # Adapting the separator format from zip list.
74 # | means new product, , (comma) means more than one language in one product
75 # On the command line, | is difficult to use. Therefore this script uses hashes
76
77 $installer::globals::languagelist =~ s/\|/\#/g;
78
79 analyze_languagelist();
80 }
81
82 #############################################
83 # All languages defined for one product
84 #############################################
85
86 sub get_all_languages_for_one_product
87 {
88 my ( $languagestring, $allvariables ) = @_;
89
90 my @languagearray = ();
91
92 my $last = $languagestring;
93
94 $installer::globals::ismultilingual = 0; # setting the global variable $ismultilingual !
95 if ( $languagestring =~ /\,/ ) { $installer::globals::ismultilingual = 1; }
96
97 while ( $last =~ /^\s*(.+?)\,(.+)\s*$/) # "$" for minimal matching, comma separated list
98 {
99 my $first = $1;
100 $last = $2;
101 installer::remover::remove_leading_and_ending_whitespaces(\$first);
102 push(@languagearray, "$first");
103 }
104
105 installer::remover::remove_leading_and_ending_whitespaces(\$last);
106 push(@languagearray, "$last");
107
108 return \@languagearray;
109 }
110
111 ##########################################################
112 # Converting the language array into a string for output
113 ##########################################################
114
115 sub get_language_string
116 {
117 my ($languagesref) = @_;
118
119 my $newstring = "";
120
121 for ( my $i = 0; $i <= $#{$languagesref}; $i++ )
122 {
123 $newstring = $newstring . ${$languagesref}[$i] . "_";
124 }
125
126 # remove ending underline
127
128 $newstring =~ s/\_\s*$//;
129
130 return \$newstring;
131 }
132
133 ##########################################################
134 # Analyzing the languages in the languages array and
135 # returning the most important language
136 ##########################################################
137
138 sub get_default_language
139 {
140 my ($languagesref) = @_;
141
142 return ${$languagesref}[0]; # ToDo, only returning the first language
143 }
144
145 1;