2
2
using System . Collections . Concurrent ;
3
3
using System . Collections . Generic ;
4
4
using Sdl . Community . MTCloud . Provider . Events ;
5
+ using Sdl . Community . MTCloud . Provider . Extensions ;
5
6
using Sdl . Community . MTCloud . Provider . Interfaces ;
6
7
using Sdl . Community . MTCloud . Provider . Model . RateIt ;
7
8
using Sdl . Core . Globalization ;
@@ -16,13 +17,11 @@ public class SegmentSupervisor : ISegmentSupervisor
16
17
{
17
18
private readonly EditorController _editorController ;
18
19
private ITranslationService _translationService ;
19
- private static List < string > _providerNames ;
20
20
21
21
22
22
public SegmentSupervisor ( EditorController editorController )
23
23
{
24
24
_editorController = editorController ;
25
- _providerNames = new List < string > { PluginResources . SDLMTCloud_Provider_Name , PluginResources . SDLMTCloud_Provider_OldName , PluginResources . SDLMTCloud_Provider_OldName2 , PluginResources . SDLMTCloud_Provider_OldName3 } ;
26
25
}
27
26
28
27
public event ShouldSendFeedbackEventHandler ShouldSendFeedback ;
@@ -105,31 +104,33 @@ public void StartSupervising(ITranslationService translationService)
105
104
106
105
private static bool WasPreviousOriginMTCloud ( ITranslationOrigin translationOrigin )
107
106
{
108
- return _providerNames . Contains ( translationOrigin ? . OriginBeforeAdaptation ? . OriginSystem ) ;
107
+ return translationOrigin ? . OriginBeforeAdaptation ? . OriginSystem ? . IsLanguageWeaverOrigin ( ) ?? false ;
109
108
}
110
109
111
110
private static bool IsOriginMTCloud ( ITranslationOrigin translationOrigin )
112
111
{
113
- return _providerNames . Contains ( translationOrigin ? . OriginSystem ) ;
112
+ return translationOrigin ? . OriginSystem ? . IsLanguageWeaverOrigin ( ) ?? false ;
114
113
}
115
114
116
115
private void ActiveDocument_SegmentsConfirmationLevelChanged ( object sender , EventArgs e )
117
116
{
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
+ }
120
121
121
122
var segmentId = targetSegment . Properties . Id ;
122
123
var translationOrigin = targetSegment . Properties . TranslationOrigin ;
123
-
124
124
if ( IsImprovementToTpTranslation ( translationOrigin , segmentId , targetSegment ) )
125
125
{
126
126
UpdateImprovement ( segmentId , targetSegment . ToString ( ) ) ;
127
127
}
128
128
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
+ }
133
134
}
134
135
135
136
private void EditorController_ActiveDocumentChanged ( object sender , DocumentEventArgs e )
@@ -142,11 +143,10 @@ private void EditorController_ActiveDocumentChanged(object sender, DocumentEvent
142
143
private bool IsImprovementToTpTranslation ( ITranslationOrigin translationOrigin , SegmentId segmentId , ISegment segment )
143
144
{
144
145
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 ;
150
150
}
151
151
152
152
private void TranslationService_TranslationReceived ( TranslationData translationData )
0 commit comments