From d7efe9ffbbff7dc641f4840bd01b1a969b6d5c4f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 31 Jan 2018 14:36:22 -0300 Subject: [PATCH] Bug 20116: Prepare the ground Just refactoring to make the next patch more readable Signed-off-by: Liz Rea Signed-off-by: Bouzid Fergani Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- C4/Languages.pm | 74 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index 31d17ba73b..0916dd4610 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -111,44 +111,27 @@ Returns a reference to an array of hashes: sub getTranslatedLanguages { my ($interface, $theme, $current_language, $which) = @_; - my $htdocs; my @languages; - my @enabled_languages; - + my @enabled_languages = + ( $interface && $interface eq 'intranet' ) + ? split ",", C4::Context->preference('language') + : split ",", C4::Context->preference('opaclanguages'); + 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); - } - else { - for my $theme ( _get_themes('opac') ) { - push @languages, _get_language_dirs($htdocs,$theme); - } - } + my $htdocs = C4::Context->config('opachtdocs'); + @languages = _get_opac_language_dirs( $htdocs, $theme ); } 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); - } - else { - foreach my $theme ( _get_themes('intranet') ) { - push @languages, _get_language_dirs($htdocs,$theme); - } - } + my $htdocs = C4::Context->config('intrahtdocs'); + @languages = _get_intranet_language_dirs( $htdocs, $theme ); } 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); - } + push @languages, _get_intranet_language_dirs( $htdocs ); + $htdocs = C4::Context->config('opachtdocs'); - foreach my $theme ( _get_themes('opac') ) { - push @languages, _get_language_dirs($htdocs,$theme); - } + push @languages, _get_opac_language_dirs( $htdocs ); + my %seen; $seen{$_}++ for @languages; @languages = keys %seen; @@ -246,6 +229,37 @@ sub getLanguages { return \@languages_loop; } +sub _get_opac_language_dirs { + my ( $htdocs, $theme ) = @_; + + my @languages; + if ( $theme and -d "$htdocs/$theme" ) { + (@languages) = _get_language_dirs($htdocs,$theme); + } + else { + for my $theme ( _get_themes('opac') ) { + push @languages, _get_language_dirs($htdocs,$theme); + } + } + return @languages; +} + + +sub _get_intranet_language_dirs { + my ( $htdocs, $theme ) = @_; + + my @languages; + if ( $theme and -d "$htdocs/$theme" ) { + @languages = _get_language_dirs($htdocs,$theme); + } + else { + foreach my $theme ( _get_themes('intranet') ) { + push @languages, _get_language_dirs($htdocs,$theme); + } + } + return @languages; +} + =head2 _get_themes Internal function, returns an array of all available themes. -- 2.39.5