Skip to content

Commit

Permalink
feat(translations): add List and Edit PreTranslation APIs (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
innomaxx authored Nov 1, 2024
1 parent f1c2df1 commit 36988cb
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 131 deletions.
21 changes: 21 additions & 0 deletions src/Crowdin.Api/Translations/PreTranslationPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

using System.ComponentModel;
using JetBrains.Annotations;
using Newtonsoft.Json;

namespace Crowdin.Api.Translations
{
[PublicAPI]
public class PreTranslationPatch : PatchEntry
{
[JsonProperty("path")]
public PreTranslationPatchPath Path { get; set; }
}

[PublicAPI]
public enum PreTranslationPatchPath
{
[Description("/status")]
Status
}
}
36 changes: 36 additions & 0 deletions src/Crowdin.Api/Translations/TranslationsApiExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,42 @@ public TranslationsApiExecutor(ICrowdinApiClient apiClient, IJsonParser jsonPars
_jsonParser = jsonParser;
}

/// <summary>
/// List Pre-Translations. Documentation:
/// <a href="https://support.crowdin.com/developer/api/v2/#tag/Translations/operation/api.projects.pre-translations.getMany">Crowdin API</a>
/// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/Translations/operation/api.projects.pre-translations.getMany">Crowdin String Based API</a>
/// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/Translations/operation/api.projects.pre-translations.getMany">Crowdin Enterprise API</a>
/// </summary>
[PublicAPI]
public async Task<ResponseList<PreTranslation>> ListPreTranslations(
int projectId,
int limit = 25,
int offset = 0)
{
var url = $"/projects/{projectId}/pre-translations";

IDictionary<string, string> queryParams = Utils.CreateQueryParamsFromPaging(limit, offset);
CrowdinApiResult result = await _apiClient.SendGetRequest(url, queryParams);
return _jsonParser.ParseResponseList<PreTranslation>(result.JsonObject);
}

/// <summary>
/// Edit Pre-Translation. Documentation:
/// <a href="https://support.crowdin.com/developer/api/v2/#tag/Translations/operation/api.projects.pre-translations.patch">Crowdin API</a>
/// <a href="https://support.crowdin.com/developer/api/v2/string-based/#tag/Translations/operation/api.projects.pre-translations.patch">Crowdin String Based API</a>
/// <a href="https://support.crowdin.com/developer/enterprise/api/v2/#tag/Translations/operation/api.projects.pre-translations.patch">Crowdin Enterprise API</a>
/// </summary>
[PublicAPI]
public async Task<PreTranslation> EditPreTranslation(
int projectId,
string preTranslationId,
IEnumerable<PreTranslationPatch> patches)
{
var url = $"/projects/{projectId}/pre-translations/{preTranslationId}";
CrowdinApiResult result = await _apiClient.SendPatchRequest(url, patches);
return _jsonParser.ParseResponseObject<PreTranslation>(result.JsonObject);
}

/// <summary>
/// Get pre-translation status. Documentation:
/// <a href="https://support.crowdin.com/api/v2/#tag/Translations/paths/~1projects~1{projectId}~1pre-translations~1{preTranslationId}/get">Crowdin API</a>
Expand Down
165 changes: 34 additions & 131 deletions tests/Crowdin.Api.Tests/Core/Resources/Translations.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions tests/Crowdin.Api.Tests/Core/Resources/Translations.resx
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,73 @@
}
}</value>
</data>
<data name="CommonResources_PreTranslations_List" xml:space="preserve">
<value>{
"data": [
{
"identifier": "9e7de270-4f83-41cb-b606-2f90631f26e2",
"status": "created",
"progress": 90,
"attributes": {
"languageIds": [
"uk"
],
"fileIds": [
742
],
"method": "tm",
"autoApproveOption": "all",
"duplicateTranslations": true,
"skipApprovedTranslations": true,
"translateUntranslatedOnly": true,
"translateWithPerfectMatchOnly": true
},
"createdAt": "2019-09-20T14:05:50+00:00",
"updatedAt": "2019-09-20T14:05:50+00:00",
"startedAt": "2019-09-20T14:05:50+00:00",
"finishedAt": "2019-09-20T14:05:50+00:00"
}
],
"pagination": {
"offset": 0,
"limit": 25
}
}</value>
</data>
<data name="CommonResources_PreTranslation" xml:space="preserve">
<value>{
"data": {
"identifier": "9e7de270-4f83-41cb-b606-2f90631f26e2",
"status": "created",
"progress": 90,
"attributes": {
"languageIds": [
"uk"
],
"fileIds": [
742
],
"method": "tm",
"autoApproveOption": "all",
"duplicateTranslations": true,
"skipApprovedTranslations": true,
"translateUntranslatedOnly": true,
"translateWithPerfectMatchOnly": true
},
"createdAt": "2019-09-20T14:05:50+00:00",
"updatedAt": "2019-09-20T14:05:50+00:00",
"startedAt": "2019-09-20T14:05:50+00:00",
"finishedAt": "2019-09-20T14:05:50+00:00"
}
}</value>
</data>
<data name="EditPreTranslation_Request" xml:space="preserve">
<value>[
{
"path": "/status",
"op": "replace",
"value": "status"
}
]</value>
</data>
</root>
Loading

0 comments on commit 36988cb

Please sign in to comment.