Skip to content

Commit

Permalink
feat: String Export Settings API implementation (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmAximani0 authored Sep 15, 2023
1 parent 3b598b9 commit 6195f20
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
109 changes: 109 additions & 0 deletions crowdin_api/api_resources/projects/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
OtherFileFormatSettings,
SpecificFileFormatSettings,
ProjectFilePatchRequest,
AndroidStringsExporterSettings,
MacOSXStringsExporterSettings,
XliffStringsExporterSettings,
)


Expand Down Expand Up @@ -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},
)
14 changes: 13 additions & 1 deletion crowdin_api/api_resources/projects/types.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6195f20

Please sign in to comment.