Bug 39851 - Languages for REST API is returned in random order
Summary: Languages for REST API is returned in random order
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-07 13:00 UTC by Jonathan Druart
Modified: 2025-05-09 13:54 UTC (History)
2 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2025-05-07 13:00:18 UTC
At least for the tests:
Run t/db_dependent/api/v1/ill_requests.t several times. If you have several languages installed it will fail randomly:

    #          $got->[0]{_strings}{status}{str} = 'Solicitado'
    #     $expected->[0]{_strings}{status}{str} = 'Requested'

or

    #          $got->[0]{_strings}{status}{str} = 'Angefordert'
    #     $expected->[0]{_strings}{status}{str} = 'Requested'

This is because getlanguage hit the else:

if ( $interface eq 'opac' || $interface eq 'intranet' ) { 
[...]
} else {                                                                                          
    @languages = map { $_->{rfc4646_subtag} } @{ getTranslatedLanguages( $interface, $theme ) };  
    $language  = Koha::Language->get_requested_language();                                        
}

and getTranslatedLanguages returns the languages in a random order.

So there might be several problems highlighted here.

You can easily recreate the problem with:

use C4::Languages;
use C4::Context;
C4::Context->interface('api');
say C4::Languages::getlanguage();
Comment 1 Jonathan Druart 2025-05-07 13:01:41 UTC
Note that if HTTP_ACCEPT_LANGUAGE is set to a language that is installed it will be used correctly.