Lines 28-33
use List::MoreUtils qw( any );
Link Here
|
28 |
use C4::Context; |
28 |
use C4::Context; |
29 |
use Koha::Caches; |
29 |
use Koha::Caches; |
30 |
use Koha::Cache::Memory::Lite; |
30 |
use Koha::Cache::Memory::Lite; |
|
|
31 |
use Koha::Language; |
31 |
|
32 |
|
32 |
our (@ISA, @EXPORT_OK); |
33 |
our (@ISA, @EXPORT_OK); |
33 |
BEGIN { |
34 |
BEGIN { |
Lines 111-122
Returns a reference to an array of hashes:
Link Here
|
111 |
=cut |
112 |
=cut |
112 |
|
113 |
|
113 |
sub getTranslatedLanguages { |
114 |
sub getTranslatedLanguages { |
114 |
my ($interface, $theme, $current_language, $which) = @_; |
115 |
my ($interface, $theme, $current_language) = @_; |
115 |
my @languages; |
116 |
my @languages; |
116 |
my @enabled_languages = |
117 |
|
117 |
( $interface && $interface eq 'intranet' ) |
118 |
my @enabled_languages; |
118 |
? split ",", C4::Context->preference('StaffInterfaceLanguages') |
119 |
if ($interface) { |
119 |
: split ",", C4::Context->preference('OPACLanguages'); |
120 |
if ($interface eq 'intranet') { |
|
|
121 |
@enabled_languages = split ",", C4::Context->preference('StaffInterfaceLanguages'); |
122 |
} elsif ($interface eq 'opac') { |
123 |
@enabled_languages = split ",", C4::Context->preference('OPACLanguages'); |
124 |
} |
125 |
} |
120 |
|
126 |
|
121 |
my $cache = Koha::Caches->get_instance; |
127 |
my $cache = Koha::Caches->get_instance; |
122 |
my $cache_key = "languages_${interface}_${theme}"; |
128 |
my $cache_key = "languages_${interface}_${theme}"; |
Lines 618-625
sub accept_language {
Link Here
|
618 |
|
624 |
|
619 |
=head2 getlanguage |
625 |
=head2 getlanguage |
620 |
|
626 |
|
621 |
Select a language based on the URL parameter 'language', a cookie, |
627 |
Select a language based on: |
622 |
syspref available languages & browser |
628 |
|
|
|
629 |
=over |
630 |
|
631 |
=item * the URL parameter 'language' (staff and opac interfaces only), |
632 |
|
633 |
=item * the 'KohaOpacLanguage' cookie (staff and opac interfaces only), |
634 |
|
635 |
=item * the language set by C<Koha::Language::set_requested_language> |
636 |
(interfaces other than staff and opac only). The REST API sets this to the |
637 |
value of 'KohaOpacLanguage' cookie, |
638 |
|
639 |
=item * syspref StaffInterfaceLanguages (staff only) |
640 |
|
641 |
=item * syspref OpacLanguages (opac only), |
642 |
|
643 |
=item * HTTP header Accept-Language (more precisely, environment variable |
644 |
HTTP_ACCEPT_LANGUAGE) |
645 |
|
646 |
=back |
623 |
|
647 |
|
624 |
=cut |
648 |
=cut |
625 |
|
649 |
|
Lines 633-661
sub getlanguage {
Link Here
|
633 |
return $cached if $cached; |
657 |
return $cached if $cached; |
634 |
} |
658 |
} |
635 |
|
659 |
|
636 |
$cgi //= CGI->new; |
|
|
637 |
my $interface = C4::Context->interface; |
660 |
my $interface = C4::Context->interface; |
638 |
my $theme = C4::Context->preference( ( $interface eq 'opac' ) ? 'opacthemes' : 'template' ); |
661 |
my $theme = ''; |
639 |
my $language; |
662 |
my $language; |
640 |
|
|
|
641 |
my $preference_to_check = |
642 |
$interface eq 'intranet' ? 'StaffInterfaceLanguages' : 'OPACLanguages'; |
643 |
# Get the available/valid languages list |
644 |
my @languages; |
663 |
my @languages; |
645 |
my $preference_value = C4::Context->preference($preference_to_check); |
|
|
646 |
if ($preference_value) { |
647 |
@languages = split /,/, $preference_value; |
648 |
} |
649 |
|
664 |
|
650 |
# Chose language from the URL |
665 |
if ($interface eq 'opac' || $interface eq 'intranet') { |
651 |
my $cgi_param_language = $cgi->param( 'language' ); |
666 |
$cgi //= CGI->new; |
652 |
if ( defined $cgi_param_language && any { $_ eq $cgi_param_language } @languages) { |
667 |
$theme = C4::Context->preference( ( $interface eq 'opac' ) ? 'opacthemes' : 'template' ); |
653 |
$language = $cgi_param_language; |
668 |
|
654 |
} |
669 |
my $preference_to_check = |
|
|
670 |
$interface eq 'intranet' ? 'StaffInterfaceLanguages' : 'OPACLanguages'; |
671 |
# Get the available/valid languages list |
672 |
my $preference_value = C4::Context->preference($preference_to_check); |
673 |
if ($preference_value) { |
674 |
@languages = split /,/, $preference_value; |
675 |
} |
676 |
|
677 |
# Chose language from the URL |
678 |
my $cgi_param_language = $cgi->param( 'language' ); |
679 |
if ( defined $cgi_param_language && any { $_ eq $cgi_param_language } @languages) { |
680 |
$language = $cgi_param_language; |
681 |
} |
655 |
|
682 |
|
656 |
# cookie |
683 |
# cookie |
657 |
if (not $language and my $cgi_cookie_language = $cgi->cookie('KohaOpacLanguage') ) { |
684 |
if (not $language and my $cgi_cookie_language = $cgi->cookie('KohaOpacLanguage') ) { |
658 |
( $language = $cgi_cookie_language ) =~ s/[^a-zA-Z_-]*//; # sanitize cookie |
685 |
( $language = $cgi_cookie_language ) =~ s/[^a-zA-Z_-]*//; # sanitize cookie |
|
|
686 |
} |
687 |
} else { |
688 |
@languages = map { $_->{rfc4646_subtag} } @{ getTranslatedLanguages($interface, $theme) }; |
689 |
$language = Koha::Language->get_requested_language(); |
659 |
} |
690 |
} |
660 |
|
691 |
|
661 |
# HTTP_ACCEPT_LANGUAGE |
692 |
# HTTP_ACCEPT_LANGUAGE |