Search Results for

    Show / Hide Table of Contents

    Adding TM Fields

    This page shows how to add fields to a translation memory. For more information on what TM fields are and what their purpose is, please refer to Configuring Translation Memories.

    Add a New Class

    As we are going to implement the functionality for defining TM fields in a separate class, create a new class called TmFieldGenerator. Let us assume that you need to add a picklist field called Customer and a free text field called Project id. Picklist fields are always associated with a pre-defined list of values, which can later be selected as required at runtime. Text fields, on the other hand, can be filled with any text. Apart from picklist and text, fields can also be of the types number and date/time. However, since picklist and text fields constitute the most common types, we fill focus on those two.

    The first step is decide whether you want to configure a field as a free text field or a picklist field. Fields that should be associated with only a limited number of values that should be used consistently, will usually be of the type picklist. Common examples are Subject, Document type, Customer, etc. Free text fields should be used when at runtime there are virtually limitless possible values. Common examples here are Project id, Comment, etc.

    Start by adding a public function called AddFields, which takes the file path and name as string parameter. This function can be called as shown below:

    • C#
    var tmFieldGenerator = new TmFieldGenerator();
    tmFieldGenerator.AddFields(_translationMemoryFilePath);
    

    In the AddFields function start by opening the TM to which the fields should be added. Our first field should be called Customer, and should be of the type list. Create a list field object through the FieldDefinition class.

    Apply the ValueType property to define the field as a picklist that can hold multiple values. Finally, add two values, e.g. Microsoft and RWS:

    • C#
    var tm = new FileBasedTranslationMemory(tmPath);
    
    var listField = new FieldDefinition();
    listField.Name = "Customer";
    listField.ValueType = FieldValueType.MultiplePicklist;
    listField.PicklistItems.Add("RWS");
    listField.PicklistItems.Add("Microsoft");
    

    The second example should be a free text field, which we call Project id. Therefore, create a free text field object:

    • C#
    var textField = new FieldDefinition();
    textField.Name = "Project id";
    textField.ValueType = FieldValueType.MultipleString;
    

    Note that picklist and text fields can allow for only a single value or for multiple values, e.g. if a translation unit can be associated with several customers or project ids. In the above example we define the fields as multiple.

    Putting it All Together

    The complete class should now look as shown below:

    • C#
    namespace SDK.LanguagePlatform.Samples.TmAutomation
    {
        using Sdl.LanguagePlatform.TranslationMemory;
        using Sdl.LanguagePlatform.TranslationMemoryApi;
    
        public class TmFieldGenerator
        {
            #region "AddFields"
            public void AddFields(string tmPath)
            {
                #region "listField"
                var tm = new FileBasedTranslationMemory(tmPath);
    
                var listField = new FieldDefinition();
                listField.Name = "Customer";
                listField.ValueType = FieldValueType.MultiplePicklist;
                listField.PicklistItems.Add("RWS");
                listField.PicklistItems.Add("Microsoft");
                #endregion
    
                #region "textField"
                var textField = new FieldDefinition();
                textField.Name = "Project id";
                textField.ValueType = FieldValueType.MultipleString;
                #endregion
    
                #region "add"
                tm.FieldDefinitions.Add(listField);
                tm.FieldDefinitions.Add(textField);
                #endregion
    
                tm.Save();
            }
            #endregion
        }
    }
    

    See Also

    Configuring Translation Memories

    Creating a File-based Translation Memory

    TM Fields Templates

    • Improve this Doc
    In this article
    • Add a New Class
    • Putting it All Together
    • See Also
    Back to top Generated by DocFX