From 5bb6d117c54034d86c5006e54b5125b0e6fb086e Mon Sep 17 00:00:00 2001 From: Joshua Ferraro Date: Sun, 3 Feb 2008 23:18:48 -0500 Subject: [PATCH] handling multiple languages gracefully in sysprefs, allow the user to enable specific languages (and language groups) Signed-off-by: Joshua Ferraro --- C4/Languages.pm | 40 +++++++++++----- admin/systempreferences.pl | 48 ++++++++++++------- .../prog/en/includes/intranet-bottom.inc | 9 ++-- .../en/modules/admin/systempreferences.tmpl | 34 +++++++++++++ .../prog/en/includes/opac-bottom.inc | 16 ++++--- 5 files changed, 108 insertions(+), 39 deletions(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index 8eb6693825..bc578f0f14 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -104,39 +104,43 @@ Returns a reference to an array of hashes: =cut sub getTranslatedLanguages { - my ($interface, $theme, $current_language) = @_; + my ($interface, $theme, $current_language, $which) = @_; my $htdocs; my $all_languages = getAllLanguages(); my @languages; my $lang; - + my @enabled_languages; + if ($interface && $interface eq 'opac' ) { + @enabled_languages = split ",", C4::Context->preference('opaclanguages'); $htdocs = C4::Context->config('opachtdocs'); if ( $theme and -d "$htdocs/$theme" ) { (@languages) = _get_language_dirs($htdocs,$theme); - return _build_languages_arrayref($all_languages,\@languages,$current_language); + return _build_languages_arrayref($all_languages,\@languages,$current_language,\@enabled_languages); } else { for my $theme ( _get_themes('opac') ) { push @languages, _get_language_dirs($htdocs,$theme); } - return _build_languages_arrayref($all_languages,\@languages,$current_language); + return _build_languages_arrayref($all_languages,\@languages,$current_language,\@enabled_languages); } } elsif ($interface && $interface eq 'intranet' ) { + @enabled_languages = split ",", C4::Context->preference('language'); $htdocs = C4::Context->config('intrahtdocs'); if ( $theme and -d "$htdocs/$theme" ) { @languages = _get_language_dirs($htdocs,$theme); - return _build_languages_arrayref($all_languages,\@languages,$current_language); + return _build_languages_arrayref($all_languages,\@languages,$current_language,\@enabled_languages); } else { foreach my $theme ( _get_themes('intranet') ) { push @languages, _get_language_dirs($htdocs,$theme); } - return _build_languages_arrayref($all_languages,\@languages,$current_language); + return _build_languages_arrayref($all_languages,\@languages,$current_language,\@enabled_languages); } } else { + @enabled_languages = split ",", C4::Context->preference('opaclanguages'); my $htdocs = C4::Context->config('intrahtdocs'); foreach my $theme ( _get_themes('intranet') ) { push @languages, _get_language_dirs($htdocs,$theme); @@ -145,7 +149,7 @@ sub getTranslatedLanguages { foreach my $theme ( _get_themes('opac') ) { push @languages, _get_language_dirs($htdocs,$theme); } - return _build_languages_arrayref($all_languages,\@languages,$current_language); + return _build_languages_arrayref($all_languages,\@languages,$current_language,\@enabled_languages); } } @@ -177,8 +181,8 @@ sub getAllLanguages { # add the correct description info while (my $language_descriptions = $sth2->fetchrow_hashref) { - # fill in the ISO6329 code - $language_subtag_registry->{iso639_2_code} = $language_descriptions->{iso639_2_code}; + # fill in the ISO6329 code + $language_subtag_registry->{iso639_2_code} = $language_descriptions->{iso639_2_code}; $language_subtag_registry->{language_description} = $language_descriptions->{description}; } push @languages_loop, $language_subtag_registry; @@ -246,9 +250,10 @@ FIXME: this could be rewritten and simplified using map =cut sub _build_languages_arrayref { - my ($all_languages,$translated_languages,$current_language) = @_; + my ($all_languages,$translated_languages,$current_language,$enabled_languages) = @_; my @translated_languages = @$translated_languages; my @languages_loop; # the final reference to an array of hashrefs + my @enabled_languages = @$enabled_languages; my %seen_languages; # the language tags we've seen my %found_languages; my $language_groups; @@ -256,9 +261,14 @@ sub _build_languages_arrayref { my $current_language_regex = regex_lang_subtags($current_language); # Loop through the translated languages for my $translated_language (@translated_languages) { - # separate the language string into its subtag types my $language_subtags_hashref = regex_lang_subtags($translated_language); + + # is this language string 'enabled'? + for my $enabled_language (@enabled_languages) { + #warn "Checking out if $translated_language eq $enabled_language"; + $language_subtags_hashref->{'enabled'} = 1 if $translated_language eq $enabled_language; + } # group this language, key by langtag $language_subtags_hashref->{'sublanguage_current'} = 1 if $translated_language eq $current_language; @@ -272,6 +282,13 @@ sub _build_languages_arrayref { } # $key is a language subtag like 'en' while( my ($key, $value) = each %$language_groups) { + + # is this language group enabled? are any of the languages within it enabled? + my $enabled; + for my $enabled_language (@enabled_languages) { + my $regex_enabled_language = regex_lang_subtags($enabled_language); + $enabled = 1 if $key eq $regex_enabled_language->{language}; + } push @languages_loop, { # this is only use if there is one rfc4646_subtag => @$value[0]->{rfc4646_subtag}, @@ -280,6 +297,7 @@ sub _build_languages_arrayref { sublanguages_loop => $value, plural => $track_language_groups->{$key} >1 ? 1 : 0, current => $current_language_regex->{language} eq $key ? 1 : 0, + group_enabled => $enabled, }; } return \@languages_loop; diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl index 0f1cc69f05..1804a535a8 100755 --- a/admin/systempreferences.pl +++ b/admin/systempreferences.pl @@ -473,25 +473,28 @@ if ($op eq 'add_form') { $counter++; } } elsif ($data->{'type'} eq 'Languages') { - $template->param('type-choice' => 1); - my $type=''; - @options=(); - my $currently_selected_languages; - my $counter=0; + my $currently_selected_languages; foreach my $language (split /\s+/, $data->{'value'}) { - next if $language eq 'images'; - push @options, { option => $language, counter => $counter }; $currently_selected_languages->{$language}=1; - $counter++; - } - my $langavail = getTranslatedLanguages(); - foreach my $language (@$langavail) { - my $selected='0'; - next if $currently_selected_languages->{$language->{'language_code'}}; - #FIXME: could add language_name and language_locale_name for better display - push @options, { option => $language->{'language_code'}, counter => $counter }; - $counter++; } + # current language + my $lang = $template->param('lang'); + my $theme; + my $interface; + if ($data->{'variable'} =~ /opac/) { + # this is the OPAC + $interface = 'opac'; + $theme = C4::Context->preference('opacthemes'); + } + else { + # this is the staff client + $interface = 'intranet'; + $theme = C4::Context->preference('template'); + } + my $languages_loop = getTranslatedLanguages($interface,$theme,$lang,$currently_selected_languages); + + $template->param('languages_loop' => $languages_loop); + $template->param('type-langselector' => 1); } else { $template->param('type-free' => 1); $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60); @@ -510,16 +513,25 @@ if ($op eq 'add_form') { my $dbh = C4::Context->dbh; my $sth=$dbh->prepare("select * from systempreferences where variable=?"); $sth->execute($input->param('variable')); + # to handle multiple values + my $value; + # handle multiple value strings (separated by ',') + my $params = $input->Vars; + my @values = split("\0",$params->{'value'}) if $params->{'value'}; + for my $vl (@values) { + $value .= "$vl,"; + } + $value =~ s/,$//; if ($sth->rows) { unless (C4::Context->config('demo') eq 1) { my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?"); - $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable')); + $sth->execute($value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable')); $sth->finish; } } else { unless (C4::Context->config('demo') eq 1) { my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)"); - $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions')); + $sth->execute($input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions')); $sth->finish; } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc index f7402fb32f..8f48a71f53 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc @@ -4,29 +4,32 @@
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl index 6b0921350b..df3d72e49b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/systempreferences.tmpl @@ -109,6 +109,40 @@ + + + + + + +
+ + +
+ + + + + +
+ + + + + + + + + +
+ + + + diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/prog/en/includes/opac-bottom.inc index 87166d87e7..74ca6fcf8d 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/opac-bottom.inc @@ -8,29 +8,31 @@
-- 2.39.5