Skip to content

Commit e698cd5

Browse files
authored
feat: add support for AI File Translation methods (#245)
1 parent 9bfe556 commit e698cd5

3 files changed

Lines changed: 395 additions & 1 deletion

File tree

crowdin_api/api_resources/ai/resource.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
GenerateAiPromptCompletionRequest,
1717
GenerateAiReportRequest,
1818
EditAiSettingsPatch,
19+
AiFileTranslationRequest,
1920
)
2021
from crowdin_api.sorting import Sorting
2122
from crowdin_api.utils import convert_enum_collection_to_string_if_exists, convert_enum_to_string_if_exists
@@ -684,6 +685,99 @@ def list_supported_ai_provider_models(
684685
params=params
685686
)
686687

688+
def get_ai_file_translations_path(
689+
self, user_id: int, job_identifier: Optional[str] = None
690+
):
691+
if job_identifier is not None:
692+
return f"users/{user_id}/ai/file-translations/{job_identifier}"
693+
return f"users/{user_id}/ai/file-translations"
694+
695+
def create_ai_file_translation(
696+
self,
697+
user_id: int,
698+
request_data: AiFileTranslationRequest,
699+
):
700+
"""
701+
AI File Translations
702+
703+
Link to documentation:
704+
https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.post
705+
"""
706+
707+
return self.requester.request(
708+
method="post",
709+
path=self.get_ai_file_translations_path(user_id),
710+
request_data=request_data,
711+
)
712+
713+
def get_ai_file_translation_status(
714+
self,
715+
user_id: int,
716+
job_identifier: str,
717+
):
718+
"""
719+
Get File Translations Status
720+
721+
Link to documentation:
722+
https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.get
723+
"""
724+
725+
return self.requester.request(
726+
method="get",
727+
path=self.get_ai_file_translations_path(user_id, job_identifier),
728+
)
729+
730+
def cancel_ai_file_translation(
731+
self,
732+
user_id: int,
733+
job_identifier: str,
734+
):
735+
"""
736+
Cancel File Translations
737+
738+
Link to documentation:
739+
https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.delete
740+
"""
741+
742+
return self.requester.request(
743+
method="delete",
744+
path=self.get_ai_file_translations_path(user_id, job_identifier),
745+
)
746+
747+
def download_ai_file_translation(
748+
self,
749+
user_id: int,
750+
job_identifier: str,
751+
):
752+
"""
753+
Download Translated File
754+
755+
Link to documentation:
756+
https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.download
757+
"""
758+
759+
return self.requester.request(
760+
method="get",
761+
path=self.get_ai_file_translations_path(user_id, job_identifier) + "/download",
762+
)
763+
764+
def download_ai_file_translation_strings(
765+
self,
766+
user_id: int,
767+
job_identifier: str,
768+
):
769+
"""
770+
Download Translated File Strings
771+
772+
Link to documentation:
773+
https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.file-translations.download-strings
774+
"""
775+
776+
return self.requester.request(
777+
method="get",
778+
path=self.get_ai_file_translations_path(user_id, job_identifier) + "/translations",
779+
)
780+
687781

688782
class EnterpriseAIResource(BaseResource):
689783
"""
@@ -1315,3 +1409,91 @@ def list_supported_ai_provider_models(
13151409
path="ai/providers/supported-models",
13161410
params=params
13171411
)
1412+
1413+
def get_ai_file_translations_path(
1414+
self, job_identifier: Optional[str] = None
1415+
):
1416+
if job_identifier is not None:
1417+
return f"ai/file-translations/{job_identifier}"
1418+
return "ai/file-translations"
1419+
1420+
def create_ai_file_translation(
1421+
self,
1422+
request_data: AiFileTranslationRequest,
1423+
):
1424+
"""
1425+
AI File Translations
1426+
1427+
Link to documentation:
1428+
https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.post
1429+
"""
1430+
1431+
return self.requester.request(
1432+
method="post",
1433+
path=self.get_ai_file_translations_path(),
1434+
request_data=request_data,
1435+
)
1436+
1437+
def get_ai_file_translation_status(
1438+
self,
1439+
job_identifier: str,
1440+
):
1441+
"""
1442+
Get File Translations Status
1443+
1444+
Link to documentation:
1445+
https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.get
1446+
"""
1447+
1448+
return self.requester.request(
1449+
method="get",
1450+
path=self.get_ai_file_translations_path(job_identifier),
1451+
)
1452+
1453+
def cancel_ai_file_translation(
1454+
self,
1455+
job_identifier: str,
1456+
):
1457+
"""
1458+
Cancel File Translations
1459+
1460+
Link to documentation:
1461+
https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.delete
1462+
"""
1463+
1464+
return self.requester.request(
1465+
method="delete",
1466+
path=self.get_ai_file_translations_path(job_identifier),
1467+
)
1468+
1469+
def download_ai_file_translation(
1470+
self,
1471+
job_identifier: str,
1472+
):
1473+
"""
1474+
Download Translated File
1475+
1476+
Link to documentation:
1477+
https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.download
1478+
"""
1479+
1480+
return self.requester.request(
1481+
method="get",
1482+
path=self.get_ai_file_translations_path(job_identifier) + "/download",
1483+
)
1484+
1485+
def download_ai_file_translation_strings(
1486+
self,
1487+
job_identifier: str,
1488+
):
1489+
"""
1490+
Download File Strings
1491+
1492+
Link to documentation:
1493+
https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI/operation/api.ai.file-translations.download-strings
1494+
"""
1495+
1496+
return self.requester.request(
1497+
method="get",
1498+
path=self.get_ai_file_translations_path(job_identifier) + "/translations",
1499+
)

0 commit comments

Comments
 (0)