Skip to content

Conversation

@biplopghimire
Copy link
Contributor

@biplopghimire biplopghimire commented Dec 6, 2025

Proposed Changes:

Fix: #16811

Checklist:

  • Lint & Unit tests pass locally & on GitHub
  • Added new tests in weblate/api/tests.py to ensure new API endpoint behaves as expected
  • Updated api.rst & changes.rst with documentation on the new behavior of his endpoint
  • Provided a summary of changes below

Summary:

This PR introduced a new API endpoint which allows for all component translation files for a given language within a specified project to be downloaded as a single ZIP file. The new endpoint is labelled as such:

GET /api/projects/(string:project)/(string:language)/file/

API Behavior:

Returns a ZIP file with the translated component files for a specified project & specified language.

Added benefit:

This new endpoint resolves the issue mentioned in #16811 as now users are able to download all component files (in a given project) for 1 language. The existing system only allows for all translations of a single component to be downloaded or all translations for an entire project to be downloaded. This new endpoint mitigates the issue of users having to individually download all component files for a singular language and manually ZIP them.

Implementation:

Added language_file method to ProjectViewSet class and provides a REST API endpoint to allow users to download translation files for all components in a project for a specific language.
Included RegEx validation ensure invalid expressions raise errors.
Included verification to ensure that only authenticated users who have download permission may proceed.
Returns a single ZIP file that contains all translation files for a specific language across 1 project named as {project-slug}-{language-code}.zip.
Updated test suite to test that API endpoint behaves as expected.
Added API documentation to document changes.

Documentation:

All changes have been documented in docs/api.rst and docs/changes.rst

raise PermissionDenied

components = instance.component_set.filter_access(request.user)
component_filter = request.query_params.get("filter")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new API endpoint that allows users to download all component translation files for a specific language within a project as a single ZIP file. The endpoint is exposed at GET /api/projects/(string:project)/(string:language)/file/ and addresses the issue where users previously had to download individual component files and manually combine them.

Key Changes

  • Added new language_file method to ProjectViewSet that filters translations by language and component
  • Included optional regex filtering for components via query parameter
  • Added comprehensive test coverage with 9 new test cases covering permissions, empty results, filtering, and content validation
  • Updated API and changelog documentation

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.

File Description
weblate/api/views.py Adds language_file action method with permission checks, regex validation, and component filtering support
weblate/api/tests.py Adds 9 comprehensive test cases covering permissions, filtering, edge cases, and content validation
docs/api.rst Documents the new endpoint with parameters, query options, and usage examples (has formatting issues)
docs/changes.rst Adds changelog entry for the new feature (has minor syntax issue)

Comment on lines 1349 to 1351



Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are excessive blank lines added here (3 blank lines). According to the rest of the file, only 1 or 2 blank lines should separate major sections. This should be reduced to maintain consistency with the rest of the documentation.

Suggested change

Copilot uses AI. Check for mistakes.
docs/api.rst Outdated
Comment on lines 1333 to 1337
.. versionchanged:: 5.15
Added ability to download ZIP file of all components translations in a project for 1 specific language.
Download a ZIP file () all translation files for a specified ``language`` 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`).
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation structure for this endpoint doesn't follow the established pattern in this file. Looking at similar endpoints (e.g., lines 1291-1307), the correct structure should be:

  1. .. http:get:: directive
  2. Blank line
  3. Description text (indented 4 spaces)
  4. Blank line
  5. .. versionadded:: 5.15 (indented 4 spaces, and should be versionadded not versionchanged since this is a new endpoint)
  6. Parameters and other documentation

Currently, the version directive appears immediately after the http directive (line 1333) and the description appears after it (line 1335), which is backwards. Additionally, the indentation is incorrect (5 and 8 spaces instead of 4).

Suggested change
.. versionchanged:: 5.15
Added ability to download ZIP file of all components translations in a project for 1 specific language.
Download a ZIP file () all translation files for a specified ``language`` 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`).
Download a ZIP file containing all translation files for a specified ``language`` across all components for a given ``project`` rather than downloading individual translated files and manually zipping them. The archive is named ``{project-slug}-{language-code}.zip`` and organized by component paths (e.g., ``component-slug/po/lang.po``).
.. versionadded:: 5.15

Copilot uses AI. Check for mistakes.
biplopghimire and others added 2 commits December 8, 2025 08:42
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Michal Čihař <[email protected]>
@nijel nijel added this to the 5.15.1 milestone Dec 15, 2025
@nijel nijel requested a review from Copilot December 15, 2025 11:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@cmukdao
Copy link
Contributor

cmukdao commented Dec 16, 2025

Hi @nijel, I would like to finalize this PR soon. Could you please re-run the CI checks when you have a chance? I am happy to make any changes right away. Thank you!

@nijel nijel modified the milestones: 5.15.1, 5.16 Dec 17, 2025
@nijel nijel enabled auto-merge (squash) December 17, 2025 17:43
@nijel nijel modified the milestones: 5.16, 5.15.1 Dec 17, 2025
@nijel nijel self-assigned this Dec 17, 2025
@nijel
Copy link
Member

nijel commented Dec 17, 2025

Scheduled for merge, thanks for your contribution!

@nijel nijel merged commit f1cfdef into WeblateOrg:main Dec 17, 2025
49 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API endpoint to download all components of a project for a specific language

5 participants