In the following tutorial it will be explained how to add a concept to a existing local termbase using MultiTerm SDK.
Sdl.MultiTerm.TMO.Interop vs Sdl.MultiTerm.Client.Api
MultiTerm Client is a newer API which might contain some improvements but this dll is private.
Tthis means it cannot be used in a plugin. When a plugin which uses a nonpublic api is used in Studio a error message appears when Studio is loaded. This client is recomanded to be used for standalone applications.
"Sdl.MultiTerm.Client.Api" is not a full replacement for the "Sdl.MultiTerm.TMO.Interop"
Sdl.MultiTerm.TMO.Interop is a public api, and it can be used in a plugin.
Full sample code can be found on SDL Community GitHub Repository.
How to load a local Termbase and get the Entries using Sdl.MultiTerm.TMO.Interop
First of all you need to add a reference to MultiTerm Interop library.
var multiTermApplication = new Application();
var localRep = multiTermApplication.LocalRepository;
var termbases = localRep.Termbases;
var path = termbasePath;
termbases.Add(path, "", "");
var termbase = termbases[path];
var entries = termbase.Entries;
How to add a new entry to a local Termbase
To add new entries to a termbase, you first need to 'construct' the entry XML content to store in the termbase. Below you see a simplified example of what a MultiTerm XML entry can look like:
<conceptGrp> <languageGrp> <language type="English" lang="EN"/> <termGrp> <term>Sdl Community Wiki</term> </termGrp> </languageGrp> </conceptGrp>
Example of concept content for 2 languages
<language type="English" lang="en-US" />
<language type="French" lang="fr-FR" />
What is Termbase Language Index and why do we need to use it
In the above XML example we see the language type is set to "English". Termbase Language index give us the Language Name which correspond to all language flavours.
For example English (Unites States) and English (Australia) will have the same language Index "English".
In the bellow example we'll use the Display Name of the language to create a entry.
Following error will appear when we try to add the concept:
How to get the Termbase Language index list
From the active project we can take the TermbaseConfiguration for Default Termbase set in project settings.
var projectsController = SdlTradosStudio.Application.GetController<ProjectsController>();
var activeProject = projectsController?.CurrentProject;
var termbaseConfiguration = activeProject?.GetTermbaseConfiguration();
var languageIndexes = termbaseConfiguration.LanguageIndexes;
In order to get the corresponding TermbaseLanguage index for a language we can use following example:
How to get entries number for each language
1. Using Studio context
After getting the Language Index (see the method "GetTermbaseIndex" from the previews print screen), you should be able to get the entries number for each language using the below code:
var numberOfLanguageEntries = termbase.Information.NumberOfEntriesInIndex["languageIndex"];
2. Using Standalone application
The Code sample can be found on the SDL GitHub public repository, unde the Code samples folder.
On the appstore.sdl.com site, it can be accessed the Multiterm Desktop SDK.
The number of term entries can be accessed similar with the plugin's side, based on the language index:
- Get the termabase
- Get the termbase information: var termbaseInformation = termbase.Information;
- Get the Indexes from termbase.Definition.Indexes (each index corresponds to one language)
- Use the Language value from each index to retrieve the number of terms entry : termbaseInformation.NumberOfEntriesInIndex(languageIndex.Language)