Search Results for

    Show / Hide Table of Contents

    Adding TM Fields

    This page explains how to add fields to a translation memory. For background on TM fields and their purpose, see Configuring Translation Memories.

    Add a New Class

    Implement the field logic in a separate class named TmFieldGenerator. This example adds a picklist field named Customer and a free-text field named Project id. Picklist fields use a predefined list of values that you select at runtime. Text fields accept any value. TM fields can also use number and date/time types, but this example focuses on picklist and text fields because they are the most common.

    First decide whether the field should be a free-text field or a picklist field. Use picklist fields when you want to limit values to a consistent set, such as Subject, Document type, or Customer. Use free-text fields when the runtime values can vary widely, such as Project id or Comment.

    Add a public method named AddFields() that takes the TM file path as a string parameter. Call it as shown below:

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

    In the AddFields() method, open the TM to which you want to add the fields. Create the first field, Customer, as a picklist by using the FieldDefinition class.

    Set the ValueType property to define the field as a multiple picklist, and add two values such as 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");
    

    Create the second field, Project id, as a free-text field:

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

    Picklist and text fields can allow a single value or multiple values. Use multiple values when a translation unit can be associated with several customers or project IDs, as in this example.

    Putting it All Together

    The complete class should now look like this:

    • 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
    Back to top Generated by DocFX