From e402cff191efeaab6198fc51a64eae970a6fae71 Mon Sep 17 00:00:00 2001 From: sathishselvam1 Date: Tue, 15 Sep 2026 17:36:31 +0100 Subject: [PATCH] feat(translations): add directoryIds to Apply Pre-Translation Add DirectoryIds to ApplyPreTranslationRequest and PreTranslateAttributes so whole directories can be pre-translated. BranchIds already existed. Closes #405 --- .../ApplyPreTranslationRequest.cs | 3 ++ .../Translations/PreTranslateAttributes.cs | 3 ++ .../Resources/Translations.Designer.cs | 12 ++++++ .../Resources/Translations.resx | 35 ++++++++++++++++++ .../Translations/TranslationsApiTests.cs | 37 +++++++++++++++++++ 5 files changed, 90 insertions(+) diff --git a/src/Crowdin.Api/Translations/ApplyPreTranslationRequest.cs b/src/Crowdin.Api/Translations/ApplyPreTranslationRequest.cs index 058a3804..e1139dea 100644 --- a/src/Crowdin.Api/Translations/ApplyPreTranslationRequest.cs +++ b/src/Crowdin.Api/Translations/ApplyPreTranslationRequest.cs @@ -19,6 +19,9 @@ public class ApplyPreTranslationRequest [JsonProperty("branchIds")] public ICollection? BranchIds { get; set; } + [JsonProperty("directoryIds")] + public ICollection? DirectoryIds { get; set; } + [JsonProperty("fileIds")] public ICollection? FileIds { get; set; } diff --git a/src/Crowdin.Api/Translations/PreTranslateAttributes.cs b/src/Crowdin.Api/Translations/PreTranslateAttributes.cs index 880a0f66..d5839977 100644 --- a/src/Crowdin.Api/Translations/PreTranslateAttributes.cs +++ b/src/Crowdin.Api/Translations/PreTranslateAttributes.cs @@ -16,6 +16,9 @@ public class PreTranslateAttributes [JsonProperty("branchIds")] public string[] BranchIds { get; set; } = Array.Empty(); + [JsonProperty("directoryIds")] + public long[]? DirectoryIds { get; set; } + [JsonProperty("fileIds")] public long[]? FileIds { get; set; } diff --git a/tests/Crowdin.Api.UnitTesting/Resources/Translations.Designer.cs b/tests/Crowdin.Api.UnitTesting/Resources/Translations.Designer.cs index 84b7b1a1..d764031f 100644 --- a/tests/Crowdin.Api.UnitTesting/Resources/Translations.Designer.cs +++ b/tests/Crowdin.Api.UnitTesting/Resources/Translations.Designer.cs @@ -141,6 +141,18 @@ internal static string ApplyPreTranslation_Response_WithNewFields { } } + internal static string ApplyPreTranslation_Request_WithDirectoryIds { + get { + return ResourceManager.GetString("ApplyPreTranslation_Request_WithDirectoryIds", resourceCulture); + } + } + + internal static string ApplyPreTranslation_Response_WithDirectoryIds { + get { + return ResourceManager.GetString("ApplyPreTranslation_Response_WithDirectoryIds", resourceCulture); + } + } + internal static string RevalidateQaChecks_Request { get { return ResourceManager.GetString("RevalidateQaChecks_Request", resourceCulture); diff --git a/tests/Crowdin.Api.UnitTesting/Resources/Translations.resx b/tests/Crowdin.Api.UnitTesting/Resources/Translations.resx index 5137e8e1..2f22d897 100644 --- a/tests/Crowdin.Api.UnitTesting/Resources/Translations.resx +++ b/tests/Crowdin.Api.UnitTesting/Resources/Translations.resx @@ -495,6 +495,41 @@ "startedAt": "2019-08-24T14:15:22Z", "finishedAt": "2019-08-24T14:15:22Z" } +} + + + { + "languageIds": ["uk"], + "branchIds": [5], + "directoryIds": [10, 11], + "labelIds": [], + "excludeLabelIds": [] +} + + + { + "data": { + "identifier": "9e7de270-4f83-41cb-b606-2f90631f26e2", + "status": "created", + "progress": 0, + "attributes": { + "languageIds": ["uk"], + "branchIds": [5], + "directoryIds": [10, 11], + "method": "tm", + "autoApproveOption": "none", + "duplicateTranslations": false, + "skipApprovedTranslations": false, + "translateUntranslatedOnly": false, + "translateWithPerfectMatchOnly": false, + "labelIds": [], + "excludeLabelIds": [] + }, + "createdAt": "2019-09-20T14:05:50+00:00", + "updatedAt": "2019-09-20T14:05:50+00:00", + "startedAt": "2019-08-24T14:15:22Z", + "finishedAt": "2019-08-24T14:15:22Z" + } } diff --git a/tests/Crowdin.Api.UnitTesting/Tests/Translations/TranslationsApiTests.cs b/tests/Crowdin.Api.UnitTesting/Tests/Translations/TranslationsApiTests.cs index 014214bc..c1c1088a 100644 --- a/tests/Crowdin.Api.UnitTesting/Tests/Translations/TranslationsApiTests.cs +++ b/tests/Crowdin.Api.UnitTesting/Tests/Translations/TranslationsApiTests.cs @@ -209,6 +209,43 @@ public async Task ApplyPreTranslation_WithNewFields() Assert.True(attributes.ResetApprovalStatus); } + [Fact] + public async Task ApplyPreTranslation_WithDirectoryIds() + { + const int projectId = 1; + + var body = new ApplyPreTranslationRequest + { + LanguageIds = new HashSet { "uk" }, + BranchIds = new HashSet { 5 }, + DirectoryIds = new HashSet { 10, 11 } + }; + + string actualRequestJson = JsonConvert.SerializeObject(body, JsonSettings); + string expectedRequestJson = TestUtils.CompactJson(Resources.Translations.ApplyPreTranslation_Request_WithDirectoryIds); + Assert.Equal(expectedRequestJson, actualRequestJson); + + var mockClient = new Mock(); + + mockClient + .Setup(client => client.SendPostRequest( + $"/projects/{projectId}/pre-translations", body, null)) + .ReturnsAsync(new CrowdinApiResult + { + StatusCode = HttpStatusCode.Accepted, + JsonObject = JObject.Parse(Resources.Translations.ApplyPreTranslation_Response_WithDirectoryIds) + }); + + var executor = new TranslationsApiExecutor(mockClient.Object, TestUtils.CreateJsonParser()); + PreTranslation preTranslation = await executor.ApplyPreTranslation(projectId, body); + + Assert.NotNull(preTranslation); + PreTranslateAttributes? attributes = preTranslation.Attributes; + Assert.NotNull(attributes); + Assert.Equal(new long[] { 10, 11 }, attributes.DirectoryIds); + Assert.Equal(new[] { "5" }, attributes.BranchIds); + } + [Fact] public async Task UploadTranslations() {