Programmatic import not working when specifying TM fields

I am trying to import an SDL XLIFF file into a file TM that has the TM fields Status (single value list field) and Project (multiple string text field) defined. The import works fine without adding any field values in the import settings.

 

When I add only the Project field (and not the Status field), then the import is done, but the field values are not added. When I add the Status field, the import is not done, i.e. the TM stays empty.

Any ideas?      

 private void DoImport()

        {

            FileBasedTranslationMemory tm = new FileBasedTranslationMemory(@"c:\test\test.sdltm");

            TranslationMemoryImporter import = new TranslationMemoryImporter(tm.LanguageDirection);

            import.ImportSettings.ProjectSettings = GetProjectSettings();         

            import.ImportSettings = GetImportSettings();

            import.Import(@"c:\test\test.sdlxliff");

            Application.Exit();

        }

 

        private ImportSettings GetImportSettings()

        {

            ImportSettings settings = new ImportSettings();

                return settings;

        }

 

        private FieldValues GetProjectSettings()

        {

            FieldValues _fieldValues = new FieldValues();

            SinglePicklistFieldValue _status = new SinglePicklistFieldValue("Status");

            _status.Add("Approved");

            MultipleStringFieldValue _project = new MultipleStringFieldValue("Project");

            _status.Add("12345");

            _fieldValues.Add(_status); // when this field is added, TM stays empty after import

            _fieldValues.Add(_project); // when this field is added (i.e. only Project, not Status), then the units are imported, but without field values

            return _fieldValues;

        }

  • Hi Ziad,

    I never really worked with file-based TMs and therefore do not know if they work the same as server TMs. I have also not work with SinglePicklist but the following is working for me:

    FieldValues tuFields = new FieldValues();

    //Looping through the passed field list and creating defintions with values

    foreach (KeyValuePair<string, string> aField in fieldList)

    {

    FieldDefinition tuFieldDef = importTM.FieldsTemplate.FieldDefinitions.First(fd => fd.Name == aField.Key);

    FieldValue tuFieldVal = tuFieldDef.CreateValue();

    tuFieldVal.Add(aField.Value);

    tuFields.Add(tuFieldVal);

    }

    importer.ImportSettings.ProjectSettings = tuFields;

    I am not creating the field definition from scratch but retrieving it from the TM in which I want to import. I then use the CreateValue function for the specified field. Maybe this might help, even if you create your TM at import.

    I also noticed that you call your GetImportSettings function after you call the GetProjectSettings function. Isn't there a risk that you reset your field definition by proceeding in this order?

    Regards,

    Laurent