From 1eb9cc2f9cd87ab373beb7ba5a7b5c5f3b5fce41 Mon Sep 17 00:00:00 2001 From: jsconan Date: Thu, 24 Oct 2024 16:56:07 +0200 Subject: [PATCH 1/3] feat: support querying for multiple resources when listing the translations --- .../Translation/Service/ResourceTranslationRetriever.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/models/classes/Translation/Service/ResourceTranslationRetriever.php b/models/classes/Translation/Service/ResourceTranslationRetriever.php index 28420698f1..dbc609d48a 100644 --- a/models/classes/Translation/Service/ResourceTranslationRetriever.php +++ b/models/classes/Translation/Service/ResourceTranslationRetriever.php @@ -47,6 +47,9 @@ public function getByRequest(ServerRequestInterface $request): ResourceCollectio throw new ResourceTranslationException('Resource id is required'); } - return $this->resourceTranslationRepository->find(new ResourceTranslationQuery([$id], $languageUri)); + if (!is_array($id)) { + $id = explode(',', $id); + } + return $this->resourceTranslationRepository->find(new ResourceTranslationQuery($id, $languageUri)); } } From 542765172d6b7b6cdde3b668e459a5b5d016bc46 Mon Sep 17 00:00:00 2001 From: jsconan Date: Thu, 24 Oct 2024 16:59:26 +0200 Subject: [PATCH 2/3] feat: add support for querying multiple resource for the translations from the FE service --- views/js/services/translation.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/views/js/services/translation.js b/views/js/services/translation.js index 5473bf6194..7e3f7745aa 100644 --- a/views/js/services/translation.js +++ b/views/js/services/translation.js @@ -286,13 +286,25 @@ define(['i18n', 'core/request', 'util/url'], function (__, request, urlUtil) { /** * Queries the list of translations for a resource. - * @param {string} id - The URI of the resource. - * @param {function} [filter] - A filter function for the translations. + * @param {string|string[]} id - The URI of the resource. It may also be a list of URIs, but in this case the languageUri must also be provided. + * @param {string|function} [languageUri] - The URI of the language to filter the translations. It may also be a filter function. + * @param {function} [filter] - A filter function for the translations. When not provided through the languageUri parameter. * @returns {Promise} */ - getTranslations(id, filter) { + getTranslations(id, filter, languageUri) { + if (Array.isArray(id)) { + id = id.join(','); + } + const params = { id }; + if (languageUri) { + if ('function' === typeof languageUri) { + filter = languageUri; + } else { + params.languageUri = languageUri; + } + } return request({ - url: urlUtil.route('translations', 'Translation', 'tao', { id }), + url: urlUtil.route('translations', 'Translation', 'tao', params), method: 'GET', noToken: true }) From b4f4f7aecd9e5c9ba48da6023302aff475995b2a Mon Sep 17 00:00:00 2001 From: jsconan Date: Thu, 24 Oct 2024 17:04:52 +0200 Subject: [PATCH 3/3] fix: parameters order mismatch in the translation helper --- views/js/services/translation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/js/services/translation.js b/views/js/services/translation.js index 7e3f7745aa..77d8ce7eae 100644 --- a/views/js/services/translation.js +++ b/views/js/services/translation.js @@ -291,7 +291,7 @@ define(['i18n', 'core/request', 'util/url'], function (__, request, urlUtil) { * @param {function} [filter] - A filter function for the translations. When not provided through the languageUri parameter. * @returns {Promise} */ - getTranslations(id, filter, languageUri) { + getTranslations(id, languageUri, filter) { if (Array.isArray(id)) { id = id.join(','); }