From 802b13e5f5e79a689c64b6826d229958b2bb14f0 Mon Sep 17 00:00:00 2001 From: Joshua Ferraro Date: Wed, 9 Jan 2008 15:02:40 -0600 Subject: [PATCH] fix for 1754; fixing I18N BiDi, improvements to handling of language TODO: clean up the OPAC similarly Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Languages.pm | 359 +++++++++--------- C4/Output.pm | 117 +++--- .../mysql/en/mandatory/subtag_registry.sql | 4 +- installer/install.pl | 15 +- .../prog/en/includes/intranet-bottom.inc | 40 +- .../intranet-tmpl/prog/en/js/staff-global.js | 1 + .../prog/en/modules/catalogue/advsearch.tmpl | 4 +- .../prog/en/modules/installer/step1.tmpl | 17 +- .../prog/en/includes/opac-bottom.inc | 30 ++ 9 files changed, 309 insertions(+), 278 deletions(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index 6667b7a808..8eb6693825 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -20,22 +20,22 @@ package C4::Languages; use strict; -use warnings; #FIXME: turn off warnings before release +use warnings; #FIXME: turn off warnings before release use Carp; use C4::Context; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); BEGIN { - $VERSION = 3.00; - require Exporter; - @ISA = qw(Exporter); - @EXPORT = qw( - &getFrameworkLanguages - &getTranslatedLanguages - &getAllLanguages - ); - @EXPORT_OK = qw(getFrameworkLanguages getTranslatedLanguages getAllLanguages get_bidi regex_lang_subtags language_get_description accept_language); - $DEBUG = 0; + $VERSION = 3.00; + require Exporter; + @ISA = qw(Exporter); + @EXPORT = qw( + &getFrameworkLanguages + &getTranslatedLanguages + &getAllLanguages + ); + @EXPORT_OK = qw(getFrameworkLanguages getTranslatedLanguages getAllLanguages get_bidi regex_lang_subtags language_get_description accept_language); + $DEBUG = 0; } =head1 NAME @@ -80,9 +80,9 @@ sub getFrameworkLanguages { if ($dirname eq $language_set->{language_code}) { push @languages, { - 'language_code'=>$dirname, - 'language_description'=>$language_set->{language_description}, - 'native_descrition'=>$language_set->{language_native_description} } + 'language_code'=>$dirname, + 'language_description'=>$language_set->{language_description}, + 'native_descrition'=>$language_set->{language_native_description} } } } } @@ -104,7 +104,7 @@ Returns a reference to an array of hashes: =cut sub getTranslatedLanguages { - my ($interface, $theme) = @_; + my ($interface, $theme, $current_language) = @_; my $htdocs; my $all_languages = getAllLanguages(); my @languages; @@ -114,26 +114,26 @@ sub getTranslatedLanguages { $htdocs = C4::Context->config('opachtdocs'); if ( $theme and -d "$htdocs/$theme" ) { (@languages) = _get_language_dirs($htdocs,$theme); - return _build_languages_arrayref($all_languages,@languages); + return _build_languages_arrayref($all_languages,\@languages,$current_language); } else { for my $theme ( _get_themes('opac') ) { push @languages, _get_language_dirs($htdocs,$theme); } - return _build_languages_arrayref($all_languages,@languages); + return _build_languages_arrayref($all_languages,\@languages,$current_language); } } elsif ($interface && $interface eq 'intranet' ) { $htdocs = C4::Context->config('intrahtdocs'); if ( $theme and -d "$htdocs/$theme" ) { @languages = _get_language_dirs($htdocs,$theme); - return _build_languages_arrayref($all_languages,@languages); + return _build_languages_arrayref($all_languages,\@languages,$current_language); } else { - foreach my $theme ( _get_themes('opac') ) { + foreach my $theme ( _get_themes('intranet') ) { push @languages, _get_language_dirs($htdocs,$theme); } - return _build_languages_arrayref($all_languages,@languages); + return _build_languages_arrayref($all_languages,\@languages,$current_language); } } else { @@ -145,7 +145,7 @@ sub getTranslatedLanguages { foreach my $theme ( _get_themes('opac') ) { push @languages, _get_language_dirs($htdocs,$theme); } - return _build_languages_arrayref($all_languages,@languages); + return _build_languages_arrayref($all_languages,\@languages,$current_language); } } @@ -164,35 +164,25 @@ Returns a reference to an array of hashes: =cut sub getAllLanguages { - my @languages_loop; - my $dbh=C4::Context->dbh; - my $current_language = 'en'; - 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 $sth2= $dbh->prepare('SELECT * FROM language_descriptions WHERE type=\'language\' AND subtag =?'); - $sth2->execute($language_subtag_registry->{subtag}); - - # add the correct description info - while (my $language_descriptions = $sth2->fetchrow_hashref) { - - # Insert the language description using the current language script - #if ( $language_subtag_registry->{subtag} - if ( $current_language eq $language_descriptions->{lang} ) { - $language_subtag_registry->{language_description} = $language_descriptions->{description}; - #warn "CUR:".$language_subtag_registry->{description}; - } - - # Insert the language name using the script native to the language (FIXME: should really be based on script) - if ($language_subtag_registry->{subtag} eq $language_descriptions->{lang}) { - $language_subtag_registry->{language_native_description} = $language_descriptions->{description}; - #warn "NAT: Desc:$language_descriptions->{description} SubtagDesc: $language_subtag_registry->{language_description}"; - } - } - push @languages_loop, $language_subtag_registry; - } + my @languages_loop; + my $dbh=C4::Context->dbh; + my $current_language = 'en'; + 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 $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 =?"); + $sth2->execute($language_subtag_registry->{subtag}); + + # 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}; + $language_subtag_registry->{language_description} = $language_descriptions->{description}; + } + push @languages_loop, $language_subtag_registry; + } return \@languages_loop; } @@ -232,19 +222,19 @@ Internal function, returns an array of directory names, excluding non-language d sub _get_language_dirs { my ($htdocs,$theme) = @_; - my @languages; + my @lang_strings; opendir D, "$htdocs/$theme"; - for my $language ( readdir D ) { - next if $language =~/^\./; - next if $language eq 'all'; - next if $language =~/png$/; - next if $language =~/css$/; - next if $language =~/CVS$/; - next if $language =~/\.txt$/i; #Don't read the readme.txt ! - next if $language =~/img|images/; - push @languages, $language; + for my $lang_string ( readdir D ) { + next if $lang_string =~/^\./; + next if $lang_string eq 'all'; + next if $lang_string =~/png$/; + next if $lang_string =~/css$/; + next if $lang_string =~/CVS$/; + next if $lang_string =~/\.txt$/i; #Don't read the readme.txt ! + next if $lang_string =~/img|images/; + push @lang_strings, $lang_string; } - return (@languages); + return (@lang_strings); } =head2 _build_languages_arrayref @@ -256,51 +246,63 @@ FIXME: this could be rewritten and simplified using map =cut sub _build_languages_arrayref { - my ($all_languages,@languages) = @_; - my @final_languages; - my %seen_languages; - my %found_languages; - # Loop through the languages, pick the ones that are translated - for my $language (@languages) { - - # separate the language string into its subtag types - my $language_subtags_hashref = regex_lang_subtags($language); - unless ($seen_languages{$language}) { - for my $language_code (@$all_languages) { - if ($language_subtags_hashref->{language} eq $language_code->{'subtag'}) { - $language_code->{'language_lang'} = $language; - $language_code->{'language_code'} = $language_subtags_hashref->{'language'}; - $language_code->{'script_code'} = $language_subtags_hashref->{'script'}; - $language_code->{'region_code'} = $language_subtags_hashref->{'region'}; - $language_code->{'variant_code'} = $language_subtags_hashref->{'variant'}; - push @final_languages, $language_code; - $found_languages{$language}++; - } - } - $seen_languages{$language}++; - - # Handle languages not in our database with their code - unless ($found_languages{$language}) { - my $language_code; - $language_code->{'language_lang'} = $language; - $language_code->{'language_code'} = $language; - push @final_languages, $language_code; - } - } + my ($all_languages,$translated_languages,$current_language) = @_; + my @translated_languages = @$translated_languages; + my @languages_loop; # the final reference to an array of hashrefs + my %seen_languages; # the language tags we've seen + my %found_languages; + my $language_groups; + my $track_language_groups; + 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); + + # group this language, key by langtag + $language_subtags_hashref->{'sublanguage_current'} = 1 if $translated_language eq $current_language; + $language_subtags_hashref->{'rfc4646_subtag'} = $translated_language; + $language_subtags_hashref->{'native_description'} = language_get_description($language_subtags_hashref->{language},$language_subtags_hashref->{language},'language'); + $language_subtags_hashref->{'script_description'} = language_get_description($language_subtags_hashref->{script},$language_subtags_hashref->{'language'},'script'); + $language_subtags_hashref->{'region_description'} = language_get_description($language_subtags_hashref->{region},$language_subtags_hashref->{'language'},'region'); + $language_subtags_hashref->{'variant_description'} = language_get_description($language_subtags_hashref->{variant},$language_subtags_hashref->{'language'},'variant'); + $track_language_groups->{$language_subtags_hashref->{'language'}}++; + push ( @{ $language_groups->{$language_subtags_hashref->{language}} }, $language_subtags_hashref ); } - return \@final_languages; + # $key is a language subtag like 'en' + while( my ($key, $value) = each %$language_groups) { + push @languages_loop, { + # this is only use if there is one + rfc4646_subtag => @$value[0]->{rfc4646_subtag}, + native_description => language_get_description($key,$key,'language'), + language => $key, + sublanguages_loop => $value, + plural => $track_language_groups->{$key} >1 ? 1 : 0, + current => $current_language_regex->{language} eq $key ? 1 : 0, + }; + } + return \@languages_loop; } sub language_get_description { - my ($script,$lang,$type) = @_; - my $dbh = C4::Context->dbh; - my $desc; - my $sth = $dbh->prepare('SELECT description FROM language_descriptions WHERE subtag=? AND lang=? AND type=?'); - $sth->execute($script,$lang,$type); - while (my $descriptions = $sth->fetchrow_hashref) { - $desc = $descriptions->{'description'}; - } - return $desc; + my ($script,$lang,$type) = @_; + my $dbh = C4::Context->dbh; + my $desc; + my $sth = $dbh->prepare("SELECT description FROM language_descriptions WHERE subtag=? AND lang=? AND type=?"); + #warn "QUERY: SELECT description FROM language_descriptions WHERE subtag=$script AND lang=$lang AND type=$type"; + $sth->execute($script,$lang,$type); + while (my $descriptions = $sth->fetchrow_hashref) { + $desc = $descriptions->{'description'}; + } + unless ($desc) { + $sth = $dbh->prepare("SELECT description FROM language_descriptions WHERE subtag=? AND lang=? AND type=?"); + $sth->execute($script,'en',$type); + while (my $descriptions = $sth->fetchrow_hashref) { + $desc = $descriptions->{'description'}; + } + } + return $desc; } =head2 regex_lang_subtags @@ -374,8 +376,9 @@ sub regex_lang_subtags { #my $root = qr{(?: ($language) (?: $s ($script) )? 40% (?: $s ($region) )? 40% (?: $s ($variant) )? 10% (?: $s ($extension) )? 5% (?: $s ($privateuse) )? 5% ) 90% | ($grandfathered) 5% | ($privateuse) 5% }; - $string =~ qr{^ (?:($language)) (?:$s($script))? (?:$s($region))? (?:$s($variant))? (?:$s($extension))? (?:$s($privateuse))? $}xi; # |($grandfathered) | ($privateuse) $}xi; - my %subtag = ( + $string =~ qr{^ (?:($language)) (?:$s($script))? (?:$s($region))? (?:$s($variant))? (?:$s($extension))? (?:$s($privateuse))? $}xi; # |($grandfathered) | ($privateuse) $}xi; + my %subtag = ( + 'rfc4646_subtag' => $string, 'language' => $1, 'script' => $2, 'region' => $3, @@ -389,83 +392,83 @@ sub regex_lang_subtags { # Script Direction Resources: # http://www.w3.org/International/questions/qa-scripts sub get_bidi { - my ($language_script)= @_; - my $dbh = C4::Context->dbh; - my $bidi; - my $sth = $dbh->prepare('SELECT bidi FROM language_script_bidi WHERE rfc4646_subtag=?'); - $sth->execute($language_script); - while (my $result = $sth->fetchrow_hashref) { - $bidi = $result->{'bidi'}; - } - return $bidi; + my ($language_script)= @_; + my $dbh = C4::Context->dbh; + my $bidi; + my $sth = $dbh->prepare('SELECT bidi FROM language_script_bidi WHERE rfc4646_subtag=?'); + $sth->execute($language_script); + while (my $result = $sth->fetchrow_hashref) { + $bidi = $result->{'bidi'}; + } + return $bidi; }; sub accept_language { - # referenced http://search.cpan.org/src/CGILMORE/I18N-AcceptLanguage-1.04/lib/I18N/AcceptLanguage.pm - # FIXME: since this is only used in Output.pm as of Jan 8 2008, maybe it should be IN Output.pm - my ($clientPreferences,$supportedLanguages) = @_; - my @languages = (); - if ($clientPreferences) { - # There should be no whitespace anways, but a cleanliness/sanity check - $clientPreferences =~ s/\s//g; - - # Prepare the list of client-acceptable languages - foreach my $tag (split(/,/, $clientPreferences)) { - my ($language, $quality) = split(/\;/, $tag); - $quality =~ s/^q=//i if $quality; - $quality = 1 unless $quality; - next if $quality <= 0; - # We want to force the wildcard to be last - $quality = 0 if ($language eq '*'); - # Pushing lowercase language here saves processing later - push(@languages, { quality => $quality, - language => $language, - lclanguage => lc($language) }); - } - } else { - carp "accept_language(x,y) called with no clientPreferences (x)."; - } - # Prepare the list of server-supported languages - my %supportedLanguages = (); - my %secondaryLanguages = (); - foreach my $language (@$supportedLanguages) { - # warn "Language supported: " . $language->{language_code}; - $supportedLanguages{lc($language->{language_code})} = $language->{language_code}; - if ($language->{language_code} =~ /^([^-]+)-?/) { - $secondaryLanguages{lc($1)} = $language->{language_code}; - } - } - - # Reverse sort the list, making best quality at the front of the array - @languages = sort { $b->{quality} <=> $a->{quality} } @languages; - my $secondaryMatch = ''; - foreach my $tag (@languages) { - if (exists($supportedLanguages{$tag->{lclanguage}})) { - # Client en-us eq server en-us - return $supportedLanguages{$tag->{language}} if exists($supportedLanguages{$tag->{language}}); - return $supportedLanguages{$tag->{lclanguage}}; - } elsif (exists($secondaryLanguages{$tag->{lclanguage}})) { - # Client en eq server en-us - return $secondaryLanguages{$tag->{language}} if exists($secondaryLanguages{$tag->{language}}); - return $supportedLanguages{$tag->{lclanguage}}; - } elsif ($tag->{lclanguage} =~ /^([^-]+)-/ && exists($secondaryLanguages{$1}) && $secondaryMatch eq '') { - # Client en-gb eq server en-us - $secondaryMatch = $secondaryLanguages{$1}; - } elsif ($tag->{lclanguage} =~ /^([^-]+)-/ && exists($secondaryLanguages{$1}) && $secondaryMatch eq '') { - # FIXME: We just checked the exact same conditional! - # Client en-us eq server en - $secondaryMatch = $supportedLanguages{$1}; - } elsif ($tag->{lclanguage} eq '*') { - # * matches every language not already specified. - # It doesn't care which we pick, so let's pick the default, - # if available, then the first in the array. - #return $acceptor->defaultLanguage() if $acceptor->defaultLanguage(); - return $supportedLanguages->[0]; - } - } - # No primary matches. Secondary? (ie, en-us requested and en supported) - return $secondaryMatch if $secondaryMatch; - return undef; # else, we got nothing. + # referenced http://search.cpan.org/src/CGILMORE/I18N-AcceptLanguage-1.04/lib/I18N/AcceptLanguage.pm + # FIXME: since this is only used in Output.pm as of Jan 8 2008, maybe it should be IN Output.pm + my ($clientPreferences,$supportedLanguages) = @_; + my @languages = (); + if ($clientPreferences) { + # There should be no whitespace anways, but a cleanliness/sanity check + $clientPreferences =~ s/\s//g; + + # Prepare the list of client-acceptable languages + foreach my $tag (split(/,/, $clientPreferences)) { + my ($language, $quality) = split(/\;/, $tag); + $quality =~ s/^q=//i if $quality; + $quality = 1 unless $quality; + next if $quality <= 0; + # We want to force the wildcard to be last + $quality = 0 if ($language eq '*'); + # Pushing lowercase language here saves processing later + push(@languages, { quality => $quality, + language => $language, + lclanguage => lc($language) }); + } + } else { + carp "accept_language(x,y) called with no clientPreferences (x)."; + } + # Prepare the list of server-supported languages + my %supportedLanguages = (); + my %secondaryLanguages = (); + foreach my $language (@$supportedLanguages) { + # warn "Language supported: " . $language->{language_code}; + $supportedLanguages{lc($language->{language_code})} = $language->{language_code}; + if ($language->{language_code} =~ /^([^-]+)-?/) { + $secondaryLanguages{lc($1)} = $language->{language_code}; + } + } + + # Reverse sort the list, making best quality at the front of the array + @languages = sort { $b->{quality} <=> $a->{quality} } @languages; + my $secondaryMatch = ''; + foreach my $tag (@languages) { + if (exists($supportedLanguages{$tag->{lclanguage}})) { + # Client en-us eq server en-us + return $supportedLanguages{$tag->{language}} if exists($supportedLanguages{$tag->{language}}); + return $supportedLanguages{$tag->{lclanguage}}; + } elsif (exists($secondaryLanguages{$tag->{lclanguage}})) { + # Client en eq server en-us + return $secondaryLanguages{$tag->{language}} if exists($secondaryLanguages{$tag->{language}}); + return $supportedLanguages{$tag->{lclanguage}}; + } elsif ($tag->{lclanguage} =~ /^([^-]+)-/ && exists($secondaryLanguages{$1}) && $secondaryMatch eq '') { + # Client en-gb eq server en-us + $secondaryMatch = $secondaryLanguages{$1}; + } elsif ($tag->{lclanguage} =~ /^([^-]+)-/ && exists($secondaryLanguages{$1}) && $secondaryMatch eq '') { + # FIXME: We just checked the exact same conditional! + # Client en-us eq server en + $secondaryMatch = $supportedLanguages{$1}; + } elsif ($tag->{lclanguage} eq '*') { + # * matches every language not already specified. + # It doesn't care which we pick, so let's pick the default, + # if available, then the first in the array. + #return $acceptor->defaultLanguage() if $acceptor->defaultLanguage(); + return $supportedLanguages->[0]; + } + } + # No primary matches. Secondary? (ie, en-us requested and en supported) + return $secondaryMatch if $secondaryMatch; + return undef; # else, we got nothing. } 1; diff --git a/C4/Output.pm b/C4/Output.pm index 1c12a73464..3d9caf162a 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -34,16 +34,16 @@ use HTML::Template::Pro; use vars qw($VERSION @ISA @EXPORT); BEGIN { - # set the version for version checking - $VERSION = 3.01; - require Exporter; - @ISA = qw(Exporter); - push @EXPORT, qw( - &themelanguage &gettemplate setlanguagecookie pagination_bar - ); - push @EXPORT, qw( - &output_html_with_http_headers - ); + # set the version for version checking + $VERSION = 3.01; + require Exporter; + @ISA = qw(Exporter); + push @EXPORT, qw( + &themelanguage &gettemplate setlanguagecookie pagination_bar + ); + push @EXPORT, qw( + &output_html_with_http_headers + ); } =head1 NAME @@ -77,14 +77,14 @@ sub gettemplate { my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query ); my $opacstylesheet = C4::Context->preference('opacstylesheet'); - # if the template doesn't exist, load the English one as a last resort - my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; - unless (-f $filename) { - $lang = 'en'; - $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase"; - } + # if the template doesn't exist, load the English one as a last resort + my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; + unless (-f $filename) { + $lang = 'en'; + $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase"; + } my $template = HTML::Template::Pro->new( - filename => $filename, + filename => $filename, die_on_bad_params => 1, global_vars => 1, case_sensitive => 1, @@ -102,34 +102,16 @@ sub gettemplate { lang => $lang ); - # Bidirectionality - my $current_lang = regex_lang_subtags($lang); - my $bidi; - $bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; - - # Languages - my @template_languages; - my $languages_loop = getTranslatedLanguages($interface,$theme); - - for my $language_hashref (@$languages_loop) { - $language_hashref->{'current_lang'} = $current_lang->{'language'}; - $language_hashref->{'native_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'language_code'},'language'); - #warn "($language_hashref->{'language_code'},$language_hashref->{'current_lang'},$language_hashref->{'script_code'}"; - $language_hashref->{'locale_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language'); - $language_hashref->{'language_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language'); - $language_hashref->{'script_description'} = language_get_description($language_hashref->{'script_code'},$language_hashref->{'current_lang'},'script'); - $language_hashref->{'region_description'} = language_get_description($language_hashref->{'region_code'},$language_hashref->{'current_lang'},'region'); - $language_hashref->{'variant_description'} = language_get_description($language_hashref->{'variant_code'},$language_hashref->{'current_lang'},'variant'); - - if ($language_hashref->{'language_lang'} eq $lang) { - $language_hashref->{current}++; - } - push @template_languages, $language_hashref; - } - # load the languages ( for switching from one template to another ) - $template->param( languages_loop => \@template_languages, - bidi => $bidi - ); + # Bidirectionality + my $current_lang = regex_lang_subtags($lang); + my $bidi; + $bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; + # Languages + my $languages_loop = getTranslatedLanguages($interface,$theme,$lang); + $template->param( + languages_loop => $languages_loop, + bidi => $bidi + ) unless @$languages_loop<2; return $template; } @@ -140,19 +122,18 @@ sub themelanguage { my ( $htdocs, $tmpl, $interface, $query ) = @_; ($query) or warn "no query in themelanguage"; - # Set some defaults for language and theme - # First, check the user's preferences - my $lang; - my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{language}; - if ($http_accept_language) { - $lang = accept_language($http_accept_language,getTranslatedLanguages($interface,'prog')); - } - # But, if there's a cookie set, obey it - $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage'); - - # Fall back to English - $lang = 'en' unless $lang; - my $theme = 'prog'; + # Set some defaults for language and theme + # First, check the user's preferences + my $lang; + my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{language}; + if ($http_accept_language) { + $lang = accept_language($http_accept_language,getTranslatedLanguages($interface,'prog')); + } + # But, if there's a cookie set, obey it + $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage'); + # Fall back to English + $lang = 'en' unless $lang; + my $theme = 'prog'; my $dbh = C4::Context->dbh; my @languages; @@ -160,14 +141,14 @@ sub themelanguage { if ( $interface eq "intranet" ) { @languages = split " ", C4::Context->preference("opaclanguages"); @themes = split " ", C4::Context->preference("template"); - push @languages, $lang if $lang; + @languages = ($lang,@languages) if $lang; } else { # we are in the opac here, what im trying to do is let the individual user # set the theme they want to use. # and perhaps the them as well. #my $lang = $query->cookie('KohaOpacLanguage'); - if ($lang) { # FIXME: if $lang always TRUE! + if ($lang) { # FIXME: if $lang always TRUE! push @languages, $lang; } else { @@ -178,18 +159,20 @@ sub themelanguage { # searches through the themes and languages. First template it find it returns. # Priority is for getting the theme right. - THEME: + THEME: foreach my $th (@themes) { foreach my $la (@languages) { - for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) { - $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2; - if ( -e "$htdocs/$th/$la/".($interface eq 'intranet'?"modules":"")."/$tmpl" ) { + #for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) { + warn "$htdocs/$th/$la/modules/$interface-"."tmpl"; + #$la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2; + if ( -e "$htdocs/$th/$la/modules/$interface-"."tmpl") { + #".($interface eq 'intranet'?"modules":"")."/$tmpl" ) { $theme = $th; $lang = $la; last THEME; } last unless $la =~ /[-_]/; - } + #} } } return ( $theme, $lang ); @@ -363,8 +346,8 @@ sub output_html_with_http_headers ($$$) { -type => 'text/html', -charset => 'UTF-8', -cookie => $cookie, - -Pragma => 'no-cache', - -'Cache-Control' => 'no-cache', + -Pragma => 'no-cache', + -'Cache-Control' => 'no-cache', ), $html; } diff --git a/installer/data/mysql/en/mandatory/subtag_registry.sql b/installer/data/mysql/en/mandatory/subtag_registry.sql index 861207cdcb..cb4d67fb1d 100644 --- a/installer/data/mysql/en/mandatory/subtag_registry.sql +++ b/installer/data/mysql/en/mandatory/subtag_registry.sql @@ -40,10 +40,10 @@ INSERT INTO language_subtag_registry( subtag, type, description, added) VALUES ( 'prog', 't', 'Prog','2005-10-16'); INSERT INTO language_descriptions(subtag, type, lang, description) -VALUES( 'prog', 'i', 'en', 'Prog'); +VALUES( 'prog', 't', 'en', 'Prog'); INSERT INTO language_descriptions(subtag, type, lang, description) -VALUES( 'prog', 'i', 'fr', 'Prog'); +VALUES( 'prog', 't', 'fr', 'Prog'); -- LANGUAGES diff --git a/installer/install.pl b/installer/install.pl index f3c1a19f8f..c88e742344 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -667,19 +667,8 @@ else { # LANGUAGE SELECTION page by default # using opendir + language Hash - - my $langavail = getTranslatedLanguages(); - - my @languages; - foreach (@$langavail) { - push @languages, - { - 'value' => $_->{'language_code'}, - 'description' => $_->{'language_name'} - } - if ( $_->{'language_code'} ); - } - $template->param( languages => \@languages ); + my $languages_loop = getTranslatedLanguages(); + $template->param( installer_languages_loop => $languages_loop ); if ($dbh) { my $rq = $dbh->prepare( 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 5a3835e58d..d02d295d1e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc @@ -1,18 +1,34 @@ - - +
+
    + + + +
  • ()
      + + + +
    • ()
    • + +
    • "> ()
    • + + + +
  • + + +
  • ()
  • + +
  • "> ()
  • + + + + +
+
+ diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js index 53efa8955f..45e6c7ed38 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js @@ -5,6 +5,7 @@ function _(s) { return s } // dummy function for gettext $(document).ready(function() { $(".focus").focus(); $('#toplevelmenu').clickMenu(); + $('#i18nMenu').clickMenu(); $('#header_search').tabs({ onShow: function() { $('#header_search').find('div:visible').find('input').eq(0).focus(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl index c487937409..c60539f59f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tmpl @@ -112,9 +112,9 @@ - + - + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step1.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step1.tmpl index f368b8bd62..f8e15bcac9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step1.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step1.tmpl @@ -10,10 +10,19 @@ listed, please inform your systems administrator.

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 9bebcd7979..f1d6281d59 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/opac-bottom.inc @@ -4,6 +4,36 @@ + +
+
    + + + +
  • ()
      + + + +
    • ()
    • + +
    • "> ()
    • + + + +
  • + + + +
  • ()
  • + +
  • "> ()
  • + + + + +
+
+ -- 2.39.5