Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Toolkit to work with Trados Studio 2022 and Trados Studio 2024… #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Modules/DependencyLoader/DependencyLoader.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@{

# Script module or binary module file associated with this manifest
ModuleToProcess = 'DependencyLoader.psm1'

# Version number of this module.
ModuleVersion = '1.0.0.0'

# ID used to uniquely identify this module
GUID = '{469B2B87-6367-4015-AF55-0C9CE7F68A52}'

# Author of this module
Author = 'Trados AppStore Team'

# Company or vendor of this module
CompanyName = 'SDL Limited as part of the RWS Holdings Plc group of companies'

# Copyright statement for this module
Copyright = 'Copyright © 2011 - 2022 SDL Limited as part of the RWS Holdings Plc group of companies (\"RWS Group\").'

# Description of the functionality provided by this module
Description = 'A PowerShell module to Load the other modules and their dependencies and resolve the versioning conflicts.'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '2.0'

# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = '2.0'

# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = '2.0.50727'

# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = 'None'

# Modules that must be imported into the global environment prior to importing
# this module
RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to
# importing this module
ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @()

# Modules to import as nested modules of the module specified in
# ModuleToProcess
NestedModules = @()

# Functions to export from this module
FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'

# List of all modules packaged with this module
ModuleList = @()

# List of all files packaged with this module
FileList = @(
'.\DependencyLoader.psm1'
'.\DependencyLoader.psd1'
)

# Private data to pass to the module specified in ModuleToProcess
PrivateData = ''

}
45 changes: 45 additions & 0 deletions Modules/DependencyLoader/DependencyLoader.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
param ([String] $studioVersion = "Studio18")

# Helper module that loads all the others and resolve the versioning conflicts between powershell versions and Trados versions
$scriptPath = $MyInvocation.MyCommand.Path
$scriptParentDiv = Split-Path $scriptPath -Parent;
$moduleNames = @("GetGuids", "PackageHelper", "ProjectHelper", "TMHelper")

Add-Dependencies $studioVersion;

foreach ($moduleName in $moduleNames)
{
Import-Module -Name $moduleName -Scope Global -ArgumentList $studioVersion
}

