Displaying Entry Content
Display the full content of an entry in the Termbase Viewer window. This guide explains how to show the content of a glossary file line in Trados Studio.
Right-click a term in the Term Recognition or Termbase Search window and select View term details to display the full entry content in the Termbase Viewer window.
- Add an Internet Explorer control to display entry content in HTML format:
- Create a user control in your project named TermProviderControl.cs.
- Add an Internet Explorer control to the user control.
- Open the MyTerminologyProviderViewerWinFormsUI.cs class.
- Declare the following term controller object:
//Stores the glossary text file name and path
public readonly string fileName;
- Modify the TermProviderControl property (implemented by the ITerminologyProviderViewerWinFormsUI interface) as shown below to create and return the control element:
#region "ProviderSettings"
//Sets the terminology provider settings, i.e. in our implementation the glossary file name
public MyTerminologyProvider(string providerSettings)
{
fileName = providerSettings;
}
#endregion
#region "Definition"
When you right-click a term and select View term details, the corresponding entry content should appear in the newly created control.
Modify the JumpToTerm() method as shown below. Trados Studio passes the ID of the selected entry, which you can use to:
- Retrieve the corresponding line from the glossary text file.
- Parse the line and generate HTML output for the Internet Explorer control.
// this function outputs the full entry content in the Internet Explorer control
// of the Termbase Viewer window
public void JumpToTerm(Entry entry)
{
// Load the glossary file
string fileName = _terminologyProvider.fileName.Replace("file:///", "");
StreamReader glossaryFile = new StreamReader(fileName);
string[] chunks;
string entryContent = String.Empty;
glossaryFile.ReadLine();
// Loop through all lines of the file and find the line that has the current entry id
while (!glossaryFile.EndOfStream)
{
string thisLine = glossaryFile.ReadLine();
chunks = thisLine.Split(';');
string thisId = chunks[0];
if (thisId == entry.Id.ToString())
{
entryContent = thisLine;
break;
}
}
// Parse the line alongside the semi-colon
chunks = entryContent.Split(';');
// Generate a small HTML file to display in the Termbase Viewer control
string tmpFile = System.IO.Path.GetTempPath() + "simple_list_entry.htm";
StreamWriter previewFile = new StreamWriter(tmpFile);
previewFile.Write("<html><body><b>Entry id:</b> " + chunks[0] +
"<br/><b>Source term:</b> " + chunks[1] +
"<br/><b>Target term:</b> " + chunks[2] +
"<br/><b>Definition:</b> " + chunks[3] +
"</body></html>");
previewFile.Close();
termControl.SetNavigation(tmpFile);
glossaryFile.Close();
}