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

(-)a/C4/Languages.pm (-45 / +66 lines)
Lines 191-247 sub getLanguages { Link Here
191
    my $lang = shift;
191
    my $lang = shift;
192
    my $isFiltered = shift;
192
    my $isFiltered = shift;
193
193
194
    my @languages_loop;
194
    my $dbh = C4::Context->dbh;
195
    my $dbh=C4::Context->dbh;
195
196
    my $default_language = 'en';
196
    my $default_language = 'en';
197
    my $current_language = $default_language;
197
    my $current_language = $default_language;
198
    my $language_list = $isFiltered ? C4::Context->preference("AdvancedSearchLanguages") : undef;
199
    if ($lang) {
198
    if ($lang) {
200
        $current_language = regex_lang_subtags($lang)->{'language'};
199
        $current_language = regex_lang_subtags($lang)->{'language'};
201
    }
200
    }
202
    my $sth = $dbh->prepare('SELECT * FROM language_subtag_registry WHERE type=\'language\' ORDER BY description');
203
    $sth->execute();
204
    while (my $language_subtag_registry = $sth->fetchrow_hashref) {
205
        my $desc;
206
        # check if language name is stored in current language
207
        my $sth4= $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag =? AND lang = ?");
208
        $sth4->execute($language_subtag_registry->{subtag},$current_language);
209
        while (my $language_desc = $sth4->fetchrow_hashref) {
210
             $desc=$language_desc->{description};
211
        }
212
        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 =? AND language_descriptions.lang = ?");
213
        if ($desc) {
214
            $sth2->execute($language_subtag_registry->{subtag},$current_language);
215
        }
216
        else {
217
            $sth2->execute($language_subtag_registry->{subtag},$default_language);
218
        }
219
        my $sth3 = $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag=? AND lang=?");
220
        # add the correct description info
221
        while (my $language_descriptions = $sth2->fetchrow_hashref) {
222
            $sth3->execute($language_subtag_registry->{subtag},$language_subtag_registry->{subtag});
223
            my $native_description;
224
            while (my $description = $sth3->fetchrow_hashref) {
225
                $native_description = $description->{description};
226
            }
227
201
228
            # fill in the ISO6329 code
202
    my $language_list = $isFiltered ? C4::Context->preference("AdvancedSearchLanguages") : undef;
229
            $language_subtag_registry->{iso639_2_code} = $language_descriptions->{iso639_2_code};
203
    my $language_list_cond = $language_list ? 'HAVING FIND_IN_SET(language_rfc4646_to_iso639.iso639_2_code, ?)' : '';
230
            # fill in the current selected ui language's translation, as well as the native description of the language
204
231
            if ($native_description) {
205
    my $sth = $dbh->prepare("
232
                $language_subtag_registry->{language_description} = $language_descriptions->{description} || q{};
206
    SELECT
233
                $language_subtag_registry->{language_description} .= " ($native_description)";
207
    language_subtag_registry.*,
234
            }
208
    language_rfc4646_to_iso639.iso639_2_code,
235
            else {
209
    CASE
236
                $language_subtag_registry->{language_description} = $language_descriptions->{description};
210
        -- If user's localized name of given lang is available
237
            }
211
        WHEN current_language_descriptions.description IS NOT NULL
238
        }
212
        THEN
239
        # Do not push unless valid iso639-2 code
213
            CASE
240
        if ( $language_subtag_registry->{ iso639_2_code } and ( !$language_list || index (  $language_list, $language_subtag_registry->{ iso639_2_code } ) >= 0) ) {
214
                -- Append native translation of given language if possible
241
            push @languages_loop, $language_subtag_registry;
215
                WHEN native_language_descriptions.description IS NOT NULL
242
        }
216
                    AND native_language_descriptions.description != current_language_descriptions.description
217
                THEN CONCAT(current_language_descriptions.description, ' (', native_language_descriptions.description, ')')
218
                ELSE current_language_descriptions.description
219
            END
220
        ELSE -- fall back to English description
221
            CASE
222
                -- Append native translation of given language if possible
223
                WHEN native_language_descriptions.description IS NOT NULL
224
                    AND native_language_descriptions.description != language_subtag_registry.description
225
                THEN CONCAT(language_subtag_registry.description, ' (', native_language_descriptions.description, ')')
226
                ELSE language_subtag_registry.description
227
            END
228
    END AS language_description
229
230
    -- Useful if debugging the query:
231
    -- current_language_descriptions.description AS _current_language_descriptions_description,
232
    -- native_language_descriptions.description AS _native_language_descriptions_description
233
234
    FROM language_subtag_registry
235
236
    -- Grab ISO code for language
237
    INNER JOIN language_rfc4646_to_iso639
238
    ON language_rfc4646_to_iso639.rfc4646_subtag = language_subtag_registry.subtag
239
    AND language_rfc4646_to_iso639.iso639_2_code IS NOT NULL
240
241
    -- Grab language name in user's current language
242
    LEFT JOIN language_descriptions current_language_descriptions
243
    ON current_language_descriptions.subtag = language_subtag_registry.subtag
244
    AND current_language_descriptions.lang = ?
245
    AND current_language_descriptions.type = 'language'
246
247
    -- Grab language name in the given language itself
248
    LEFT JOIN language_descriptions native_language_descriptions
249
    ON native_language_descriptions.subtag = language_subtag_registry.subtag
250
    AND native_language_descriptions.lang = language_subtag_registry.subtag
251
    AND native_language_descriptions.type = 'language'
252
253
    WHERE language_subtag_registry.type = 'language'
254
    ${language_list_cond}");
255
256
    if ($language_list) {
257
        $sth->execute($current_language, join ',' => split(/,|\|/, $language_list));
258
    } else {
259
        $sth->execute($current_language);
260
    }
261
262
    my @languages_list;
263
    while (my $row = $sth->fetchrow_hashref) {
264
        push @languages_list, $row;
243
    }
265
    }
244
    return \@languages_loop;
266
    return \@languages_list;
245
}
267
}
246
268
247
sub _get_opac_language_dirs {
269
sub _get_opac_language_dirs {
248
- 

Return to bug 38646