Koha-clms/t/db_dependent/api/v1
Julian Maurice 045818de6e
Bug 38630: Make the REST API respect KohaOpacLanguage cookie
The REST API can return translated strings to the opac or staff
interface, so it should respect the KohaOpacLanguage cookie and return
translations in the same language than the interface.

Test plan:
1. Do not apply patch yet
2. Log in to koha staff interface
3. Use the browser's devtools to get the value of CGISESSID cookie
4. Make sure you have at least 2 languages installed ('en' + another
   one - I'll use 'fr-FR' as an example in this test plan)
5. Find an item and note its itemnumber and itemtype
6. Go translate this itemtype's description (admin » item types » edit
   item type » translate). Add a translation for 'en' and another one
   for your language.
7. Close your browser tab (do not logout) and restart Koha to flush the
   memory cache.
8. Execute the following commands (replace variables by the correct
   value):

    curl -sSL "$KOHA_URL/api/v1/items/$ITEMNUMBER" \
        -H 'x-koha-embed: +strings' \
        -H "Cookie: KohaOpacLanguage=en; CGISESSID=$CGISESSID" \
        | jq -r '._strings.item_type_id.str'

   If you do not have jq, it can be found in most distributions
   packages. Or you could inspect the JSON manually at the path
   /_strings/item_type_id/str

   Restart Koha again, and execute the same command but with your
   language set in KohaOpacLanguage cookie:

    curl -sSL "$KOHA_URL/api/v1/items/$ITEMNUMBER" \
        -H 'x-koha-embed: +strings' \
        -H "Cookie: KohaOpacLanguage=fr-FR; CGISESSID=$CGISESSID" \
        | jq -r '._strings.item_type_id.str'

   Depending on how Koha sort the languages (not sure how it's done),
   you should get either the 'en' one or the 'fr-FR' one, but the
   important thing is you should get the same translation, no matter
   what the value of KohaOpacLanguage is, which is the issue this patch
   is trying to fix.
9. Apply the patch and restart Koha
10. Repeat step 8. This time you should get the translation
    corresponding to the language set in KohaOpacLanguage cookie

Side note:
* The need to restart Koha before each request is due to a bug (see bug
  38454). If already pushed when you're testing this one, you don't have
  to restart.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit ca5db9ffb7)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2025-09-29 09:34:42 +02:00
