Skip to content

feat(ai): add AI Translate Strings endpoint support#240

Draft
Tharun-bot wants to merge 4 commits intocrowdin:mainfrom
Tharun-bot:feat/ai-translate-strings
Draft

feat(ai): add AI Translate Strings endpoint support#240
Tharun-bot wants to merge 4 commits intocrowdin:mainfrom
Tharun-bot:feat/ai-translate-strings

Conversation

@Tharun-bot
Copy link

Description

Adds support for the AI Translate Strings endpoint introduced in the Crowdin API.

Changes

  • Added ai_translate_strings() method to the AI resource
  • Added unit tests for the new method

References

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.38%. Comparing base (993e783) to head (f54d06d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crowdin_api/api_resources/ai/resource.py 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
- Coverage   99.39%   99.38%   -0.01%     
==========================================
  Files         182      182              
  Lines        8433     8444      +11     
  Branches      187      188       +1     
==========================================
+ Hits         8381     8391      +10     
  Misses         36       36              
- Partials       16       17       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

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

Adds SDK support for invoking Crowdin’s “AI Translate Strings” endpoint from the AI resource layer, with a corresponding unit test to validate the outgoing request shape.

Changes:

  • Added ai_translate_strings() to the AI resource implementation.
  • Added a unit test covering the happy-path request for the new endpoint.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
crowdin_api/api_resources/ai/resource.py Introduces the new resource method that builds the request payload and calls the requester.
crowdin_api/api_resources/ai/tests/test_ai_resources.py Adds a test that asserts the HTTP method/path and payload passed to the requester.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return self.requester.request(
method="post",
path=f"ai/{aiId}/translate-strings",
post_data=post_data,
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

APIRequester.request() does not accept a post_data keyword (it only supports request_data), so this will raise a TypeError at runtime when the request is executed. Please rename post_data to request_data here (and keep the dict as-is).

Suggested change
post_data=post_data,
request_data=post_data,

Copilot uses AI. Check for mistakes.
AI Translate Strings.

Link to API docs:
https://developer.crowdin.com/api/v2/#tag/AI/operation/api.ai.translations.generate
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The documentation link in this docstring doesn’t match the endpoint being called (ai/{aiId}/translate-strings) and also uses the non-enterprise base URL. Please update it to the correct "AI Translate Strings" operation URL for this resource (enterprise vs. non-enterprise) so readers aren’t sent to the wrong API docs.

Suggested change
https://developer.crowdin.com/api/v2/#tag/AI/operation/api.ai.translations.generate
https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.translate-strings.enterprise.generate

Copilot uses AI. Check for mistakes.
Comment on lines +1323 to +1324
targetLanguageIds,
stringIds=None,
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

targetLanguageIds and stringIds are missing type hints here, while other resource methods typically annotate these as Optional[Iterable[str]] / Optional[Iterable[int]]. Adding explicit types (and making stringIds an Optional[...]) will improve IDE/autocomplete support and make the public API clearer.

Suggested change
targetLanguageIds,
stringIds=None,
targetLanguageIds: Optional[Iterable[str]],
stringIds: Optional[Iterable[int]] = None,

Copilot uses AI. Check for mistakes.
Comment on lines +1319 to +1342
def ai_translate_strings(
self,
aiId: int,
projectId: int,
targetLanguageIds,
stringIds=None,
):
"""
AI Translate Strings.

Link to API docs:
https://developer.crowdin.com/api/v2/#tag/AI/operation/api.ai.translations.generate
"""
post_data = {
"projectId": projectId,
"targetLanguageIds": targetLanguageIds,
}
if stringIds is not None:
post_data["stringIds"] = stringIds

return self.requester.request(
method="post",
path=f"ai/{aiId}/translate-strings",
post_data=post_data,
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

PR description says this adds support for the Crowdin API "AI Translate Strings" endpoint (linked under the non-enterprise docs), but the implementation is currently only on EnterpriseAIResource and uses the enterprise-style path (no users/{userId} prefix). Please confirm whether this endpoint is enterprise-only; if it’s part of the standard API as well, the method (and tests) likely need to be added to AIResource with the correct path/params, or the PR description should be updated to reflect enterprise scope.

Copilot uses AI. Check for mistakes.
Comment on lines +2120 to +2128
m_request.assert_called_once_with(
method="post",
path="ai/1/translate-strings",
post_data={
"projectId": 42,
"targetLanguageIds": ["uk", "fr"],
"stringIds": [101, 102],
},
)
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

This test asserts the request is called with post_data=..., but APIRequester.request() uses request_data for payloads. Once the implementation is fixed to use request_data, the test should be updated accordingly so it matches the real requester API.

Copilot uses AI. Check for mistakes.
Comment on lines +2112 to +2118
resource = self.get_resource(base_absolut_url)
assert resource.ai_translate_strings(
aiId=1,
projectId=42,
targetLanguageIds=["uk", "fr"],
stringIds=[101, 102],
) == "response"
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The implementation conditionally includes stringIds only when provided, but the tests only cover the case where stringIds is set. Consider adding a second assertion covering the stringIds=None/omitted case to lock in the payload behavior for that branch.

Copilot uses AI. Check for mistakes.
@andrii-bodnar
Copy link
Member

@Tharun-bot thanks for the contribution! Please address the comments above

@andrii-bodnar andrii-bodnar marked this pull request as draft March 3, 2026 15:25
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.

Add support for AI Translate Strings method

4 participants