How to update a Translation Unit programmatically - SDK example does not seem to work

Dear all,

I am trying to change the Origin value of some translation units in a file-based translation memory via the API but it is not working.

The Origin value is "TM" but it should be "Machine Translation". At the end of the message, you will see the code but this is what I am doing:

I am declaring a translation memory object ("tm")-> OK

Then I create a "tus" object with all the TUs from that TM (it is a small one) -> OK, I can read the TUs.

Then I loop through all TUs creating a translation unit object (tru). -> OK. At this stage I can read the values of the translation units one by one.

then I set the value of the Origin to MT: tru.Origin = TranslationUnitOrigin.MachineTranslation; OK. In the debugger, I can see that the value is updated. So far so good.

And now comes the problem. I then try to save this change to the translation memory using this line:

tm.LanguageDirection.UpdateTranslationUnit(tru);

Expected result: the changed values from the "tru" object are saved into the translation memory.

Actual result: the tru object is reverted to what it was before I changed it.

I must be missing somethin absurdly obvious but I am totally at loss here because I am doing the same that is shown in the SDK (https://developers.rws.com/studio-api-docs/apiconcepts/translationmemory/updating_a_translation_memory.html#edit-a-translation-unit) and the additional explanations included in this tutorial: 

  How to replace a Text with a Tag in Translation Memory 

The UpdateTranslationUnit retturns "Add (GUID)-OK".

I am using Studio 2021 SR1, in case it makes a difference. 

Daniel

PS. Here is the code I am using code:

var tm = new FileBasedTranslationMemory(translationMemoryPath);
var ri = new RegularIterator();

var tus = tm.LanguageDirection.GetTranslationUnits(ref ri);

foreach (TranslationUnit tru in tus)
{
tru.Origin = TranslationUnitOrigin.MachineTranslation;

tm.LanguageDirection.UpdateTranslationUnit(tru);
tm.Save();

};

emoji