Setting the Source and Target Language
In this chapter you will learn how to retrieve and set the terminology provider source and target language.
How to read the source and target language from the glossary file header
Open the MyTerminologyProvider.cs class and go to the GetLanguages() function. Our implementation is based on the assumption that the first line in the text file contains the source and target language name and locale in the following form: 1;English,en-US;German,de-DE
The source and target language are separated with a semicolon, the language name and locale are comma-separated.
Modify the GetLanguages() function as shown below. In this function, we parse the first line of the text file to retrieve the language label (for example 'English') and the locale (for example 'en-US'). Based on the locale, Trados Studio assigns the glossary languages to the corresponding project language. After parsing the first line, the method creates two language objects which are added to the results list that the method returns.
//We parse the first line of the glossary text file to retrieve the the source and target language.
//Then we create two language objects that we return as source and target language to populate the
//termbase language dropdown lists in Studio.
public IList<ILanguage> GetLanguages()
{
StreamReader _inFile = new StreamReader(fileName.Replace("file:///", ""));
string[] languages = _inFile.ReadLine().Split(';');
string srgLanguage = languages[0], trgLanguage = languages[1];
string srcLabel = srgLanguage.Split(',')[0], srcLocale = srgLanguage.Split(',')[1];
string trgLabel = trgLanguage.Split(',')[0], trgLocale = trgLanguage.Split(',')[1];
_inFile.Close();
var result = new List<DefinitionLanguage>();
var tbSrcLanguage = new DefinitionLanguage
{
Name = srcLabel,
Locale = new Sdl.Core.Globalization.CultureCode(srcLocale)
};
var tbTrgLanguage = new DefinitionLanguage
{
Name = trgLabel,
Locale = new Sdl.Core.Globalization.CultureCode(trgLocale)
};
result.Add(tbSrcLanguage);
result.Add(tbTrgLanguage);
return result.Cast<ILanguage>().ToList();
}
Note that you can add more than two languages. If Trados Studio cannot assign the glossary languages automatically to the project languages, then you have to pick the correct glossary language manually from the dropdown list.
