Selecting the Glossary File
Learn how to select the delimited text file as a terminology provider for our implementation.
How to return the Term Provider URI, Name and Description
Open the MyTerminologyProvider.cs class. Add the following public string variable which stores the delimited text file name:
//Stores the glossary text file name and path
public readonly string fileName;
Modify the following members to return the term provider URI, which includes the text file name:
public Uri Uri
{
get
{
return new Uri(fileName);
}
}
Then add the following member, which allows us to pass any settings to the term provider. In our implementation, this will be the path to the glossary file:
//Sets the terminology provider settings, i.e. in our implementation the glossary file name
public MyTerminologyProvider(string providerSettings)
{
fileName = providerSettings;
}
Modify the two following members to return the term provider name and definition:
//Return the terminology provider name, uri, and description to show in the Studio UI
public string Description
{
get
{
return PluginResources.My_Terminology_Provider_Description;
}
}
public string Name
{
get
{
return PluginResources.My_Terminology_Provider_Name;
}
}
public Uri Uri
{
get
{
return new Uri(fileName);
}
}
public bool Initialize()
{
return true;
}
public bool Initialize(TerminologyProviderCredential credential)
{
return true;
}
public bool IsProviderUpToDate()
{
return true;
}
public IList<FilterDefinition> GetFilters()
{
return new List<FilterDefinition>();
}
public bool Uninitialize()
{
throw new NotImplementedException();
}
public string Id => "id";
public TerminologyProviderType Type => TerminologyProviderType.Custom;
public bool IsReadOnly => false;
public bool SearchEnabled => true;
public FilterDefinition ActiveFilter
{
get { return null; }
set { value = new FilterDefinition(); }
}
public bool IsInitialized => true;
How to select the Glossary File
Open the MyTerminologyProviderWinFormsUI.cs class and modify the Browse() method as shown below. This method allows you to raise the UI in which the user selects the text file, that is the Open File dialog box. Create a terminology provider object based on the MyTerminologyProvider class and set the fileName variable to the selected file name and path.
//Raises the File Open dialog in which the user selects the glossary text file.
//The file name and path is then passed to the terminology provider object.
public ITerminologyProvider[] Browse(IWin32Window owner, ITerminologyProviderCredentialStore credentialStore)
{
OpenFileDialog dlgOpenFile = new OpenFileDialog
{
Title = "Select list file",
Filter = "Delimited list files (*.txt)|*.txt"
};
dlgOpenFile.ShowDialog();
var result = new List<ITerminologyProvider>();
var _termProvider = new MyTerminologyProvider(dlgOpenFile.FileName);
result.Add(_termProvider);
return result.ToArray();
}
Go to the MyTerminologyProviderViewerWinFormsUI.cs class and create a terminology provider object. Make sure that your provider object is initialized as follows:
private MyTerminologyProvider _terminologyProvider;
public void Initialize(ITerminologyProvider terminologyProvider, CultureCode source, CultureCode target)
{
_terminologyProvider = (MyTerminologyProvider)terminologyProvider;
}
public bool Initialized
{
get
{
return true;
}
}
When selecting the text file, Trados Studio will try to retrieve the languages from the terminology list. As we have not implemented the corresponding functionality yet, simply change the GetLanguages() method of the MyTerminologyProvider.cs class to return null for the moment.
We will implement the required language retrieval functionality in the next chapter.
The Terminology Provider Factory Class
Open the class MyTerminologyProviderFactory.cs and create your term provider object as show below. Only then will Trados Studio be able to access and display your provider in the UI:
//Create the terminology provider and pass the provider uri, which is the glossary text file name and path
public ITerminologyProvider CreateTerminologyProvider(Uri terminologyProviderUri, ITerminologyProviderCredentialStore credentials)
{
MyTerminologyProvider _terminologyProvider = new MyTerminologyProvider(terminologyProviderUri.ToString());
return _terminologyProvider;
}