Lines 168-174
sub getTranslatedLanguages {
Link Here
|
168 |
|
168 |
|
169 |
Returns a reference to an array of hashes: |
169 |
Returns a reference to an array of hashes: |
170 |
|
170 |
|
171 |
my $alllanguages = getAllLanguages(); |
171 |
my $alllanguages = getAllLanguages() |
172 |
print "Available translated languages:\n"; |
172 |
print "Available translated languages:\n"; |
173 |
for my $language(@$alllanguages) { |
173 |
for my $language(@$alllanguages) { |
174 |
print "$language->{language_code}\n"; |
174 |
print "$language->{language_code}\n"; |
Lines 179-197
Returns a reference to an array of hashes:
Link Here
|
179 |
=cut |
179 |
=cut |
180 |
|
180 |
|
181 |
sub getAllLanguages { |
181 |
sub getAllLanguages { |
|
|
182 |
my $lang = shift; |
183 |
# if no parameter is passed to the function, it returns english languages names |
184 |
# if a $lang parameter conforming to RFC4646 syntax is passed, the function returns languages names translated in $lang |
185 |
# if a language name is not translated in $lang in database, the function returns english language name |
182 |
my @languages_loop; |
186 |
my @languages_loop; |
183 |
my $dbh=C4::Context->dbh; |
187 |
my $dbh=C4::Context->dbh; |
184 |
my $current_language = shift || 'en'; |
188 |
my $default_language = 'en'; |
|
|
189 |
my $current_language = $default_language; |
190 |
if ($lang) { |
191 |
$current_language = regex_lang_subtags($lang)->{'language'}; |
192 |
} |
185 |
my $sth = $dbh->prepare('SELECT * FROM language_subtag_registry WHERE type=\'language\''); |
193 |
my $sth = $dbh->prepare('SELECT * FROM language_subtag_registry WHERE type=\'language\''); |
186 |
$sth->execute(); |
194 |
$sth->execute(); |
187 |
while (my $language_subtag_registry = $sth->fetchrow_hashref) { |
195 |
while (my $language_subtag_registry = $sth->fetchrow_hashref) { |
188 |
|
196 |
my $desc; |
189 |
# pull out all the script descriptions for each language |
197 |
# check if language name is stored in current language |
|
|
198 |
my $sth4= $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag =? AND lang = ?"); |
199 |
$sth4->execute($language_subtag_registry->{subtag},$current_language); |
200 |
while (my $language_desc = $sth4->fetchrow_hashref) { |
201 |
$desc=$language_desc->{description}; |
202 |
} |
190 |
my $sth2= $dbh->prepare("SELECT * FROM language_descriptions LEFT JOIN language_rfc4646_to_iso639 on language_rfc4646_to_iso639.rfc4646_subtag = language_descriptions.subtag WHERE type='language' AND subtag =? AND language_descriptions.lang = ?"); |
203 |
my $sth2= $dbh->prepare("SELECT * FROM language_descriptions LEFT JOIN language_rfc4646_to_iso639 on language_rfc4646_to_iso639.rfc4646_subtag = language_descriptions.subtag WHERE type='language' AND subtag =? AND language_descriptions.lang = ?"); |
191 |
$sth2->execute($language_subtag_registry->{subtag},$current_language); |
204 |
if ($desc) { |
192 |
|
205 |
$sth2->execute($language_subtag_registry->{subtag},$current_language); |
|
|
206 |
} |
207 |
else { |
208 |
$sth2->execute($language_subtag_registry->{subtag},$default_language); |
209 |
} |
193 |
my $sth3 = $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag=? AND lang=?"); |
210 |
my $sth3 = $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag=? AND lang=?"); |
194 |
|
|
|
195 |
# add the correct description info |
211 |
# add the correct description info |
196 |
while (my $language_descriptions = $sth2->fetchrow_hashref) { |
212 |
while (my $language_descriptions = $sth2->fetchrow_hashref) { |
197 |
$sth3->execute($language_subtag_registry->{subtag},$language_subtag_registry->{subtag}); |
213 |
$sth3->execute($language_subtag_registry->{subtag},$language_subtag_registry->{subtag}); |