..
items Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
public Bug 28965: Unit tests 2024-11-08 16:09:23 +01:00
acquisitions_baskets.t Bug 38204: Tidy 2024-10-30 07:47:42 +01:00
acquisitions_funds.t Bug 29523: Remove the FIXME 2023-10-27 16:40:45 -03:00
acquisitions_orders.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
acquisitions_vendor_issues.t Bug 33105: Tidy files 2023-07-20 10:59:31 -03:00
acquisitions_vendors.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
advanced_editor_macros.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
article_requests.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
auth.t Bug 34999: Add unit test 2024-01-16 12:05:59 +01:00
auth_authenticate_api_request.t Bug 32551: Regression tests 2024-01-11 15:44:44 +01:00
auth_basic.t Bug 36420: Unit tests 2024-04-18 16:51:14 +02:00
authorised_values.t Bug 37289: Add sorting to test 2024-07-11 13:40:49 +02:00
authorities.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
biblios.t Bug 35246: Unit tests 2025-08-06 13:25:36 +00:00
bookings.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
cashups.t Bug 36493: Make cashups test more robust 2024-04-12 11:26:01 +02:00
checkouts.t Bug 28907: REST - Remove allow-owner from public checkouts route 2025-02-18 19:17:17 +01:00
circulation_rules.t Bug 36641: (follow-up) Ensure limited return works 2024-07-18 18:25:49 +02:00
cities.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
clubs_holds.t Bug 38929: Regression tests 2025-04-22 23:02:21 +02:00
deleted_biblios.t Bug 38678: Regression tests 2025-02-04 21:40:48 +01:00
edifact_files.t Bug 30070: (follow-up) Filter out deleted files on the API 2024-01-17 11:38:57 +01:00
erm_agreements.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
erm_counter_files.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
erm_counter_logs.t Bug 36627: Fix typo "embeded" 2025-03-19 23:57:21 +01:00
erm_counter_registries.t Bug 37898: Wrap some ERM api tests inside a transaction 2024-09-19 12:50:20 +01:00
erm_custom_reports.t Bug 38782: mock_userenv in API tests 2025-03-19 23:57:36 +01:00
erm_documents.t
…
erm_eholdings_packages.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
erm_eholdings_resources.t
…
erm_eholdings_titles.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
erm_licenses.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
erm_sushi_services.t Bug 39007: Update API spec and unit test 2025-03-19 23:57:55 +01:00
erm_usage_data_providers.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
erm_usage_titles.t Bug 34587: Fix license issues 2023-11-01 09:26:11 -03:00
erm_users.t Bug 38322: (QA follow-up) Fix spelling 2024-11-13 17:00:51 +01:00
extended_attribute_types.t Bug 37262: Tests for filtering unmapped tablename 2024-07-12 10:21:22 +02:00
holds.t Bug 40372: Remove warning from api/v1/holds.t 2025-08-01 15:35:37 +02:00
idp.t
…
ill_backends.t Bug 35581: Koha::Illrequest -> Koha::ILL::Request 2024-04-22 08:57:45 +02:00
ill_batches.t Bug 35581: Koha::Illrequest -> Koha::ILL::Request 2024-04-22 08:57:45 +02:00
ill_batchstatuses.t Bug 38929: Regression tests 2025-04-22 23:02:21 +02:00
ill_requests.t Bug 35581: Koha::Illrequest -> Koha::ILL::Request 2024-04-22 08:57:45 +02:00
import_batch_profiles.t Bug 38929: Regression tests 2025-04-22 23:02:21 +02:00
import_record_matches.t
…
item_groups.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
item_types.t Bug 34008: Harmonize attribute names 2023-11-01 17:23:15 -03:00
items.t Bug 38630: Make the REST API respect KohaOpacLanguage cookie 2025-09-29 09:34:42 +02:00
jobs.t Bug 36495: Use render_resource_not_found() helper everywhere 2024-04-26 18:06:13 +02:00
libraries.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
oauth.t
…
pagination.t Bug 35129: Regression tests 2024-04-04 15:24:34 +02:00
password_validation.t Bug 36575: (QA follow-up) 2024-06-20 17:55:32 +02:00
patron_categories.t Bug 36453: (QA follow-up) Update api spec 2024-06-11 10:43:54 +01:00
patrons.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
patrons_accounts.t Bug 38932: Regression tests 2025-04-22 23:02:25 +02:00
patrons_checkouts.t Bug 22613: Add GET endpoint /patrons/{patron_id}/checkouts 2024-04-26 20:15:49 +02:00
patrons_extended_attributes.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
patrons_holds.t Bug 39710: Unit test 2025-05-23 12:18:30 +02:00
patrons_password.t Bug 28097: REST - Remove allow-owner from public password route 2025-02-18 19:17:17 +01:00
patrons_password_expiration.t
…
patrons_recalls.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
preservation_Processings.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
preservation_Trains.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
preservation_WaitingList.t Bug 30708: Tidy perl files 2023-10-18 15:42:04 -03:00
provider.t Bug 37157: Fix Malformed UTF-8 character in JSON string before decode_json 2024-06-27 11:50:06 +02:00
query.t Bug 37018: Add 400 response definition to all routes 2024-08-01 17:26:44 +02:00
record_sources.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
responses.t Bug 36641: Fix tests 2024-07-18 18:25:50 +02:00
return_claims.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
search_filters.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
smtp_servers.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
stockrotation_rotas.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
stockrotationstage.t Bug 37686: Fix render_resource_not_found() and render_resource_deleted() misses 2024-08-29 18:16:19 +02:00
suggestions.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
ticket_updates.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
tickets.t Bug 38929: (follow-up) Replace SWAGGER -> REST in the tests 2025-04-22 23:02:23 +02:00
transfer_limits.t Bug 38929: Regression tests 2025-04-22 23:02:21 +02:00
two_factor_auth.t Bug 40490: Remove warnings from GD::Barcode::QRcode - U24 2025-09-17 16:40:11 +02:00
unhandled_exceptions.t
…