Skip to content

Commit f1cfdef

Browse files
biplopghimirecmukdaoZhuHengjinaditi-agnipre-commit-ci[bot]
authored
feat(api): API endpoint for language-specific project translation download (#17204)
* added the multi download functionality with tests * Add regex filter for project language file downloads Introduces a 'filter' query parameter to the project language file API endpoint, allowing users to filter components by slug using a regular expression. Includes validation for invalid regex patterns and corresponding tests to ensure correct filtering and error handling. * added test for no translations for requested language * Draft One of API doc * Initial draft of api documentation * Initial commit to test * Drafted API documentation in api.rst * Updated changes.rst * Added new versionchanged number in api.rst * Updated api.rst documentation to reflect error codes * Updated changes.rst to reflect that API endpoint generates a ZIP file * final touchups to api docs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed typo * chore(docs): update OpenAPI schema * Update docs/api.rst Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update weblate/api/views.py Co-authored-by: Michal Čihař <michal@cihar.com> * Update docs/api.rst Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update docs/api.rst Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update docs/api.rst Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update docs/changes.rst Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor component filtering in API views and tests for improved clarity and functionality * created helper attach_component and updated filter_invalid test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * removed reimport of data_dir * fix: write file bytes from the fixture path instead of string path * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Replaced old api.rst file * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update docs/api.rst Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Addressing Co-Pilot comment about adding 200 OK note in api.rst * Updated syntax of error and success notes in api.rst * Small fixes to error and success notes in api.rst * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added an explicit OpenAPI parameter definition for language_code * updated release notes to point to correct endpoint * redone zip contents and path filter test; added new unsupported file format test * chore(docs): update OpenAPI schema * Update changelog * Apply suggestion from @nijel --------- Co-authored-by: Edison Dao <164945428+cmukdao@users.noreply.github.com> Co-authored-by: ZhuHengjin <HengjinZhu@iCloud.com> Co-authored-by: Edison <kdao@andrew.cmu.edu> Co-authored-by: aditi-agni <aditiagni1@gmail.com> Co-authored-by: aditi <152739362+aditi-agni@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Michal Čihař <michal@cihar.com> Co-authored-by: Edison <edictory@LAPTOP-8DAPF4PK> Co-authored-by: Michal Čihař <michal@weblate.org>
1 parent 87f612b commit f1cfdef

File tree

5 files changed

+581
-2
lines changed

5 files changed

+581
-2
lines changed

docs/api.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,28 @@ Projects
13291329
:form string service: Service name
13301330
:form string configuration: Service configuration in JSON
13311331

1332+
.. http:get:: /api/projects/(string:project)/languages/(string:language_code)/file/
1333+
1334+
.. versionchanged:: 5.15.1
1335+
1336+
Added ability to download ZIP file of all components translations in a project for 1 specific language.
1337+
1338+
Download a ZIP file of all translation files for a specified ``language_code`` across all components for a given ``project`` rather than downloading individual translated files and manually zipping them, with the archive named `{project-slug}-{language-code}.zip` and organized by component paths (e.g., `component-slug/po/lang.po`).
1339+
1340+
:param project: Project URL slug
1341+
:type project: string
1342+
:param language_code: Language code
1343+
:type language_code: string
1344+
:query string filter: Optional case-insensitive substring to filter components by slug (e.g., ``?filter=core`` will match components with 'core' anywhere in their slug); only components whose slugs contain the substring will be included in the download.
1345+
:query string format: The archive format to use; If not specified, defaults to ``zip``; Supported formats: ``zip`` and ``zip:CONVERSION`` where ``CONVERSION`` is one of converters listed at :ref:`download`.
1346+
1347+
.. note::
1348+
1349+
Possible responses:
1350+
1351+
- ``200 OK`` with the ZIP file of translations for the specified language across all components in the project. If no components have translations for the specified language, an empty ZIP file will be returned.
1352+
- ``403 Forbidden`` if the user does not have permission to the project.
1353+
- ``404 Not Found`` if the project slug does not exist.
13321354

13331355
Components
13341356
++++++++++

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Weblate 5.15.1
55

66
.. rubric:: New features
77

8+
* Added :http:get:`/api/projects/(string:project)/languages/(string:language_code)/file/` to download a ZIP file of all component translations of a project for a specified language.
9+
810
.. rubric:: Improvements
911

1012
* Updated list of OpenAI models.

docs/specs/openapi.yaml

Lines changed: 288 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)