From 6195f204328d49a62d92e2db2b6e334bc9e61d83 Mon Sep 17 00:00:00 2001 From: Om Aximani <75031769+OmAximani0@users.noreply.github.com> Date: Fri, 15 Sep 2023 20:53:05 +0530 Subject: [PATCH] feat: String Export Settings API implementation (#105) --- .../api_resources/projects/resource.py | 109 ++++++++++++++++++ crowdin_api/api_resources/projects/types.py | 14 ++- 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/crowdin_api/api_resources/projects/resource.py b/crowdin_api/api_resources/projects/resource.py index 930eb02..8394e62 100644 --- a/crowdin_api/api_resources/projects/resource.py +++ b/crowdin_api/api_resources/projects/resource.py @@ -20,6 +20,9 @@ OtherFileFormatSettings, SpecificFileFormatSettings, ProjectFilePatchRequest, + AndroidStringsExporterSettings, + MacOSXStringsExporterSettings, + XliffStringsExporterSettings, ) @@ -372,3 +375,109 @@ def edit_project_file( ), request_data=data, ) + + def get_strings_exporter_path( + self, + projectId: int, + systemStringExporterSettingsId: Optional[int] = None + ): + if systemStringExporterSettingsId is None: + return f"projects/{projectId}/strings-exporter-settings" + return f"projects/{projectId}/strings-exporter-settings/{systemStringExporterSettingsId}" + + def list_project_strings_exporter_settings( + self, + projectId: int, + ): + """ + List Project Strings Exporter Settings. + + Link to documetation: + https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.getMany + """ + return self._get_entire_data( + method="get", + path=self.get_strings_exporter_path(projectId=projectId), + ) + + def add_project_strings_exporter_settings( + self, + projectId: int, + format: str, + settings: Union[ + AndroidStringsExporterSettings, + MacOSXStringsExporterSettings, + XliffStringsExporterSettings, + ], + ): + """ + Add Project Strings Exporter Settings. + + Link to documetation: + https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.post + """ + return self.requester.request( + method="post", + path=self.get_strings_exporter_path(projectId=projectId), + request_data={"format": format, "settings": settings}, + ) + + def get_project_strings_exporter_settings( + self, projectId: int, systemStringExporterSettingsId: int + ): + """ + Get Project Strings Exporter Settings + + Link to documetation: + https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.get + """ + return self.requester.request( + method="get", + path=self.get_strings_exporter_path( + projectId=projectId, + systemStringExporterSettingsId=systemStringExporterSettingsId, + ), + ) + + def delete_project_strings_exporter_settings( + self, projectId: int, systemStringExporterSettingsId: int + ): + """ + Delete Project Strings Exporter Settings. + + Link to documetation: + https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.delete + """ + return self.requester.request( + method="delete", + path=self.get_strings_exporter_path( + projectId=projectId, + systemStringExporterSettingsId=systemStringExporterSettingsId, + ), + ) + + def edit_project_strings_exporter_settings( + self, + projectId: int, + systemStringExporterSettingsId: int, + format: str, + settings: Union[ + AndroidStringsExporterSettings, + MacOSXStringsExporterSettings, + XliffStringsExporterSettings, + ], + ): + """ + Edit Project Strings Exporter Settings. + + Link to documetation: + https://developer.crowdin.com/api/v2/#operation/api.projects.strings-exporter-settings.patch + """ + return self.requester.request( + method="patch", + path=self.get_strings_exporter_path( + projectId=projectId, + systemStringExporterSettingsId=systemStringExporterSettingsId + ), + request_data={"format": format, "settings": settings}, + ) diff --git a/crowdin_api/api_resources/projects/types.py b/crowdin_api/api_resources/projects/types.py index 1335bb9..29bd788 100644 --- a/crowdin_api/api_resources/projects/types.py +++ b/crowdin_api/api_resources/projects/types.py @@ -1,4 +1,4 @@ -from typing import Any, Iterable, List, Union +from typing import Any, Iterable, List, Union, Dict from crowdin_api.api_resources.enums import PatchOperation from crowdin_api.api_resources.projects.enums import ( @@ -98,6 +98,18 @@ class OtherFileFormatSettings(TypedDict): exportPattern: str +class AndroidStringsExporterSettings(TypedDict): + convertPlaceholders: bool + + +class MacOSXStringsExporterSettings(TypedDict): + convertPlaceholders: bool + + +class XliffStringsExporterSettings(TypedDict): + languagePairMapping: Dict[str, str] + + class ProjectFilePatchRequest(TypedDict): value: Union[str, List[str]] op: PatchOperation