Click or drag to resize
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, SDL 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.

Getting the Term Provider Languages
//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 override IList<ILanguage> GetLanguages()
{
    StreamReader _inFile = new StreamReader(fileName.Replace("file:///", ""));
    string[] languages = _inFile.ReadLine().Split(';');
    string srgLanguage = languages[1], trgLanguage = languages[2];
    string srcLabel = srgLanguage.Split(',')[0], srcLocale = srgLanguage.Split(',')[1];
    string trgLabel = trgLanguage.Split(',')[0], trgLocale = trgLanguage.Split(',')[1];
    _inFile.Close();

    var result = new List<IDefinitionLanguage>();

    var tbSrcLanguage = new DefinitionLanguage
    {
        Name = srcLabel,
        Locale = new System.Globalization.CultureInfo(srcLocale)
    };

    var tbTrgLanguage = new DefinitionLanguage
    {
        Name = trgLabel,
        Locale = new System.Globalization.CultureInfo(trgLocale)
    };


    result.Add(tbSrcLanguage);
    result.Add(tbTrgLanguage);

    return result.Cast<ILanguage>().ToList();
}

Note that you can add more than two languages. If SDL Trados Studio cannot assign the glossary languages automatically to the project languages, then the user has to pick the correct glossary language manually from the dropdown list.

project 01 selected languages

Community
Edit

Be the first to Edit the community content of this topic.
Comments