Skip to content

Commit 0e63de3

Browse files
SDLCOM-4285
1 parent 88f5cfe commit 0e63de3

File tree

5 files changed

+66
-44
lines changed

5 files changed

+66
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
3+
namespace Sdl.Community.MTCloud.Provider.Extensions
4+
{
5+
public static class ValidationExtensions
6+
{
7+
private static readonly List<string> _providerNames = new()
8+
{
9+
PluginResources.SDLMTCloud_Provider_Name,
10+
PluginResources.SDLMTCloud_Provider_OldName,
11+
PluginResources.SDLMTCloud_Provider_OldName2,
12+
PluginResources.SDLMTCloud_Provider_OldName3
13+
};
14+
15+
public static bool IsLanguageWeaverOrigin(this string originSystem)
16+
=> originSystem is string originSystemString
17+
&& (_providerNames.Contains(originSystemString) || originSystemString.ToLower().Contains(PluginResources.SDLMTCloud_Provider_Name.ToLower()));
18+
}
19+
}

SDLMTCloud.Provider/Sdl.Community.MTCloud.Provider/Service/RateIt/MetadataSupervisor.cs

+8-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Windows;
66
using Sdl.Community.MTCloud.Provider.Events;
7+
using Sdl.Community.MTCloud.Provider.Extensions;
78
using Sdl.Community.MTCloud.Provider.Interfaces;
89
using Sdl.Community.MTCloud.Provider.Model.RateIt;
910
using Sdl.Community.MTCloud.Provider.Service.Interface;
@@ -22,17 +23,12 @@ public class MetadataSupervisor : IMetadataSupervisor
2223
private Window _batchProcessingWindow;
2324
private bool _isFirstTime = true;
2425
private ITranslationService _translationService;
25-
private static List<string> _providerNames;
2626

2727
public MetadataSupervisor(ISegmentMetadataCreator segmentMetadataCreator, EditorController editorController)
2828
{
2929
_segmentMetadataCreator = segmentMetadataCreator;
3030
_editorController = editorController;
31-
32-
_providerNames = new List<string> { PluginResources.SDLMTCloud_Provider_Name, PluginResources.SDLMTCloud_Provider_OldName, PluginResources.SDLMTCloud_Provider_OldName2, PluginResources.SDLMTCloud_Provider_OldName3 };
33-
34-
_ = MtCloudApplicationInitializer
35-
.Subscribe<RefreshQeStatus>(OnQeStatus);
31+
_ = MtCloudApplicationInitializer.Subscribe<RefreshQeStatus>(OnQeStatus);
3632
}
3733

3834
private IStudioDocument ActiveDocument => _editorController?.ActiveDocument;
@@ -97,11 +93,6 @@ public string GetSegmentQe(SegmentId segmentId)
9793
return ActiveDocumentData.TryGetValue(segmentId, out var value) ? value.QualityEstimation : null;
9894
}
9995

