Skip to content

Commit

Permalink
ApplyTMTemplate 4.0.1.2 - SDLCOM-6420:
Browse files Browse the repository at this point in the history
- Fixed loading of Translation Memories from ApplyTMSettings
- All settings are now persistent
  • Loading branch information
aflorescu579774 committed Feb 3, 2025
1 parent 0fe3352 commit dcaa35c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class ApplyTMSettings
{
public string LanguageResourcePath { get; set; } = string.Empty;

public List<string> TMPathCollection { get; set; } = new();
public List<TranslationMemoryEntry> TMPathCollection { get; set; } = new();

public ApplyTMMethod SelectedMethod { get; set; }

public Settings Settings { get; set; } = new Settings();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sdl.Community.ApplyTMTemplate.Models
{
public class TranslationMemoryEntry
{
public string Path { get; set; } = string.Empty;

public bool IsSelected { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.0.0.0")]
[assembly: AssemblyFileVersion("4.0.1.1")]
[assembly: AssemblyFileVersion("4.0.1.2")]
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,25 @@ public ObservableCollection<TranslationMemory> GetTms(IEnumerable<string> files,

return newTmsCollection;
}

public ObservableCollection<TranslationMemory> GetTMsAndApplySelection(IEnumerable<TranslationMemoryEntry> tmEntries, ObservableCollection<TranslationMemory> tmCollection)
{
var newTmsCollection = new ObservableCollection<TranslationMemory>();

foreach (var entry in tmEntries)
{
if (IsValid(entry.Path)) continue;

var fileBasedTm = new TranslationMemory(entry.Path);
fileBasedTm.IsSelected = entry.IsSelected;

if (tmCollection.All(tm => tm.Name != fileBasedTm.Name))
{
newTmsCollection.Add(fileBasedTm);
}
}

return newTmsCollection;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ private void AddTMSettings(string location)

if (filePaths is null || !filePaths.Any()) return;

TmCollection.Clear();
_applyTMSettingsPath = filePaths[0];
var preferences = _applyTMSettingsManager.LoadSettings(filePaths[0]);
if (preferences is null)
Expand All @@ -285,39 +286,41 @@ private void AddTMSettings(string location)
return;
}

SettingsSelectedMethod = preferences.SelectedMethod;

if (preferences.LanguageResourcePath is not null)
ResourceTemplatePath = preferences.LanguageResourcePath;

if (preferences.TMPathCollection is not null)
{
var validTMs = FilterInvalidTMs(preferences.TMPathCollection, location);
AddRangeOfTms(_tmLoader.GetTms(validTMs, TmCollection));
AddRangeOfTms(_tmLoader.GetTMsAndApplySelection(validTMs, TmCollection));
}

if (preferences.Settings is not null) ApplyNewSettings(preferences.Settings);
}

private IEnumerable<string> GetMissingTMs(IEnumerable<string> filePaths)
private IEnumerable<TranslationMemoryEntry> GetMissingTMs(IEnumerable<TranslationMemoryEntry> tms)
{
return filePaths.Where(filePath => !File.Exists(filePath));
return tms.Where(tm => !File.Exists(tm.Path));
}

private IEnumerable<string> GetInvalidTMs(IEnumerable<string> filePaths)
private IEnumerable<TranslationMemoryEntry> GetInvalidTMs(IEnumerable<TranslationMemoryEntry> tms)
{
return filePaths.Where(file => Path.GetExtension(file).ToLower() != ".sdltm");
return tms.Where(tm => Path.GetExtension(tm.Path).ToLower() != ".sdltm");
}

private List<string> FilterInvalidTMs(IEnumerable<string> filePaths, string location)
private IEnumerable<TranslationMemoryEntry> FilterInvalidTMs(IEnumerable<TranslationMemoryEntry> tms, string location)
{
var missingTMs = GetMissingTMs(filePaths);
var missingTMs = GetMissingTMs(tms);
if (missingTMs.Any() && location is null)
_messageService.ShowWarningMessage(PluginResources.Warning, PluginResources.ApplyTMSettings_MissingTMs);

var invalidTMs = GetInvalidTMs(filePaths);
var invalidTMs = GetInvalidTMs(tms);
if (invalidTMs.Any() && location is null)
_messageService.ShowWarningMessage(PluginResources.Warning, PluginResources.ApplyTMSettings_InvalidTMs);

return filePaths.Where(path => !missingTMs.Contains(path) && !invalidTMs.Contains(path)).ToList();
return tms.Where(tm => !missingTMs.Contains(tm) && !invalidTMs.Contains(tm)).ToList();
}

private void ApplyNewSettings(Settings newSettings)
Expand Down Expand Up @@ -353,9 +356,15 @@ private async void SavePreferences()
{
var preferences = new ApplyTMSettings()
{
TMPathCollection = TmCollection.Select(tm => tm.FilePath).ToList(),
TMPathCollection = TmCollection.Select(
tm => new TranslationMemoryEntry()
{
IsSelected = tm.IsSelected,
Path = tm.FilePath
}).ToList(),
LanguageResourcePath = ResourceTemplatePath,
Settings = Settings
Settings = Settings,
SelectedMethod = SettingsSelectedMethod
};

var saveLocation = GetSaveLocation(
Expand All @@ -365,7 +374,7 @@ private async void SavePreferences()
if (saveLocation == null) return;

await Task.Run(() => _applyTMSettingsManager.SaveSettings(saveLocation, preferences));
_messageService.ShowMessage(PluginResources.Success_Window_Title, PluginResources.TMSettings_Created));
_messageService.ShowMessage(PluginResources.Success_Window_Title, PluginResources.TMSettings_Created);
}

private async void ExportToExcel()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<PluginPackage xmlns="http://www.sdl.com/Plugins/PluginPackage/1.0">
<PlugInName>applyTM Template</PlugInName>
<Version>4.0.1.1</Version>
<Version>4.0.1.2</Version>
<Description>This plugin adds support for managing and applying the settings in a Language Resource Template to multiple translation memories in one go.</Description>
<Author>Trados AppStore Team</Author>
<Include>
Expand Down

0 comments on commit dcaa35c

Please sign in to comment.