Skip to content

Commit 64c7757

Browse files
committed
Add sample for creating an empty TM from another reusing only the language resources
1 parent a9da97b commit 64c7757

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Sdl.LanguagePlatform.TranslationMemoryApi;
2+
using System.Collections.Generic;
3+
4+
namespace StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources
5+
{
6+
public class Program
7+
{
8+
private static void Main(string[] args)
9+
{
10+
var originalTm = new FileBasedTranslationMemory("filePath");
11+
12+
var langResBundleList = new List<LanguageResourceBundle>();
13+
foreach (var bundle in originalTm.LanguageResourceBundles)
14+
{
15+
langResBundleList.Add(bundle.Clone());
16+
}
17+
18+
var tmCreator = new TmCreator();
19+
20+
var newTm = tmCreator.CreateFileBasedTm("destFileName");
21+
langResBundleList.ForEach(b => newTm.LanguageResourceBundles.Add(b));
22+
23+
newTm.Save();
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources")]
9+
[assembly: AssemblyProduct("StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources")]
10+
[assembly: AssemblyCopyright("Copyright © 2020")]
11+
12+
// Setting ComVisible to false makes the types in this assembly not visible
13+
// to COM components. If you need to access a type in this assembly from
14+
// COM, set the ComVisible attribute to true on that type.
15+
[assembly: ComVisible(false)]
16+
17+
// The following GUID is for the ID of the typelib if this project is exposed to COM
18+
[assembly: Guid("fdb17e01-04fa-4821-bb12-c38a271133ef")]
19+
20+
// Version information for an assembly consists of the following four values:
21+
//
22+
// Major Version
23+
// Minor Version
24+
// Build Number
25+
// Revision
26+
//
27+
// You can specify all the values or you can default the Build and Revision Numbers
28+
// by using the '*' as shown below:
29+
// [assembly: AssemblyVersion("1.0.*")]
30+
[assembly: AssemblyVersion("1.0.0.0")]
31+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{FDB17E01-04FA-4821-BB12-C38A271133EF}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources</RootNamespace>
10+
<AssemblyName>StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<PropertyGroup>
37+
<StartupObject />
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="Sdl.Core.Globalization">
41+
<SpecificVersion>False</SpecificVersion>
42+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\Sdl.Core.Globalization.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Sdl.Core.Settings">
45+
<SpecificVersion>False</SpecificVersion>
46+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\Sdl.Core.Settings.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Sdl.LanguagePlatform.Core">
49+
<SpecificVersion>False</SpecificVersion>
50+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\Sdl.LanguagePlatform.Core.dll</HintPath>
51+
</Reference>
52+
<Reference Include="Sdl.LanguagePlatform.TranslationMemory">
53+
<SpecificVersion>False</SpecificVersion>
54+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\Sdl.LanguagePlatform.TranslationMemory.dll</HintPath>
55+
</Reference>
56+
<Reference Include="Sdl.LanguagePlatform.TranslationMemoryApi">
57+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17Sdl.LanguagePlatform.TranslationMemoryApi.dll</HintPath>
58+
</Reference>
59+
<Reference Include="Sdl.ProjectAutomation.Core">
60+
<SpecificVersion>False</SpecificVersion>
61+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\Sdl.ProjectAutomation.Core.dll</HintPath>
62+
</Reference>
63+
<Reference Include="Sdl.ProjectAutomation.FileBased">
64+
<SpecificVersion>False</SpecificVersion>
65+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\Sdl.ProjectAutomation.FileBased.dll</HintPath>
66+
</Reference>
67+
<Reference Include="Sdl.ProjectAutomation.Settings">
68+
<SpecificVersion>False</SpecificVersion>
69+
<HintPath>$(MSBuildProgramFiles32)\Trados\Trados Studio\Studio17\Sdl.ProjectAutomation.Settings.dll</HintPath>
70+
</Reference>
71+
<Reference Include="System" />
72+
<Reference Include="System.Core" />
73+
<Reference Include="System.Xml.Linq" />
74+
<Reference Include="System.Data.DataSetExtensions" />
75+
<Reference Include="Microsoft.CSharp" />
76+
<Reference Include="System.Data" />
77+
<Reference Include="System.Net.Http" />
78+
<Reference Include="System.Xml" />
79+
</ItemGroup>
80+
<ItemGroup>
81+
<Compile Include="Program.cs" />
82+
<Compile Include="Properties\AssemblyInfo.cs" />
83+
<Compile Include="TmCreator.cs" />
84+
</ItemGroup>
85+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
86+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33424.131
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources", "StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources.csproj", "{FDB17E01-04FA-4821-BB12-C38A271133EF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{FDB17E01-04FA-4821-BB12-C38A271133EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FDB17E01-04FA-4821-BB12-C38A271133EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FDB17E01-04FA-4821-BB12-C38A271133EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FDB17E01-04FA-4821-BB12-C38A271133EF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {515BD5EB-98CA-48B1-9784-0EC7E867C5D2}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Sdl.LanguagePlatform.TranslationMemoryApi;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Sdl.LanguagePlatform.Core.Tokenization;
9+
using Sdl.LanguagePlatform.TranslationMemory;
10+
11+
namespace StandAlone_CreateEmptyFileBasedTMFromAnother_UsingSameResources
12+
{
13+
public class TmCreator
14+
{
15+
16+
public FileBasedTranslationMemory CreateFileBasedTm(string tmPath)
17+
{
18+
FileBasedTranslationMemory tm = new FileBasedTranslationMemory(
19+
tmPath,
20+
"This is a sample TM",
21+
CultureInfo.GetCultureInfo("en-US"),
22+
CultureInfo.GetCultureInfo("de-DE"),
23+
this.GetFuzzyIndexes(),
24+
this.GetRecognizers(),
25+
TokenizerFlags.BreakOnDash | TokenizerFlags.BreakOnHyphen | TokenizerFlags.BreakOnApostrophe,
26+
WordCountFlags.BreakOnTag | WordCountFlags.BreakOnHyphen | WordCountFlags.BreakOnApostrophe | WordCountFlags.BreakOnDash
27+
);
28+
29+
tm.LanguageResourceBundles.Clear();
30+
tm.Save();
31+
return tm;
32+
}
33+
34+
private FuzzyIndexes GetFuzzyIndexes()
35+
{
36+
return FuzzyIndexes.SourceCharacterBased |
37+
FuzzyIndexes.SourceWordBased |
38+
FuzzyIndexes.TargetCharacterBased |
39+
FuzzyIndexes.TargetWordBased;
40+
}
41+
42+
private BuiltinRecognizers GetRecognizers()
43+
{
44+
return BuiltinRecognizers.RecognizeAcronyms |
45+
BuiltinRecognizers.RecognizeDates |
46+
BuiltinRecognizers.RecognizeNumbers |
47+
BuiltinRecognizers.RecognizeTimes |
48+
BuiltinRecognizers.RecognizeVariables |
49+
BuiltinRecognizers.RecognizeMeasurements |
50+
BuiltinRecognizers.RecognizeAlphaNumeric;
51+
}
52+
53+
}
54+
}

0 commit comments

Comments
 (0)