100-
private static bool IsFromSdlMtCloud(ITranslationOrigin translationOrigin)
101-
{
102-
return _providerNames.Contains(translationOrigin?.OriginSystem);
103-
}
104-
10596
private void ActiveDocument_ActiveSegmentChanged(object sender, EventArgs e)
10697
{
10798
var storedQe = GetCurrentSegmentStoredQe();
@@ -110,11 +101,13 @@ private void ActiveDocument_ActiveSegmentChanged(object sender, EventArgs e)
110101

111102
private void ActiveDocument_SegmentsConfirmationLevelChanged(object sender, EventArgs e)
112103
{
113-
var segment = (ISegment)((ISegmentContainerNode)sender).Item;
114-
if (segment == null) return;
104+
if ((sender as ISegmentContainerNode).Item is not ISegment segment)
105+
{
106+
return;
107+
}
115108

116-
var translationOrigin = segment.Properties.TranslationOrigin;
117-
if (IsFromSdlMtCloud(translationOrigin))
109+
var isLwOrigin = segment.Properties?.TranslationOrigin?.OriginSystem?.IsLanguageWeaverOrigin();
110+
if (isLwOrigin ?? false)
118111
{
119112
AddToSegmentContextData();
120113
}

SDLMTCloud.Provider/Sdl.Community.MTCloud.Provider/Service/RateIt/SegmentSupervisor.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using Sdl.Community.MTCloud.Provider.Events;
5+
using Sdl.Community.MTCloud.Provider.Extensions;
56
using Sdl.Community.MTCloud.Provider.Interfaces;
67
using Sdl.Community.MTCloud.Provider.Model.RateIt;
78
using Sdl.Core.Globalization;
@@ -16,13 +17,11 @@ public class SegmentSupervisor : ISegmentSupervisor
1617
{
1718
private readonly EditorController _editorController;
1819
private ITranslationService _translationService;
19-
private static List<string> _providerNames;
2020

2121

2222
public SegmentSupervisor(EditorController editorController)
2323
{
2424
_editorController = editorController;
25-
_providerNames = new List<string> { PluginResources.SDLMTCloud_Provider_Name, PluginResources.SDLMTCloud_Provider_OldName, PluginResources.SDLMTCloud_Provider_OldName2, PluginResources.SDLMTCloud_Provider_OldName3 };
2625
}
2726

2827
public event ShouldSendFeedbackEventHandler ShouldSendFeedback;
@@ -105,31 +104,33 @@ public void StartSupervising(ITranslationService translationService)
105104

106105
private static bool WasPreviousOriginMTCloud(ITranslationOrigin translationOrigin)
107106
{
108-
return _providerNames.Contains(translationOrigin?.OriginBeforeAdaptation?.OriginSystem);
107+
return translationOrigin?.OriginBeforeAdaptation?.OriginSystem?.IsLanguageWeaverOrigin() ?? false;
109108
}
110109

111110
private static bool IsOriginMTCloud(ITranslationOrigin translationOrigin)
112111
{
113-
return _providerNames.Contains(translationOrigin?.OriginSystem);
112+
return translationOrigin?.OriginSystem?.IsLanguageWeaverOrigin() ?? false;
114113
}
115114

116115
private void ActiveDocument_SegmentsConfirmationLevelChanged(object sender, EventArgs e)
117116
{
118-
var targetSegment = (ISegment)((ISegmentContainerNode)sender).Item;
119-
if (targetSegment == null) return;
117+
if ((sender as ISegmentContainerNode).Item is not ISegment targetSegment)
118+
{
119+
return;
120+
}
120121

121122
var segmentId = targetSegment.Properties.Id;
122123
var translationOrigin = targetSegment.Properties.TranslationOrigin;
123-
124124
if (IsImprovementToTpTranslation(translationOrigin, segmentId, targetSegment))
125125
{
126126
UpdateImprovement(segmentId, targetSegment.ToString());
127127
}
128128

129-
if (!IsOriginMTCloud(translationOrigin) && !WasPreviousOriginMTCloud(translationOrigin) ||
130-
targetSegment.Properties.ConfirmationLevel != ConfirmationLevel.Translated) return;
131-
132-
ShouldSendFeedback?.Invoke(segmentId);
129+
if ((IsOriginMTCloud(translationOrigin) || WasPreviousOriginMTCloud(translationOrigin))
130+
&& targetSegment.Properties.ConfirmationLevel == ConfirmationLevel.Translated)
131+
{
132+
ShouldSendFeedback?.Invoke(segmentId);
133+
}
133134
}
134135

135136
private void EditorController_ActiveDocumentChanged(object sender, DocumentEventArgs e)
@@ -142,11 +143,10 @@ private void EditorController_ActiveDocumentChanged(object sender, DocumentEvent
142143
private bool IsImprovementToTpTranslation(ITranslationOrigin translationOrigin, SegmentId segmentId, ISegment segment)
143144
{
144145
if (ActiveDocumentData is null) return false;
145-
146-
return (WasPreviousOriginMTCloud(translationOrigin) || IsOriginMTCloud(translationOrigin)) &&
147-
ActiveDocumentData.ContainsKey(segmentId) &&
148-
ActiveDocumentData[segmentId].OriginalMtCloudTranslation != segment.ToString() &&
149-
segment.Properties?.ConfirmationLevel == ConfirmationLevel.Translated;
146+
return (WasPreviousOriginMTCloud(translationOrigin) || IsOriginMTCloud(translationOrigin))
147+
&& ActiveDocumentData.ContainsKey(segmentId)
148+
&& ActiveDocumentData[segmentId].OriginalMtCloudTranslation != segment.ToString()
149+
&& segment.Properties?.ConfirmationLevel == ConfirmationLevel.Translated;
150150
}
151151

152152
private void TranslationService_TranslationReceived(TranslationData translationData)

SDLMTCloud.Provider/Sdl.Community.MTCloud.Provider/Studio/TranslationProvider/SdlMTCloudTranslationProvider.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,20 @@ public SdlMTCloudTranslationProvider(Uri uri, string translationProviderState, I
4242

4343
public ILanguageProvider LanguageProvider { get; }
4444

45-
public string Name => PluginResources.SDLMTCloud_Provider_Name;
45+
public string Name
46+
{
47+
get
48+
{
49+
var selectedModelName = Options.LanguageMappings?
50+
.FirstOrDefault(x => x.TargetTradosCode.Equals(LanguageDirectionProvider?.TargetLanguage?.Name))
51+
.SelectedModel?
52+
.MTCloudLanguagePair
53+
.DisplayName;
54+
return string.IsNullOrEmpty(selectedModelName)
55+
? PluginResources.SDLMTCloud_Provider_Name
56+
: $"{PluginResources.SDLMTCloud_Provider_Name} - {selectedModelName}";
57+
}
58+
}
4659

4760
public Options Options
4861
{

SDLMTCloud.Provider/Sdl.Community.MTCloud.Provider/ViewModel/RateItViewModel.cs

+9-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Sdl.Community.MTCloud.Languages.Provider;
1111
using Sdl.Community.MTCloud.Provider.Commands;
1212
using Sdl.Community.MTCloud.Provider.Events;
13+
using Sdl.Community.MTCloud.Provider.Extensions;
1314
using Sdl.Community.MTCloud.Provider.Interfaces;
1415
using Sdl.Community.MTCloud.Provider.Model;
1516
using Sdl.Community.MTCloud.Provider.Model.RateIt;
@@ -385,19 +386,15 @@ private bool IsResetNeeded(object sender, PropertyChangedEventArgs e)
385386
private void MetadataSupervisor_ActiveSegmentQeChanged(ActiveSegmentQeChanged data)
386387
{
387388
AddEvaluationForCurrentSegment(data.Estimation);
389+
if (!ActiveSegmentId.HasValue)
390+
{
391+
return;
392+
}
388393

389-
if (!ActiveSegmentId.HasValue) return;
390-
391-
var currentSegmentEvaluation = ActiveDocumentEvaluations.EvaluationPerSegment.TryGetValue(
392-
ActiveSegmentId.Value,
393-
out var qualityEstimation);
394-
395-
ActiveDocumentEvaluations.CurrentSegmentEvaluation =
396-
ActiveDocument.ActiveSegmentPair.Properties.TranslationOrigin.OriginSystem ==
397-
Resources.OriginSystem_LWC && currentSegmentEvaluation
398-
? qualityEstimation
399-
: null;
400-
394+
var currentEvaluation = ActiveDocumentEvaluations.EvaluationPerSegment.TryGetValue(ActiveSegmentId.Value, out var qualityEstimation);
395+
var isLwOrigin = ActiveDocument.ActiveSegmentPair.Properties.TranslationOrigin.OriginSystem.IsLanguageWeaverOrigin();
396+
qualityEstimation = isLwOrigin && currentEvaluation ? qualityEstimation : null;
397+
ActiveDocumentEvaluations.CurrentSegmentEvaluation = qualityEstimation;
401398
OnPropertyChanged(nameof(ActiveDocumentEvaluations));
402399
}
403400

0 commit comments

Comments
 (0)