Skip to content

Commit a9da97b

Browse files
Merge pull request #1147 from RWS/LanguageWeaver_2022
Language weaver 2022
2 parents b094aea + 0e63de3 commit a9da97b

File tree

9 files changed

+80
-55
lines changed

9 files changed

+80
-55
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/Sdl.Community.MTCloud.Provider.csproj

-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
<Reference Include="Sdl.Desktop.Platform.Styles">
6464
<HintPath>$(TradosFolder)\Sdl.Desktop.Platform.Styles.dll</HintPath>
6565
</Reference>
66-
<Reference Include="Sdl.DesktopEditor.Control">
67-
<HintPath>$(TradosFolder)\Sdl.DesktopEditor.Control.dll</HintPath>
68-
</Reference>
6966
<Reference Include="Sdl.DesktopEditor.EditorApi">
7067
<HintPath>$(TradosFolder)\Sdl.DesktopEditor.EditorApi.dll</HintPath>
7168
</Reference>

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/OptionsViewModel.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,31 @@ private void ResetToDefaults(object parameter)
171171
return;
172172
}
173173

174+
var selectedIndex = LanguageMappingModels.IndexOf(SelectedLanguageMappingModel);
174175
if ((parameter as string) == "ResetSelected" && SelectedLanguageMappingModel is not null)
175176
{
176177
var selectedLanguageMappingModelName = SelectedLanguageMappingModel.Name;
177178
var originalLanguageMappingModels = LanguageMappingModels.Where(x => x.Name != SelectedLanguageMappingModel.Name).ToList();
178179
LanguageMappingModels.Clear();
179180
LoadLanguageMappings();
180181

181-
originalLanguageMappingModels.Add(LanguageMappingModels.FirstOrDefault(x => x.Name.Equals(selectedLanguageMappingModelName)));
182+
originalLanguageMappingModels.Insert(selectedIndex, LanguageMappingModels.FirstOrDefault(x => x.Name.Equals(selectedLanguageMappingModelName)));
182183
LanguageMappingModels = new(originalLanguageMappingModels);
183-
SelectedLanguageMappingModel = LanguageMappingModels.FirstOrDefault(x => x.Name.Equals(selectedLanguageMappingModelName));
184+
SelectedLanguageMappingModel = LanguageMappingModels.ElementAt(selectedIndex) ?? LanguageMappingModels.FirstOrDefault();
185+
186+
System.Windows.MessageBox.Show($"{PluginResources.Message_Successfully_reset_to_defaults} the selected model",
187+
Application.ProductName, MessageBoxButton.OK, MessageBoxImage.Information);
188+
}
189+
else if ((parameter as string) == "ResetSelected" && SelectedLanguageMappingModel is null)
190+
{
191+
System.Windows.MessageBox.Show("Please select a model to reset",
192+
Application.ProductName, MessageBoxButton.OK, MessageBoxImage.Warning);
184193
}
185194
else
186195
{
187196
LanguageMappingModels.Clear();
188197
LoadLanguageMappings();
189-
}
190-
191-
if (Owner != null)
192-
{
198+
SelectedLanguageMappingModel = LanguageMappingModels.ElementAt(selectedIndex) ?? LanguageMappingModels.FirstOrDefault();
193199
System.Windows.MessageBox.Show(PluginResources.Message_Successfully_reset_to_defaults,
194200
Application.ProductName, MessageBoxButton.OK, MessageBoxImage.Information);
195201
}

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

SDLMTCloud.Provider/Sdl.Community.MTCloud.Provider/pluginpackage.manifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PluginPackage xmlns="http://www.sdl.com/Plugins/PluginPackage/1.0">
33
<PlugInName>Language Weaver</PlugInName>
4-
<Version>5.0.8.4</Version>
4+
<Version>5.0.8.5</Version>
55
<Description>Language Weaver Provider</Description>
66
<Author>Trados AppStore Team</Author>
77
<Include>

SDLMTCloud.Provider/SolutionInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
// by using the '*' as shown below:
1818
// [assembly: AssemblyVersion("1.0.*")]
1919
[assembly: AssemblyVersion("5.0.0.0")]
20-
[assembly: AssemblyFileVersion("5.0.8.4")]
20+
[assembly: AssemblyFileVersion("5.0.8.5")]

0 commit comments

Comments
 (0)