diff --git a/Apps.Crowdin/Actions/FileActions.cs b/Apps.Crowdin/Actions/FileActions.cs index d43ae5f..ff594f8 100644 --- a/Apps.Crowdin/Actions/FileActions.cs +++ b/Apps.Crowdin/Actions/FileActions.cs @@ -506,7 +506,7 @@ public async Task AddSpreadsheetFile( } } - var importOptions = new Apps.Crowdin.Models.Request.File.CustomFileImportOptions + var importOptions = new CustomFileImportOptions { FirstLineContainsHeader = input.FirstLineContainsHeader, ImportTranslations = input.ImportTranslations, diff --git a/Apps.Crowdin/Actions/SourceStringAction.cs b/Apps.Crowdin/Actions/SourceStringAction.cs index 27324a0..9466ab9 100644 --- a/Apps.Crowdin/Actions/SourceStringAction.cs +++ b/Apps.Crowdin/Actions/SourceStringAction.cs @@ -76,7 +76,7 @@ public async Task AddString([ActionParameter] AddSourceStrin Context = input.Context, IsHidden = input.IsHidden, MaxLength = input.MaxLength, - LabelIds = input.LabelIds?.Select(labelId => IntParser.Parse(labelId, nameof(labelId))!.Value).ToList() + LabelIds = input.LabelIds?.Select(labelId => LongParser.Parse(labelId, nameof(labelId))!.Value).ToList() }; var response = await ExceptionWrapper.ExecuteWithErrorHandling(async () => await SdkClient.SourceStrings .AddString(intProjectId!.Value, request)); diff --git a/Apps.Crowdin/Actions/TaskActions.cs b/Apps.Crowdin/Actions/TaskActions.cs index ff21cd7..d7949c4 100644 --- a/Apps.Crowdin/Actions/TaskActions.cs +++ b/Apps.Crowdin/Actions/TaskActions.cs @@ -132,7 +132,7 @@ public async Task AddTask( LanguageId = input.LanguageId, FileIds = input.FileIds.Select(fileId => { - if (!int.TryParse(fileId, out var parsedFileId)) + if (!long.TryParse(fileId, out var parsedFileId)) throw new PluginMisconfigurationException($"Invalid File ID: {fileId} must be a numeric value. Please check the input file ID"); return parsedFileId; }).ToList(), @@ -144,7 +144,7 @@ public async Task AddTask( SkipUntranslatedStrings = input.SkipUntranslatedStrings, LabelIds = input.LabelIds?.Select(labelId => { - if (!int.TryParse(labelId, out var parsedLabelId)) + if (!long.TryParse(labelId, out var parsedLabelId)) throw new PluginMisconfigurationException($"Invalid Label ID: {labelId} must be a numeric value. Please check the input label ID"); return parsedLabelId; }).ToList(), diff --git a/Apps.Crowdin/Actions/TranslationActions.cs b/Apps.Crowdin/Actions/TranslationActions.cs index 21bf79b..e98b04c 100644 --- a/Apps.Crowdin/Actions/TranslationActions.cs +++ b/Apps.Crowdin/Actions/TranslationActions.cs @@ -53,7 +53,7 @@ public async Task PreTranslate( var request = new ApplyPreTranslationRequest { LanguageIds = input.LanguageIds.ToList(), - FileIds = input.FileIds.Select(fileId => IntParser.Parse(fileId, nameof(fileId))!.Value).ToList(), + FileIds = input.FileIds.Select(fileId => LongParser.Parse(fileId, nameof(fileId))!.Value).ToList(), EngineId = intEngineId, Method = method, AiPromptId = input.aiPromptId is null ? null : IntParser.Parse(input.aiPromptId, nameof(input.aiPromptId)), @@ -176,20 +176,10 @@ public async Task AddStringTranslation([ActionParameter] AddN [Action("Add file translation", Description = "Add new file translation")] public async Task AddFileTranslation([ActionParameter] AddNewFileTranslationRequest input) { - if (string.IsNullOrEmpty(input.LanguageId)) - { - throw new PluginMisconfigurationException( - "Language ID cannot be null or empty. Please provide a valid language ID."); - } - - if (string.IsNullOrEmpty(input.ProjectId)) - { - throw new PluginMisconfigurationException( - "Project ID cannot be null or empty. Please provide a valid project ID."); - } + input.Validate(); int? fileID; - if (!String.IsNullOrEmpty(input.SourceFileId)) + if (!string.IsNullOrEmpty(input.SourceFileId)) { try { @@ -223,18 +213,19 @@ public async Task AddFileTranslation([ActionParameter] Ad await client.Storage.AddStorage(memoryStream, input.File.Name)); - var request = new UploadTranslationsRequest + var request = new ImportTranslationsRequest { StorageId = storageResult.Id, FileId = fileID, ImportEqSuggestions = input.ImportEqSuggestions, AutoApproveImported = input.AutoApproveImported, - TranslateHidden = input.TranslateHidden + TranslateHidden = input.TranslateHidden, + LanguageIds = [input.LanguageId] }; - var response = await ExceptionWrapper.ExecuteWithErrorHandling(async () => - await client.Translations.UploadTranslations(intProjectId!.Value, input.LanguageId, request)); - return new(response); + await client.Translations.ImportTranslations(intProjectId!.Value, request)); + + return new(response, intProjectId.ToString()); } [Action("Delete translation", Description = "Delete specific translation")] @@ -280,8 +271,6 @@ await client.Translations.BuildProjectFileTranslation(intProjectId!.Value, intFi return new(file); } - - [Action("Get language progress", Description = "Get translation progress for a specific language in the project")] public async Task GetLanguageProgress( [ActionParameter] ProjectRequest project, @@ -319,8 +308,6 @@ public async Task GetLanguageProgress( return new SimplifiedLanguageProgressResponseDto { Data = simplifiedList }; } - - [Action("Export project translation", Description = "Generate a download link for a project's translation in a specified language for the given files")] public async Task ExportProjectTranslation( [ActionParameter] ProjectRequest project, diff --git a/Apps.Crowdin/Actions/VendorActions.cs b/Apps.Crowdin/Actions/VendorActions.cs index 4966c84..55f24ec 100644 --- a/Apps.Crowdin/Actions/VendorActions.cs +++ b/Apps.Crowdin/Actions/VendorActions.cs @@ -1,4 +1,5 @@ using Apps.Crowdin.Invocables; +using Apps.Crowdin.Models.Entities; using Apps.Crowdin.Models.Request.Vendors; using Apps.Crowdin.Models.Response.Vendors; using Apps.Crowdin.Utils; diff --git a/Apps.Crowdin/Apps.Crowdin.csproj b/Apps.Crowdin/Apps.Crowdin.csproj index 284bdc7..d3b9846 100644 --- a/Apps.Crowdin/Apps.Crowdin.csproj +++ b/Apps.Crowdin/Apps.Crowdin.csproj @@ -5,7 +5,7 @@ enable Crowdin Cloud-based solution that streamlines localization management - 1.2.39 + 1.2.40 Apps.Crowdin @@ -13,7 +13,7 @@ - + all diff --git a/Apps.Crowdin/Models/Entities/FileTranslationEntity.cs b/Apps.Crowdin/Models/Entities/FileTranslationEntity.cs index 77906c2..849fdb7 100644 --- a/Apps.Crowdin/Models/Entities/FileTranslationEntity.cs +++ b/Apps.Crowdin/Models/Entities/FileTranslationEntity.cs @@ -3,25 +3,17 @@ namespace Apps.Crowdin.Models.Entities; -public class FileTranslationEntity +public class FileTranslationEntity(TranslationImportResponse fileTranslation, string? projectId) { [Display("File ID")] - public string FileId { get; set; } + public string FileId { get; set; } = fileTranslation.Attributes.FileId.ToString(); [Display("Language ID")] - public string LanguageId { get; set; } + public string LanguageId { get; set; } = fileTranslation.Attributes.LanguageIds.First().ToString(); [Display("Project ID")] - public string ProjectId { get; set; } + public string? ProjectId { get; set; } = projectId; [Display("Storage ID")] - public string StorageId { get; set; } - - public FileTranslationEntity(UploadTranslationsResponse fileTranslation) - { - FileId = fileTranslation.FileId.ToString(); - LanguageId = fileTranslation.LanguageId.ToString(); - ProjectId = fileTranslation.ProjectId.ToString(); - StorageId = fileTranslation.StorageId.ToString(); - } + public string StorageId { get; set; } = fileTranslation.Attributes.StorageId.ToString(); } \ No newline at end of file diff --git a/Apps.Crowdin/Models/Entities/VendorEntity.cs b/Apps.Crowdin/Models/Entities/VendorEntity.cs index 5f929f7..4fc03a7 100644 --- a/Apps.Crowdin/Models/Entities/VendorEntity.cs +++ b/Apps.Crowdin/Models/Entities/VendorEntity.cs @@ -1,25 +1,19 @@ using Crowdin.Api.Vendors; using Blackbird.Applications.Sdk.Common; -public class VendorEntity +namespace Apps.Crowdin.Models.Entities; + +public class VendorEntity(Vendor vendor) { [Display("Vendor ID")] - public int Id { get; set; } + public long Id { get; set; } = vendor.Id; [Display("Name")] - public string Name { get; set; } + public string Name { get; set; } = vendor.Name; [Display("Description")] - public string? Description { get; set; } + public string? Description { get; set; } = string.IsNullOrWhiteSpace(vendor.Description) ? null : vendor.Description; [Display("Status")] - public string Status { get; set; } - - public VendorEntity(Vendor vendor) - { - Id = vendor.Id; - Name = vendor.Name; - Description = string.IsNullOrWhiteSpace(vendor.Description) ? null : vendor.Description; - Status = vendor.Status.ToString(); - } + public string Status { get; set; } = vendor.Status.ToString(); } \ No newline at end of file diff --git a/Apps.Crowdin/Models/Request/File/AddNewFileRequest.cs b/Apps.Crowdin/Models/Request/File/AddNewFileRequest.cs index d2bfd53..a1574d8 100644 --- a/Apps.Crowdin/Models/Request/File/AddNewFileRequest.cs +++ b/Apps.Crowdin/Models/Request/File/AddNewFileRequest.cs @@ -22,5 +22,5 @@ public class AddNewFileRequest : ManageFileRequest public IEnumerable? ExcludedTargetLanguages { get; set; } [Display("Attach label IDs")] - public IEnumerable? AttachLabelIds { get; set; } + public IEnumerable? AttachLabelIds { get; set; } } \ No newline at end of file diff --git a/Apps.Crowdin/Models/Request/File/AddNewSpreadsheetFileRequest.cs b/Apps.Crowdin/Models/Request/File/AddNewSpreadsheetFileRequest.cs index 65407f6..7ba1963 100644 --- a/Apps.Crowdin/Models/Request/File/AddNewSpreadsheetFileRequest.cs +++ b/Apps.Crowdin/Models/Request/File/AddNewSpreadsheetFileRequest.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; using Apps.Crowdin.DataSourceHandlers; using Blackbird.Applications.Sdk.Common; using Blackbird.Applications.Sdk.Common.Dynamic; @@ -31,7 +26,7 @@ public class AddNewSpreadsheetFileRequest : ManageFileRequest public IEnumerable? ExcludedTargetLanguages { get; set; } [Display("Attach label IDs")] - public IEnumerable? AttachLabelIds { get; set; } + public IEnumerable? AttachLabelIds { get; set; } [Display("Content segmentation")] [Description("If enabled, Crowdin will split content into segments")] diff --git a/Apps.Crowdin/Models/Request/Translation/AddNewFileTranslationRequest.cs b/Apps.Crowdin/Models/Request/Translation/AddNewFileTranslationRequest.cs index ff170a7..a4a905f 100644 --- a/Apps.Crowdin/Models/Request/Translation/AddNewFileTranslationRequest.cs +++ b/Apps.Crowdin/Models/Request/Translation/AddNewFileTranslationRequest.cs @@ -1,19 +1,19 @@ using Apps.Crowdin.DataSourceHandlers; using Apps.Crowdin.Models.Request.Project; -using Blackbird.Applications.Sdk.Common.Dynamic; using Blackbird.Applications.Sdk.Common; +using Blackbird.Applications.Sdk.Common.Dynamic; +using Blackbird.Applications.Sdk.Common.Exceptions; using Blackbird.Applications.Sdk.Common.Files; namespace Apps.Crowdin.Models.Request.Translation; public class AddNewFileTranslationRequest : ProjectRequest { - [Display("Language ID")] - [DataSource(typeof(LanguagesDataHandler))] - public string LanguageId { get; set; } + [Display("Language ID"), DataSource(typeof(LanguagesDataHandler))] + public string LanguageId { get; set; } = string.Empty; [Display("File")] - public FileReference File { get; set; } + public FileReference File { get; set; } = null!; [Display("Source file ID")] public string? SourceFileId { get; set; } @@ -26,4 +26,21 @@ public class AddNewFileTranslationRequest : ProjectRequest [Display("Translate hidden")] public bool? TranslateHidden { get; set; } + + public AddNewFileTranslationRequest Validate() + { + if (string.IsNullOrEmpty(LanguageId)) + { + throw new PluginMisconfigurationException( + "Language ID cannot be null or empty. Please provide a valid language ID."); + } + + if (string.IsNullOrEmpty(ProjectId)) + { + throw new PluginMisconfigurationException( + "Project ID cannot be null or empty. Please provide a valid project ID."); + } + + return this; + } } \ No newline at end of file diff --git a/Apps.Crowdin/Models/Response/Vendors/GetVendorResponse.cs b/Apps.Crowdin/Models/Response/Vendors/GetVendorResponse.cs index d8aa556..1711a78 100644 --- a/Apps.Crowdin/Models/Response/Vendors/GetVendorResponse.cs +++ b/Apps.Crowdin/Models/Response/Vendors/GetVendorResponse.cs @@ -1,4 +1,5 @@ -using Blackbird.Applications.Sdk.Common; +using Apps.Crowdin.Models.Entities; +using Blackbird.Applications.Sdk.Common; namespace Apps.Crowdin.Models.Response.Vendors; diff --git a/Apps.Crowdin/Models/Response/Vendors/ListVendorsResponse.cs b/Apps.Crowdin/Models/Response/Vendors/ListVendorsResponse.cs index 121a33f..e3ce6ad 100644 --- a/Apps.Crowdin/Models/Response/Vendors/ListVendorsResponse.cs +++ b/Apps.Crowdin/Models/Response/Vendors/ListVendorsResponse.cs @@ -1,3 +1,5 @@ -namespace Apps.Crowdin.Models.Response.Vendors; +using Apps.Crowdin.Models.Entities; + +namespace Apps.Crowdin.Models.Response.Vendors; public record ListVendorsResponse(VendorEntity[] Vendors); \ No newline at end of file diff --git a/Apps.Crowdin/Polling/Models/Responses/PreTranslationResponse.cs b/Apps.Crowdin/Polling/Models/Responses/PreTranslationResponse.cs index 4e8bbbc..6b0e880 100644 --- a/Apps.Crowdin/Polling/Models/Responses/PreTranslationResponse.cs +++ b/Apps.Crowdin/Polling/Models/Responses/PreTranslationResponse.cs @@ -56,10 +56,10 @@ public class Attributes public string Method { get; set; } = default!; [Display("File IDs")] - public List FileIds { get; set; } = default!; + public List FileIds { get; set; } = default!; [Display("Label IDs")] - public List LabelIds { get; set; } = default!; + public List LabelIds { get; set; } = default!; [Display("Language IDs")] public List LanguageIds { get; set; } = default!;