Bug 8954: Make languages list in advanced search translatable (revision 1)

In opac-search.pl and search.pl, this patch moves the $lang variable from the end to the begining of the script, and use it as a parameter for getAllLanguages.
In Languages.pm, getAllLanguages function is modified :
- if no parameter is passed to the function, it returns english languages names
- if a $lang parameter conforming to RFC4646 syntax is passed :
-- the function returns languages names translated in $lang if possible
-- if a language name is not translated in $lang in database, the function returns english language name
To test, set your opac and staff interface in english and in other languages and check search.pl and opac-search.pl :
- If language names in your languages_description table are translated in the same language you use for your GUI, the language names in dropdown list will be translated in this language (+native name).
- If your GUI is in english, or in a language into whitch languages names are not translated in languages_description, the dropdown list will stay in english (+native name).

Signed-off-by: Marc Veron <veron@veron.ch>

Patch behaves as expected.

With Opac language set to French I got all languages with French language name.
With German (de-DE), I got only a few with German language names (and all other with English ones),
this was due to missing entries for de-DE in table language_descriptions.
This behaviour is consistent with the description above.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>

Tested language list in OPAC and staff advanced search is translated
properly after applying the patch. Checked that language switcher still
works like it should.

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Fixed typo in POD.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
This commit is contained in:
Mathieu Saby 2012-11-09 00:49:49 +01:00 committed by Liz Rea - Catalyst
parent 0915a0cb19
commit 7c428e6ea0
3 changed files with 26 additions and 12 deletions

View File

@ -186,19 +186,35 @@ Returns a reference to an array of hashes:
=cut
sub getAllLanguages {
my $lang = shift;
# if no parameter is passed to the function, it returns english languages names
# if a $lang parameter conforming to RFC4646 syntax is passed, the function returns languages names translated in $lang
# if a language name is not translated in $lang in database, the function returns english language name
my @languages_loop;
my $dbh=C4::Context->dbh;
my $current_language = shift || 'en';
my $default_language = 'en';
my $current_language = $default_language;
if ($lang) {
$current_language = regex_lang_subtags($lang)->{'language'};
}
my $sth = $dbh->prepare('SELECT * FROM language_subtag_registry WHERE type=\'language\'');
$sth->execute();
while (my $language_subtag_registry = $sth->fetchrow_hashref) {
# pull out all the script descriptions for each language
my $desc;
# check if language name is stored in current language
my $sth4= $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag =? AND lang = ?");
$sth4->execute($language_subtag_registry->{subtag},$current_language);
while (my $language_desc = $sth4->fetchrow_hashref) {
$desc=$language_desc->{description};
}
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 = ?");
$sth2->execute($language_subtag_registry->{subtag},$current_language);
if ($desc) {
$sth2->execute($language_subtag_registry->{subtag},$current_language);
}
else {
$sth2->execute($language_subtag_registry->{subtag},$default_language);
}
my $sth3 = $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag=? AND lang=?");
# add the correct description info
while (my $language_descriptions = $sth2->fetchrow_hashref) {
$sth3->execute($language_subtag_registry->{subtag},$language_subtag_registry->{subtag});

View File

@ -158,7 +158,7 @@ use CGI qw('-no_undef_params');
my $cgi = new CGI;
my ($template,$borrowernumber,$cookie);
my $lang = C4::Templates::getlanguage($cgi, 'intranet');
# decide which template to use
my $template_name;
my $template_type;
@ -328,7 +328,7 @@ if ( $template_type eq 'advsearch' ) {
search_boxes_loop => \@search_boxes_array);
# load the language limits (for search)
my $languages_limit_loop = getAllLanguages();
my $languages_limit_loop = getAllLanguages($lang);
$template->param(search_languages_loop => $languages_limit_loop,);
# Expanded search options in advanced search:
@ -471,7 +471,6 @@ my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit
my @results;
## I. BUILD THE QUERY
my $lang = C4::Templates::getlanguage($cgi, 'intranet');
( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by,$scan,$lang);
## parse the query_cgi string and put it into a form suitable for <input>s

View File

@ -55,7 +55,7 @@ BEGIN {
}
my ($template,$borrowernumber,$cookie);
my $lang = C4::Templates::getlanguage($cgi, 'opac');
# decide which template to use
my $template_name;
my $template_type = 'basic';
@ -150,7 +150,7 @@ $template->param(
);
# load the language limits (for search)
my $languages_limit_loop = getAllLanguages();
my $languages_limit_loop = getAllLanguages($lang);
$template->param(search_languages_loop => $languages_limit_loop,);
# load the Type stuff
@ -386,7 +386,6 @@ my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_
my @results;
## I. BUILD THE QUERY
my $lang = C4::Templates::getlanguage($cgi, 'opac');
( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang);
sub _input_cgi_parse {