Skip to content

Commit

Permalink
feat: add addToTm parameter support for Upload Translation API (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
imprvhub authored Nov 27, 2024
1 parent bd7a021 commit 1fa4b5b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
20 changes: 12 additions & 8 deletions crowdin_api/api_resources/translations/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from crowdin_api.api_resources.translations.types import (
FallbackLanguages,
EditPreTranslationScheme,
UploadTranslationRequest,
)
from crowdin_api.api_resources.translations.enums import (
CharTransformation,
Expand Down Expand Up @@ -325,26 +326,29 @@ def upload_translation(
importEqSuggestions: Optional[bool] = None,
autoApproveImported: Optional[bool] = None,
translateHidden: Optional[bool] = None,
addToTm: Optional[bool] = None,
):
"""
Upload Translations.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.translations.postOnLanguage
"""

projectId = projectId or self.get_project_id()

request_data: UploadTranslationRequest = {
"storageId": storageId,
"fileId": fileId,
"importEqSuggestions": importEqSuggestions,
"autoApproveImported": autoApproveImported,
"translateHidden": translateHidden,
"addToTm": addToTm,
}

return self.requester.request(
method="post",
path=f"projects/{projectId}/translations/{languageId}",
request_data={
"storageId": storageId,
"fileId": fileId,
"importEqSuggestions": importEqSuggestions,
"autoApproveImported": autoApproveImported,
"translateHidden": translateHidden,
},
request_data=request_data,
)

def download_project_translations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def test_build_pseudo_project_translation(
"importEqSuggestions": None,
"autoApproveImported": None,
"translateHidden": None,
"addToTm": None,
},
),
(
Expand All @@ -331,13 +332,63 @@ def test_build_pseudo_project_translation(
"importEqSuggestions": False,
"autoApproveImported": False,
"translateHidden": False,
"addToTm": False,
},
{
"storageId": 1,
"fileId": 2,
"importEqSuggestions": False,
"autoApproveImported": False,
"translateHidden": False,
"addToTm": False,
},
),
(
{
"storageId": 1,
"fileId": 2,
"importEqSuggestions": True,
"autoApproveImported": True,
"translateHidden": True,
"addToTm": True,
},
{
"storageId": 1,
"fileId": 2,
"importEqSuggestions": True,
"autoApproveImported": True,
"translateHidden": True,
"addToTm": True,
},
),
(
{
"storageId": 1,
"fileId": 2,
"addToTm": False,
},
{
"storageId": 1,
"fileId": 2,
"importEqSuggestions": None,
"autoApproveImported": None,
"translateHidden": None,
"addToTm": False,
},
),
(
{
"storageId": 1,
"fileId": 2,
"addToTm": True,
},
{
"storageId": 1,
"fileId": 2,
"importEqSuggestions": None,
"autoApproveImported": None,
"translateHidden": None,
"addToTm": True,
},
),
),
Expand Down
13 changes: 10 additions & 3 deletions crowdin_api/api_resources/translations/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Iterable

from typing import Iterable, Optional
from crowdin_api.typing import TypedDict

from crowdin_api.api_resources.translations.enums import PreTranslationEditOperation


Expand All @@ -13,3 +11,12 @@ class EditPreTranslationScheme(TypedDict):
op: PreTranslationEditOperation
path: str
value: str


class UploadTranslationRequest(TypedDict):
storageId: int
fileId: int
importEqSuggestions: Optional[bool]
autoApproveImported: Optional[bool]
translateHidden: Optional[bool]
addToTm: Optional[bool]

0 comments on commit 1fa4b5b

Please sign in to comment.