Skip to content

Commit

Permalink
Merge pull request #22 from bb-io/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vitalii-bezuhlyi authored May 6, 2024
2 parents e75c55c + 5256ae5 commit 1307f43
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 51 deletions.
55 changes: 32 additions & 23 deletions Apps.Memoq/Actions/ServerProjectActions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Apps.Memoq.Contracts;
using Apps.Memoq.DataSourceHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Apps.Memoq.Extensions;
using Apps.Memoq.Models;
using Apps.Memoq.Models.Dto;
Expand All @@ -10,6 +11,7 @@
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Actions;
using Blackbird.Applications.Sdk.Common.Authentication;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.Sdk.Utils.Extensions.String;
Expand Down Expand Up @@ -68,8 +70,7 @@ public ProjectDto GetProject([ActionParameter] ProjectRequest project)
[Action("Add target language to project", Description = "Add target language to project by code")]
public void AddNewTargetLanguageToProject(
[ActionParameter] ProjectRequest project,
[ActionParameter] [DataSource(typeof(TargetLanguageDataHandler))] [Display("Target language")]
string targetLangCode)
[ActionParameter, StaticDataSource(typeof(TargetLanguageDataHandler)), Display("Target language")] string targetLangCode)
{
var projectService = new MemoqServiceFactory<IServerProjectService>(
SoapConstants.ProjectServiceUrl, Creds);
Expand Down Expand Up @@ -248,33 +249,34 @@ public async Task AddResourceToProject([ActionParameter] ProjectRequest project,
await projectService.Service.SetProjectResourceAssignmentsAsync(Guid.Parse(project.ProjectGuid), array);
}

[Action("Pretranslate documents", Description = "Pretranslate documents in a specific project")]
[Action("Pretranslate documents", Description = "Pretranslate documents if document GUIDs are provided, otherwise pretranslate the whole project with all documents")]
public async Task<PretranslateDocumentsResponse> PretranslateDocuments(
[ActionParameter] ProjectRequest projectRequest,
[ActionParameter] PretranslateDocumentsRequest request)
{
var projectService = new MemoqServiceFactory<IServerProjectService>(
SoapConstants.ProjectServiceUrl, Creds);

var options = new PretranslateOptions();

if (request.LockPretranslated.HasValue)
options.LockPretranslated = request.LockPretranslated.Value;

if (request.UseMt.HasValue)
options.UseMT = request.UseMt.Value;

if (request.ConfirmLockPreTranslated != null)
options.ConfirmLockPretranslated =
(PretranslateStateToConfirmAndLock)int.Parse(request.ConfirmLockPreTranslated);

var options = new PretranslateOptions
{
OnlyUnambiguousMatches = request.OnlyUnambiguousMatches ?? true,
LockPretranslated = request.LockPretranslated ?? true,
UseMT = request.UseMt ?? true,
ConfirmLockPretranslated = request.ConfirmLockPreTranslated != null
? (PretranslateStateToConfirmAndLock)int.Parse(request.ConfirmLockPreTranslated)
: PretranslateStateToConfirmAndLock.ExactMatch,
FinalTranslationState = request.FinalTranslationState != null
? (PretranslateExpectedFinalTranslationState)int.Parse(request.FinalTranslationState)
: PretranslateExpectedFinalTranslationState.NoChange
};

if (request.PretranslateLookupBehavior != null)
options.PretranslateLookupBehavior =
(PretranslateLookupBehavior)int.Parse(request.PretranslateLookupBehavior);

if (request.TranslationMemoriesGuids != null && request.TranslationMemoriesGuids.Any())
{
options.ResourceFilter = new PreTransFilter()
options.ResourceFilter = new PreTransFilter
{
TMs = request.TranslationMemoriesGuids.Select(Guid.Parse).ToArray()
};
Expand All @@ -289,14 +291,21 @@ public async Task<PretranslateDocumentsResponse> PretranslateDocuments(
IncludeNT = request.IncludeNonTranslatables ?? true,
IncludeTB = request.IncludeTermBases ?? true,
MinCoverage = request.MinCoverage ?? 50,
CoverageType = (MatchCoverageType)int.Parse(request.CoverageType ?? "300")
CoverageType = (MatchCoverageType)int.Parse(request.CoverageType ?? "300"),
};

var guids = request.DocumentGuids.Select(Guid.Parse).ToArray();
var resultInfo = await projectService.Service.PretranslateDocumentsAsync(Guid.Parse(projectRequest.ProjectGuid),
guids, options);

return new(resultInfo);
var guids = request.DocumentGuids?.Select(Guid.Parse).ToArray();
if (guids != null && guids.Length != 0)
{
var resultInfo = await projectService.Service.PretranslateDocumentsAsync(Guid.Parse(projectRequest.ProjectGuid),
guids, options);

return new(resultInfo);
}

var targetLanguages = request.TargetLanguages?.ToArray();
var result = await projectService.Service.PretranslateProjectAsync(Guid.Parse(projectRequest.ProjectGuid), targetLanguages, options);
return new(result);
}

private List<ServerProjectResourceAssignment> CreateAssignmentsBasedOnResourceType(ResourceType resourceType,
Expand Down
2 changes: 1 addition & 1 deletion Apps.Memoq/Apps.MemoQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<Product>memoQ</Product>
<Description>Computer-assisted translation</Description>
<Version>1.1.11</Version>
<Version>1.1.12</Version>
<AssemblyName>Apps.MemoQ</AssemblyName>
<LangVersion>12</LangVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Blackbird.Applications.Sdk.Common.Dictionaries;

namespace Apps.Memoq.DataSourceHandlers.EnumDataHandlers;

public class FinalTranslationStateDataHandler : IStaticDataSourceHandler
{
public Dictionary<string, string> GetData()
{
return new Dictionary<string, string>
{
{ "0", "No change" },
{ "1", "Confirmed" },
{ "2", "Proofread" },
{ "3", "Pretranslated" },
{ "4", "Reviewer 1 confirmed" }
};
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Blackbird.Applications.Sdk.Utils.Sdk.DataSourceHandlers;
using Blackbird.Applications.Sdk.Common.Dictionaries;

namespace Apps.Memoq.DataSourceHandlers;
namespace Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;

public class TargetLanguageDataHandler : EnumDataHandler
public class TargetLanguageDataHandler : IStaticDataSourceHandler
{
protected override Dictionary<string, string> EnumValues => new()
private Dictionary<string, string> EnumValues => new()
{
["afr"] = "Afrikaans", ["aka"] = "Akan", ["alb"] = "Albanian", ["alb-AL"] = "Albanian (Albania)",
["alb-XK"] = "Albanian (Kosovo)", ["alb-MK"] = "Albanian (Macedonia)", ["alb-ME"] = "Albanian (Montenegro)",
Expand Down Expand Up @@ -77,4 +77,9 @@ public class TargetLanguageDataHandler : EnumDataHandler
["uzb"] = "Uzbek (Latin)", ["vie"] = "Vietnamese", ["wel"] = "Welsh", ["wol"] = "Wolof", ["xho"] = "Xhosa",
["yid"] = "Yiddish", ["yor"] = "Yoruba", ["zul"] = "Zulu"
};

public Dictionary<string, string> GetData()
{
return EnumValues;
}
}
7 changes: 4 additions & 3 deletions Apps.Memoq/DataSourceHandlers/ObjectDataHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Apps.Memoq.Models.ServerProjects.Requests;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Apps.Memoq.Models.ServerProjects.Requests;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Authentication;
using Blackbird.Applications.Sdk.Common.Dynamic;
Expand Down Expand Up @@ -47,13 +48,13 @@ public async Task<Dictionary<string, string>> GetDataAsync(DataSourceContext con
resourceType == ResourceType.QASettings)
{
var targetLanguageDataHandler = new TargetLanguageDataHandler();
return targetLanguageDataHandler.GetData(context);
return targetLanguageDataHandler.GetData();
}

if (resourceType == ResourceType.SegRules)
{
var targetLanguageDataHandler = new TargetLanguageDataHandler();
return targetLanguageDataHandler.GetData(context);
return targetLanguageDataHandler.GetData();
}

if (resourceType == ResourceType.TMSettings)
Expand Down
21 changes: 15 additions & 6 deletions Apps.Memoq/Models/Files/Requests/PretranslateDocumentsRequest.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
using Apps.Memoq.DataSourceHandlers.EnumDataHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Memoq.Models.Files.Requests;

public class PretranslateDocumentsRequest
{
[Display("Document GUIDs")]
public IEnumerable<string> DocumentGuids { get; set; }
[Display("Document GUIDs", Description = "If not provided, all documents in the project will be pretranslated")]
public IEnumerable<string>? DocumentGuids { get; set; }

[Display("Target languages", Description = "If not provided, documents with all target languages will be translated"), StaticDataSource(typeof(TargetLanguageDataHandler))]
public IEnumerable<string>? TargetLanguages { get; set; }

[Display("Lock")]
[Display("Lock", Description = "By default: true")]
public bool? LockPretranslated { get; set; }

[Display("Confirm lock pretranslated"), StaticDataSource(typeof(ConfirmLockDataHandler))]
[Display("Confirm lock pretranslated", Description = "By default: Exact match"), StaticDataSource(typeof(ConfirmLockDataHandler))]
public string? ConfirmLockPreTranslated { get; set; }

[Display("Pretranslate lookup behavior"), StaticDataSource(typeof(PretranslateLookupBehaviorDataHandler))]
public string? PretranslateLookupBehavior { get; set; }

[Display("Use MT")]
[Display("Use MT", Description = "By default: true")]
public bool? UseMt { get; set; }

[Display("Translation memories GUIDs")]
Expand Down Expand Up @@ -48,4 +51,10 @@ public class PretranslateDocumentsRequest

[Display("Coverage type", Description = "By default: Not full"), StaticDataSource(typeof(MatchCoverageTypeDataHandler))]
public string? CoverageType { get; set; }

[Display("Only unambiguous matches", Description = "By default: true")]
public bool? OnlyUnambiguousMatches { get; set; }

[Display("Final translation state", Description = "By default: No change"), StaticDataSource(typeof(FinalTranslationStateDataHandler))]
public string? FinalTranslationState { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Apps.Memoq.DataSourceHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Apps.Memoq.Models.ServerProjects.Requests;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Files;

Expand All @@ -11,8 +13,7 @@ public class UploadDocumentToProjectRequest : ProjectRequest
[Display("Document")]
public FileReference File { get; set; }

[Display("Target languages")]
[DataSource(typeof(TargetLanguageDataHandler))]
[Display("Target languages"), StaticDataSource(typeof(TargetLanguageDataHandler))]
public IEnumerable<string>? TargetLanguageCodes { get; set; }

[Display("File name")]
Expand Down
5 changes: 3 additions & 2 deletions Apps.Memoq/Models/LanguagesRequest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Apps.Memoq.DataSourceHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Memoq.Models;
Expand All @@ -10,7 +12,6 @@ public class LanguagesRequest
[DataSource(typeof(SourceLanguageDataHandler))]
public string SourceLanguage { get; set; }

[Display("Target language")]
[DataSource(typeof(TargetLanguageDataHandler))]
[Display("Target language"), StaticDataSource(typeof(TargetLanguageDataHandler))]
public string TargetLanguage { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Apps.Memoq.DataSourceHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Memoq.Models.ServerProjects.Requests;
Expand All @@ -10,8 +12,7 @@ public class CreateProjectRequest
[DataSource(typeof(SourceLanguageDataHandler))]
public string SourceLangCode { get; set; }

[Display("Target languages")]
[DataSource(typeof(TargetLanguageDataHandler))]
[Display("Target languages"), StaticDataSource(typeof(TargetLanguageDataHandler))]
public IEnumerable<string> TargetLangCodes { get; set; }

[Display("Project name")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Apps.Memoq.DataSourceHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Memoq.Models.ServerProjects.Requests;
Expand All @@ -10,8 +12,7 @@ public class CreateProjectTemplateRequest
[DataSource(typeof(SourceLanguageDataHandler))]
public string SourceLangCode { get; set; }

[Display("Target languages")]
[DataSource(typeof(TargetLanguageDataHandler))]
[Display("Target languages"), StaticDataSource(typeof(TargetLanguageDataHandler))]
public IEnumerable<string> TargetLangCodes { get; set; }

[Display("Project name")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Apps.Memoq.DataSourceHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Memoq.Models.ServerProjects.Requests;
Expand All @@ -18,8 +20,7 @@ public class ListProjectsRequest
[DataSource(typeof(SourceLanguageDataHandler))]
public string? SourceLanguageCode { get; set; }

[Display("Target language")]
[DataSource(typeof(TargetLanguageDataHandler))]
[Display("Target language"), StaticDataSource(typeof(TargetLanguageDataHandler))]
public string? TargetLanguageCode { get; set; }

[Display("Time closed")] public DateTime? TimeClosed { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Apps.Memoq.DataSourceHandlers;
using Apps.MemoQ.DataSourceHandlers.EnumDataHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dictionaries;
using Blackbird.Applications.Sdk.Common.Dynamic;

namespace Apps.Memoq.Models.TranslationMemories.Requests;
Expand All @@ -9,7 +11,7 @@ public class AddTranslationMemoryToProjectRequest
[Display("Translation memory GUID"), DataSource(typeof(TranslationMemoryDataHandler))]
public IEnumerable<string>? TmGuids { get; set; }

[Display("Target language code"), DataSource(typeof(TargetLanguageDataHandler))]
[Display("Target language code"), StaticDataSource(typeof(TargetLanguageDataHandler))]
public string TargetLanguageCode { get; set; }

[Display("Master translation memory GUID"), DataSource(typeof(TranslationMemoryDataHandler))]
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ Before you can connect you need to make sure that:
- **Create project from package/template** creates a new project based on a specified template/package.
- **Add target language to project** adds target language to a specific project.
- **Pretranslate documents** This action allows you to pretranslate documents in a specific project. Pretranslation is a process where the system automatically fills in the translations for segments in a document based on certain criteria. This can significantly speed up the translation process. Parameters:
1. **Document GUIDs**: This parameter is used to specify the unique identifiers of the documents you want to pretranslate.
2. **Lock**: This optional parameter, when set to true, locks the pretranslated segments to prevent further editing.
3. **Confirm lock pretranslated**: This optional parameter determines the state of segments that should be confirmed and locked during pretranslation.
1. **Document GUIDs**: This parameter is used to specify the unique identifiers of the documents you want to pretranslate. If you don't specify any document GUIDs, the action will pretranslate all documents in the project.
2. **Target languages**: This parameter is used to specify the target languages for pretranslation. If you don't specify any target languages, the action will pretranslate all target languages in the project.
2. **Lock**: This optional parameter, when set to true, locks the pretranslated segments to prevent further editing. By default, this is set to true.
3. **Confirm lock pretranslated**: This optional parameter determines the state of segments that should be confirmed and locked during pretranslation. By default, this is set to 'ExactMatch'.
4. **Pretranslate lookup behavior**: This optional parameter determines the behavior of the pretranslation lookup process.
5. **Use MT**: This optional parameter, when set to true, enables the use of Machine Translation (MT) during pretranslation.
6. **Translation memories GUIDs**: This optional parameter is used to specify the unique identifiers of the translation memories to be used during pretranslation.
Expand All @@ -84,6 +85,8 @@ Before you can connect you need to make sure that:
12. **Include term bases**: This optional parameter, when set to true, includes term bases in the pretranslation. By default, this is set to true.
13. **Minimum coverage**: This optional parameter is used to specify the minimum coverage for pretranslation. By default, this is set to 50.
14. **Coverage type**: This optional parameter is used to specify the type of coverage for pretranslation. By default, this is set to 'Not full'.
15. **Only unambiguous matches**: This optional parameter, when set to true, only includes unambiguous matches in the pretranslation. By default, this is set to true.
16. **Final translation state**: This optional parameter is used to specify the final translation state for pretranslated segments. By default, this is set to 'No change'.

### Translation memories

Expand Down

0 comments on commit 1307f43

Please sign in to comment.