[Bug 39851] New: Languages for REST API is returned in random order
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Bug ID: 39851 Summary: Languages for REST API is returned in random order Change sponsored?: --- Product: Koha Version: 24.11 Hardware: All OS: All Status: NEW Severity: major Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: jonathan.druart@gmail.com QA Contact: testopia@bugs.koha-community.org CC: tomascohen@gmail.com 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(); -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #1 from Jonathan Druart <jonathan.druart@gmail.com> --- Note that if HTTP_ACCEPT_LANGUAGE is set to a language that is installed it will be used correctly. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Version|24.11 |unspecified -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |martin.renvoize@openfifth.c | |o.uk Severity|major |normal -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pedro.amorim@openfifth.co.u | |k --- Comment #2 from Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> --- *** Bug 42715 has been marked as a duplicate of this bug. *** -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #3 from Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> --- Originally in bug 42715: Regular fresh ktd, install en-GB (don't enable, just install): 1) Enable ILLModule, create 1 ILL request, visit: http://localhost:8081/cgi-bin/koha/ill/ill-requests.pl?method=create&backend=Standard 2) Pick a type, a cardnumber e.g. 42 and a destination library. Create. 3) Artificially set this request's status to CHK, run: $ koha-mysql kohadev $ update illrequests set status = 'CHK' where illrequest_id = 1; 4) Visit the ILL list: http://localhost:8081/cgi-bin/koha/ill/ill-requests.pl 5) Refresh a few times, notice the status is always 'Checked out'. 6) Set 20 plack workers: $ sed -i 's|<plack_workers>2</plack_workers>|<plack_workers>20</plack_workers>|' /etc/koha/sites/kohadev/koha-conf.xml 7) Install en-GB translation and restart plack: $ koha-translate --install en-GB --dev kohadev $ koha-plack --restart kohadev 8) Repeat 5. Notice you sometimes get 'Issued', other times you get 'Checked out'. 9) Bonus: Install fr-FR, also without enabling it, and refresh: You'll now sometimes get 'Prêté' instead of 'Checked out' or 'Issued'. It's picking up a random installed translation on every new page load, even without enabling - or selecting - that particular language. I believe different plack workers are picking up different installed languages and API requests where $interface == 'api' get confused. It's much less noticeable (or can't reproduce at all) if we keep the stock 2 plack workers. My current leads: 1) strings_map in ILL/Request.pm use of cache may be part of the problem. 2) the 'else' in C4::Languages::getlanguage where interface is neither 'staff' or 'opac' is somehow picking up all installed languages regardless if enabled or not? 3) Plan to consider a x-koha-interface HTTP header and have kohaTable make use of that? Could fix the problem but only by working around it. I've explored all of the above but got nowhere and have unfortunately ran out of time here. Any thoughts are welcome! -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@gmail.com, | |julian.maurice@biblibre.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #4 from Katrin Fischer <katrin.fischer@bsz-bw.de> --- Could this also be what we see in bug 40666? -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #5 from Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> --- (In reply to Katrin Fischer from comment #4)
Could this also be what we see in bug 40666?
Possibly, but not sure. I left a comment on bug 40666. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |katrin.fischer@bsz-bw.de --- Comment #6 from Jonathan Druart <jonathan.druart@gmail.com> --- *** Bug 40666 has been marked as a duplicate of this bug. *** -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #7 from Jonathan Druart <jonathan.druart@gmail.com> --- Created attachment 199730 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=199730&action=edit Bug 39851: Expose KohaOpacLanguage to JS So the cookie can be retrieved from JS. It's not a security concern to expose this value. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #8 from Jonathan Druart <jonathan.druart@gmail.com> --- Created attachment 199731 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=199731&action=edit Bug 39851: Compare all sublanguages for a given language To know if a language is available we list all the languages in the first level of the array. Example for "fr": [8] { current 0, group_enabled undef, language "fr", native_description "Français", plural 1, rfc4646_subtag "fr-CA", sublanguages_loop [ [0] { extension undef, language "fr", native_description "Français", privateuse undef, region "CA", region_description "Canada", rfc4646_subtag "fr-CA", script undef, script_description undef, variant undef, variant_description undef }, [1] { extension undef, language "fr", native_description "Français", privateuse undef, region "FR", region_description "France", rfc4646_subtag "fr-FR", script undef, script_description undef, variant undef, variant_description undef } ] }, The rfc4646_subtag entry at the "language" level get one of the 2 values from the sublanguages_loop, randomly! So if you request fr-FR but fr-CA is set, then it's considered not available and one of the languages in @languages will be picked randomly (actually the first one, but it's not sorted consistently!) -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #9 from Jonathan Druart <jonathan.druart@gmail.com> --- Created attachment 199732 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=199732&action=edit Bug 39851: Accept Accept-Language at the REST API level We allow KohaOpacLanguage but Accept-Language is not taken into account. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 --- Comment #10 from Jonathan Druart <jonathan.druart@gmail.com> --- Created attachment 199733 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=199733&action=edit Bug 39851: Pass Accept-Header from the UI, based on OpacKohaLanguage We set Accept-Header from the OpacKohaLanguage cookie value for: Fetches from regular Koha Fetches from Vue apps Requests from KohaTable/DataTables -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |38630 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38630 [Bug 38630] Make the REST API respect KohaOpacLanguage cookie -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |jonathan.druart@gmail.com |ity.org | CC| |dcook@prosentient.com.au Status|NEW |Needs Signoff --- Comment #11 from Jonathan Druart <jonathan.druart@gmail.com> --- For discussion, and ready for testing. But I don't think it's ready for inclusion yet (at least tests are missing). I have found several bugs in the area that I've tried to fix. I am not sure about the change in the .js file. Now that KohaOpacLanguage is exposed to JS the cookie is passed anyway. But I think it's better to use Accept-Language instead of the cookie, what do you think? -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39851 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42727 -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org