Catching items that come back from translation

If you are reading this, you probably know that Tridion has an event system which allows you to attach your own custom functionality to pretty much everything that goes down. A typical example is to perform some pre-processing of an item before it is saved.

The customer I work for at the moment had just such a requirement. The only thing was: the pre-processing should only occur if the item in question was updated by SDL’s translation management system. The question is: how can one see that a ‘save’ action was triggered by TMS, and not by a regular user or some other system activity?

First, we looked at the name of the user who attempted the save. For the TMS this turned out to be the Tridion system user (commonly known as ‘MTSUser’). This made the username useless as a criteria, because there are more situations where the MTSUser performs a save.

With some help (thanks, Peter K) we figured it out. The TMS makes itself known in the session’s ContextData. Here’s what you do:

if (component.Session.ContextData.ContainsKey("TranslationManager"))
{
     // do your thing here!
}

That’s it! You can now write code which only executes when the action was triggered by the TMS.