View | Details | Raw Unified | Return to bug 29245
Collapse All | Expand All

(-)a/C4/Languages.pm (-15 / +19 lines)
Lines 97-125 sub getFrameworkLanguages { Link Here
97
97
98
=head2 getTranslatedLanguages
98
=head2 getTranslatedLanguages
99
99
100
Returns a reference to an array of hashes:
100
    my $languages = getTranslatedLanguages( 'opac', 'bootstrap' );
101
101
102
 my $languages = getTranslatedLanguages();
102
    Parameter interface falls back to opac.
103
 print "Available translated languages:\n";
103
    Parameter theme falls back to pref opacthemes or template (stafftheme).
104
 for my $language(@$trlanguages) {
104
105
    print "$language->{language_code}\n"; # language code in iso 639-2
105
    Returns a reference to an array of hashes.
106
    print "$language->{language_name}\n"; # language name in native script
106
107
    print "$language->{language_locale_name}\n"; # language name in current locale
107
    Key language_code refers to ISO 639-2.
108
 }
108
    Key language_name is name in native script.
109
    Key language_locale_name is name in current locale.
109
110
110
=cut
111
=cut
111
112
112
sub getTranslatedLanguages {
113
sub getTranslatedLanguages {
113
    my ($interface, $theme, $current_language, $which) = @_;
114
    my ( $interface, $theme, $current_language ) = @_;
115
    $interface ||= 'opac';
116
    $theme ||= C4::Context->preference(
117
        $interface eq 'opac' ? 'opacthemes' : 'template'
118
    );
119
114
    my @languages;
120
    my @languages;
115
    my @enabled_languages =
121
    my @enabled_languages = $interface eq 'intranet'
116
      ( $interface && $interface eq 'intranet' )
117
      ? split ",", C4::Context->preference('language')
122
      ? split ",", C4::Context->preference('language')
118
      : split ",", C4::Context->preference('OPACLanguages');
123
      : split ",", C4::Context->preference('OPACLanguages');
119
124
120
    my $cache = Koha::Caches->get_instance;
125
    my $cache = Koha::Caches->get_instance;
121
    my $cache_key = "languages_${interface}_${theme}";
126
    my $cache_key = "languages_${interface}_${theme}";
122
    if ($interface && $interface eq 'opac' ) {
127
    if( $interface eq 'opac' ) {
123
        my $htdocs = C4::Context->config('opachtdocs');
128
        my $htdocs = C4::Context->config('opachtdocs');
124
        my $cached = $cache->get_from_cache($cache_key);
129
        my $cached = $cache->get_from_cache($cache_key);
125
        if ( $cached ) {
130
        if ( $cached ) {
Lines 129-135 sub getTranslatedLanguages { Link Here
129
            $cache->set_in_cache($cache_key, \@languages );
134
            $cache->set_in_cache($cache_key, \@languages );
130
        }
135
        }
131
    }
136
    }
132
    elsif ($interface && $interface eq 'intranet' ) {
137
    elsif( $interface eq 'intranet' ) {
133
        my $htdocs = C4::Context->config('intrahtdocs');
138
        my $htdocs = C4::Context->config('intrahtdocs');
134
        my $cached = $cache->get_from_cache($cache_key);
139
        my $cached = $cache->get_from_cache($cache_key);
135
        if ( $cached ) {
140
        if ( $cached ) {
Lines 150-156 sub getTranslatedLanguages { Link Here
150
        $seen{$_}++ for @languages;
155
        $seen{$_}++ for @languages;
151
        @languages = keys %seen;
156
        @languages = keys %seen;
152
    }
157
    }
153
    return _build_languages_arrayref(\@languages,$current_language,\@enabled_languages);
158
    return _build_languages_arrayref( \@languages, $current_language, \@enabled_languages );
154
}
159
}
155
160
156
=head2 getAllLanguages
161
=head2 getAllLanguages
157
- 

Return to bug 29245