diff --git a/crowdin_api/api_resources/ai/resource.py b/crowdin_api/api_resources/ai/resource.py index 38678c2..14184d8 100644 --- a/crowdin_api/api_resources/ai/resource.py +++ b/crowdin_api/api_resources/ai/resource.py @@ -1315,3 +1315,29 @@ def list_supported_ai_provider_models( path="ai/providers/supported-models", params=params ) + + 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, + ) diff --git a/crowdin_api/api_resources/ai/tests/test_ai_resources.py b/crowdin_api/api_resources/ai/tests/test_ai_resources.py index 4002abd..e69bcaf 100644 --- a/crowdin_api/api_resources/ai/tests/test_ai_resources.py +++ b/crowdin_api/api_resources/ai/tests/test_ai_resources.py @@ -2104,3 +2104,25 @@ def test_list_supported_ai_provider_models(self, m_request, in_params, request_p path="ai/providers/supported-models", params=request_params ) + + @mock.patch("crowdin_api.requester.APIRequester.request") + def test_ai_translate_strings(self, m_request, base_absolut_url): + m_request.return_value = "response" + + resource = self.get_resource(base_absolut_url) + assert resource.ai_translate_strings( + aiId=1, + projectId=42, + targetLanguageIds=["uk", "fr"], + stringIds=[101, 102], + ) == "response" + + m_request.assert_called_once_with( + method="post", + path="ai/1/translate-strings", + post_data={ + "projectId": 42, + "targetLanguageIds": ["uk", "fr"], + "stringIds": [101, 102], + }, + )