diff --git a/crowdin_api/api_resources/translations/enums.py b/crowdin_api/api_resources/translations/enums.py index ee4c7e8..e817ba6 100644 --- a/crowdin_api/api_resources/translations/enums.py +++ b/crowdin_api/api_resources/translations/enums.py @@ -19,3 +19,8 @@ class CharTransformation(Enum): EUROPEAN = "european" ARABIC = "arabic" CYRILLIC = "cyrillic" + + +class PreTranslationEditOperation(Enum): + REPLACE = "replace" + TEST = "test" diff --git a/crowdin_api/api_resources/translations/resource.py b/crowdin_api/api_resources/translations/resource.py index 26ea76c..347b10a 100644 --- a/crowdin_api/api_resources/translations/resource.py +++ b/crowdin_api/api_resources/translations/resource.py @@ -2,7 +2,10 @@ from crowdin_api.api_resources.abstract.resources import BaseResource from crowdin_api.api_resources.enums import ExportProjectTranslationFormat -from crowdin_api.api_resources.translations.types import FallbackLanguages +from crowdin_api.api_resources.translations.types import ( + FallbackLanguages, + EditPreTranslationScheme, +) from crowdin_api.api_resources.translations.enums import ( CharTransformation, PreTranslationApplyMethod, @@ -48,6 +51,29 @@ def pre_translation_status( path=f"projects/{projectId}/pre-translations/{preTranslationId}", ) + def list_pre_translations( + self, + projectId: Optional[int] = None, + page: Optional[int] = None, + offset: Optional[int] = None, + limit: Optional[int] = None, + ): + """ + List Pre-Translations + + Link to documentation: + https://support.crowdin.com/developer/api/v2/#tag/Translations/operation/api.projects.pre-translations.getMany + """ + projectId = projectId or self.get_project_id() + + params = self.get_page_params(page=page, offset=offset, limit=limit) + + return self.requester.request( + method="get", + path=f"projects/{projectId}/pre-translations", + params=params, + ) + def apply_pre_translation( self, languageIds: Iterable[str], @@ -102,6 +128,26 @@ def apply_pre_translation( }, ) + def edit_pre_translation( + self, + preTranslationId: str, + data: Iterable[EditPreTranslationScheme], + projectId: Optional[int] = None, + ): + """ + Edit Pre-Translation + + Link to documentation: + https://support.crowdin.com/developer/api/v2/#tag/Translations/operation/api.projects.pre-translations.patch + """ + projectId = projectId or self.get_project_id() + + return self.requester.request( + method="patch", + path=f"projects/{projectId}/pre-translations/{preTranslationId}", + request_data=data, + ) + def build_project_directory_translation( self, directoryId: int, diff --git a/crowdin_api/api_resources/translations/tests/test_translations_resources.py b/crowdin_api/api_resources/translations/tests/test_translations_resources.py index 1e44965..4838bad 100644 --- a/crowdin_api/api_resources/translations/tests/test_translations_resources.py +++ b/crowdin_api/api_resources/translations/tests/test_translations_resources.py @@ -6,6 +6,7 @@ CharTransformation, PreTranslationApplyMethod, PreTranslationAutoApproveOption, + PreTranslationEditOperation, ) from crowdin_api.api_resources.translations.resource import TranslationsResource from crowdin_api.requester import APIRequester @@ -35,6 +36,19 @@ def test_list_project_branches(self, m_request, base_absolut_url): path="projects/1/pre-translations/2", ) + @mock.patch("crowdin_api.requester.APIRequester.request") + def test_list_pre_translations(self, m_request, base_absolut_url): + m_request.return_value = "response" + + resource = self.get_resource(base_absolut_url) + params = resource.get_page_params() + assert resource.list_pre_translations(projectId=1) == "response" + m_request.assert_called_once_with( + method="get", + path="projects/1/pre-translations", + params=params, + ) + @pytest.mark.parametrize( "in_params, request_data", ( @@ -105,6 +119,26 @@ def test_apply_pre_translation(self, m_request, in_params, request_data, base_ab path="projects/1/pre-translations", ) + @mock.patch("crowdin_api.requester.APIRequester.request") + def test_edit_bundle(self, m_request, base_absolut_url): + m_request.return_value = "response" + + data = [ + { + "value": "value", + "op": PreTranslationEditOperation.REPLACE, + "path": "/status", + } + ] + + resource = self.get_resource(base_absolut_url) + assert resource.edit_pre_translation(projectId=1, preTranslationId="pre-id", data=data) == "response" + m_request.assert_called_once_with( + method="patch", + path="projects/1/pre-translations/pre-id", + request_data=data, + ) + @pytest.mark.parametrize( "in_params, request_data, headers", ( diff --git a/crowdin_api/api_resources/translations/types.py b/crowdin_api/api_resources/translations/types.py index eea6ee9..32d0182 100644 --- a/crowdin_api/api_resources/translations/types.py +++ b/crowdin_api/api_resources/translations/types.py @@ -2,6 +2,14 @@ from crowdin_api.typing import TypedDict +from crowdin_api.api_resources.translations.enums import PreTranslationEditOperation + class FallbackLanguages(TypedDict): languageId: Iterable[str] + + +class EditPreTranslationScheme(TypedDict): + op: PreTranslationEditOperation + path: str + value: str