-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
API: API endpoint for language-specific project translation download #17204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: API endpoint for language-specific project translation download #17204
Conversation
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.
merge from the main, sync changes
Adding Documentation for API Endpoint Download Zip
for more information, see https://pre-commit.ci
weblate/api/views.py
Outdated
| raise PermissionDenied | ||
|
|
||
| components = instance.component_set.filter_access(request.user) | ||
| component_filter = request.query_params.get("filter") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really use https://www.django-rest-framework.org/api-guide/filtering/
There was a problem hiding this 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_filemethod toProjectViewSetthat 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) |
|
|
||
|
|
||
|
|
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
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.
docs/api.rst
Outdated
| .. 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`). |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
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:
.. http:get::directive- Blank line
- Description text (indented 4 spaces)
- Blank line
.. versionadded:: 5.15(indented 4 spaces, and should beversionaddednotversionchangedsince this is a new endpoint)- 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).
| .. 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 |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Michal Čihař <[email protected]>
There was a problem hiding this 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.
Co-authored-by: Copilot <[email protected]>
for more information, see https://pre-commit.ci
|
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! |
|
Scheduled for merge, thanks for your contribution! |
Proposed Changes:
Fix: #16811
Checklist:
weblate/api/tests.pyto ensure new API endpoint behaves as expectedSummary:
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.rstanddocs/changes.rst