function Add-Dependencies {
param([String] $StudioVersion)

$assemblyResolverPath = $scriptParentDiv + "\DependencyResolver.dll"
$versionNumber = [regex]::Match($StudioVersion, "\d+").Value;

if ("${Env:ProgramFiles(x86)}") {
$ProgramFilesDir = "${Env:ProgramFiles(x86)}"
}
else {
$ProgramFilesDir = "${Env:ProgramFiles}"
}

if ($versionNumber -le 16)
{
$appPath = "$ProgramFilesDir\Sdl\Sdl Trados Studio\$StudioVersion\"
}
else {
$appPath = "$ProgramFilesDir\Trados\Trados Studio\$StudioVersion\"
}

# Solve dependency conficts
Add-Type -Path $assemblyResolverPath;
$assemblyResolver = New-Object DependencyResolver.AssemblyResolver("$appPath\");
$assemblyResolver.Resolve();

Add-Type -Path "$appPath\Sdl.ProjectAutomation.Core.dll"
Add-Type -Path "$appPath\Sdl.ProjectAutomation.FileBased.dll"
Add-Type -Path "$appPath\Sdl.ProjectAutomation.Settings.dll"
Add-Type -Path "$appPath\Sdl.LanguagePlatform.TranslationMemory.dll"
}
Binary file added Modules/DependencyLoader/DependencyResolver.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions Modules/PackageHelper/PackageHelper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ ModuleVersion = '1.0.0.0'
GUID = '{766899a3-186e-4bf2-b39f-b7d001d67105}'

# Author of this module
Author = 'Patrik Mazanek'
Author = 'Trados AppStore Team'

# Company or vendor of this module
CompanyName = 'SDL'
CompanyName = 'SDL Limited as part of the RWS Holdings Plc group of companies'

# Copyright statement for this module
Copyright = '© 2011 SDL. All rights reserved.'
Copyright = 'Copyright © 2011 - 2022 SDL Limited as part of the RWS Holdings Plc group of companies (\"RWS Group\").'

# Description of the functionality provided by this module
Description = 'A PowerShell module to help project package management'
Expand Down
17 changes: 1 addition & 16 deletions Modules/PackageHelper/PackageHelper.psm1
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
param([String]$StudioVersion = "Studio5")

if ("${Env:ProgramFiles(x86)}") {
$ProgramFilesDir = "${Env:ProgramFiles(x86)}"
}
else {
$ProgramFilesDir = "${Env:ProgramFiles}"
}

Add-Type -Path "$ProgramFilesDir\SDL\SDL Trados Studio\$StudioVersion\Sdl.ProjectAutomation.FileBased.dll"
Add-Type -Path "$ProgramFilesDir\SDL\SDL Trados Studio\$StudioVersion\Sdl.ProjectAutomation.Core.dll"

$LanguagesSeparator = "\s+|;\s*|,\s*"

$ProjectPackageExtension = ".sdlppx"
$ReturnPackageExtension = ".sdlrpx"
param ([string] $studioVersion = "Studio18")

function Export-Package {
<#
Expand Down
6 changes: 3 additions & 3 deletions Modules/ProjectHelper/ProjectHelper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ ModuleVersion = '1.0.0.0'
GUID = '{5eae9ba2-b21e-4b59-b60a-6f519ec522dc}'

# Author of this module
Author = 'Patrik Mazanek'
Author = 'Trados AppStore Team'

# Company or vendor of this module
CompanyName = 'SDL'
CompanyName = 'SDL Limited as part of the RWS Holdings Plc group of companies'

# Copyright statement for this module
Copyright = '© 2011 SDL. All rights reserved.'
Copyright = 'Copyright © 2011 - 2022 SDL Limited as part of the RWS Holdings Plc group of companies (\"RWS Group\").'

# Description of the functionality provided by this module
Description = 'A PowerShell module to automate SDL Trados Studio project management'
Expand Down
88 changes: 60 additions & 28 deletions Modules/ProjectHelper/ProjectHelper.psm1
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
param([String]$StudioVersion = "Studio5")

if ("${Env:ProgramFiles(x86)}") {
$ProgramFilesDir = "${Env:ProgramFiles(x86)}"
}
else {
$ProgramFilesDir = "${Env:ProgramFiles}"
}

Add-Type -Path "$ProgramFilesDir\SDL\SDL Trados Studio\$StudioVersion\Sdl.ProjectAutomation.FileBased.dll"
Add-Type -Path "$ProgramFilesDir\SDL\SDL Trados Studio\$StudioVersion\Sdl.ProjectAutomation.Core.dll"
Add-Type -Path "$ProgramFilesDir\SDL\SDL Trados Studio\$StudioVersion\Sdl.ProjectApi.dll"
param ([string] $studioVersion = "Studio18")

# Helper for handling PowerShell runspace issues with multithreaded event handlers
# https://stackoverflow.com/questions/53788232/system-threading-timer-kills-the-powershell-console/53789011

Add-Type -TypeDefinition @'
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -54,7 +44,30 @@ public class RunspacedDelegateFactory
}
'@

$LanguagesSeparator = "\s+|;\s*|,\s*"
Add-Type -TypeDefinition @'
using System;
using System.Reflection;

public static class ReflectionHelper
{
public static void CallEnsurePluginRegistryIsCreated(Type fileBasedProjectType)
{
// Get the MethodInfo object for the private static method using BindingFlags
MethodInfo methodInfo = fileBasedProjectType.GetMethod(
"EnsurePluginRegistryIsCreated",
BindingFlags.NonPublic | BindingFlags.Static);

// Ensure the method has been found
if (methodInfo == null)
{
throw new InvalidOperationException("Could not find the method EnsurePluginRegistryIsCreated");
}

// Invoke the private static method
methodInfo.Invoke(null, null);
}
}
'@

$StudioVersionsMap = @{
Studio2 = "10.0.0.0"
Expand All @@ -63,23 +76,42 @@ $StudioVersionsMap = @{
Studio5 = "14.0.0.0"
Studio15 = "15.0.0.0"
Studio16 = "16.0.0.0"
Studio17 = "Studio17"
Studio18 = "Studio18"
}

function Get-DefaultProjectTemplate {
##########################################################################################################
# Due to API bug basing new projects on "Default.sdltpl" template instead of actual default project template,
# we need to find the real default template configured in Trados Studio by reading the configuration files
$StudioVersionAppData = $StudioVersionsMap[$StudioVersion]

# Get default project template GUID from the user settings file
$UserSettingsFilePath = "${Env:AppData}\SDL\SDL Trados Studio\$StudioVersionAppData\UserSettings.xml"
$DefaultProjectTemplateGuid = (Select-Xml -Path $UserSettingsFilePath -XPath "//Setting[@Id='DefaultProjectTemplateGuid']").Node.InnerText
# Get user's project templates and get the default one using the GUID
$ProjectTemplates = [Sdl.ProjectApi.ApplicationFactory]::CreateApplication().LocalProjectServers[0].ProjectTemplates
$DefaultProjectTemplate = ($ProjectTemplates | Where-Object -Property Guid -eq $DefaultProjectTemplateGuid).FilePath
[int] $_StudioVersion = $StudioVersion.Replace("Studio", "")
if ($_StudioVersion -gt 16)
{
[ReflectionHelper]::CallEnsurePluginRegistryIsCreated([Sdl.ProjectAutomation.FileBased.FileBasedProject])
$UserSettingsFilePath = "${Env:AppData}\Trados\Trados Studio\$StudioVersionAppData\UserSettings.xml"
$DefaultProjectTemplateGuid = (Select-Xml -Path $UserSettingsFilePath -XPath "//Setting[@Id='DefaultProjectTemplateGuid']").Node.InnerText
$application = [Sdl.ProjectApi.ApplicationFactory]::CreateApplication();
$provider = $application.AllProjectsProviders[0]
$projectTemplates = $application.GetProjectsProvider($provider, $null).ProjectTemplates
$DefaultProjectTemplate = ($ProjectTemplates | Where-Object -Property Guid -eq $DefaultProjectTemplateGuid).FilePath
}
else
{
$UserSettingsFilePath = "${Env:AppData}\SDL\SDL Trados Studio\$StudioVersionAppData\UserSettings.xml"
$DefaultProjectTemplateGuid = (Select-Xml -Path $UserSettingsFilePath -XPath "//Setting[@Id='DefaultProjectTemplateGuid']").Node.InnerText
$ProjectTemplates = [Sdl.ProjectApi.ApplicationFactory]::CreateApplication().LocalProjectServers[0].ProjectTemplates
$DefaultProjectTemplate = ($ProjectTemplates | Where-Object -Property Guid -eq $DefaultProjectTemplateGuid).FilePath
}

return $DefaultProjectTemplate
}

$LanguagesSeparator = "\s+|;\s*|,\s*"

function New-Project {
<#
.SYNOPSIS
Expand All @@ -101,13 +133,6 @@ Optionally also following tasks can be run:
- Pretranslate
- Analyze
.EXAMPLE
New-Project -Name "Project" -ProjectLocation "D:\Project" -SourceLocation "D:\Sources"

Creates project named "Project" based on default Trados Studio project template in "D:\Project" folder;
source files are taken from "D:\Sources" folder;
source language, target languages and translation memories are taken from the default project template;
only default Scan, Convert and Copy to target languages tasks are run.
.EXAMPLE
New-Project -Name "Project" -ProjectLocation "D:\Project" -SourceLocation "D:\Sources" -SourceLanguage "en-US" -TargetLanguages "fi-FI" -TMLocation "D:\TMs" -Pretranslate -Analyze

Creates project named "Project" based on default Trados Studio project template in "D:\Project" folder, with American English as source language and Finnish as target language; source files are taken from "D:\Sources" folder and translation memories are taken from "D:\TMs" folder; and runs Pretranslate and Analyze as additional tasks after scanning, converting and copying to target languages.
Expand Down Expand Up @@ -252,7 +277,14 @@ Analyze task is run after scanning, converting and copying to target languages.
}

# Crete new project using creation reference and constructed project info
$Project = New-Object Sdl.ProjectAutomation.FileBased.FileBasedProject ($ProjectInfo, $ProjectCreationReference)
if ($ProjectCreationReference)
{
$Project = New-Object Sdl.ProjectAutomation.FileBased.FileBasedProject ($ProjectInfo, $ProjectCreationReference)
}
else
{
$Project = New-Object Sdl.ProjectAutomation.FileBased.FileBasedProject ($projectInfo)
}

# Get project languages
$TargetLanguagesList = @($Project.GetProjectInfo().TargetLanguages.IsoAbbreviation)
Expand Down Expand Up @@ -1097,7 +1129,7 @@ function Validate-Task {

function Validate-TaskSequence {
param (
[Sdl.ProjectAutomation.FileBased.TaskSequence] $TaskSequenceToValidate
[Sdl.ProjectAutomation.Core.TaskSequence] $TaskSequenceToValidate
)

ForEach ($Task in $TaskSequenceToValidate.SubTasks) {
Expand All @@ -1108,11 +1140,11 @@ function Validate-TaskSequence {
Set-Alias -Name Pseudo -Value PseudoTranslate
Export-ModuleMember New-Project
Export-ModuleMember Get-Project
Export-ModuleMember Get-DefaultProjectTemplate
Export-ModuleMember Remove-Project
Export-ModuleMember ConvertTo-TradosLog
Export-ModuleMember Export-TargetFiles
Export-ModuleMember Update-MainTMs
Export-ModuleMember Update-MainTMs
Export-ModuleMember PseudoTranslate -Alias Pseudo
Export-ModuleMember Get-BilingualFileMappings
Export-ModuleMember Get-TaskFileInfoFiles
Export-ModuleMember Get-DefaultProjectTemplate
6 changes: 3 additions & 3 deletions Modules/TMHelper/TMHelper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ ModuleVersion = '1.0.0.0'
GUID = '{6ccd7a22-904b-4494-8795-88b1f41f0199}'

# Author of this module
Author = 'Patrik Mazanek'
Author = 'Trados AppStore Team'

# Company or vendor of this module
CompanyName = 'SDL'
CompanyName = 'SDL Limited as part of the RWS Holdings Plc group of companies'

# Copyright statement for this module
Copyright = '© 2011 SDL. All rights reserved.'
Copyright = 'Copyright © 2011 - 2022 SDL Limited as part of the RWS Holdings Plc group of companies (\"RWS Group\").'

# Description of the functionality provided by this module
Description = 'A PowerShell module to help SDL Translation Memories management'
Expand Down
Loading