cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Decorator vs Translator

0 Kudos
1,027

Hi arvind-kumar-avinash and Experts,

Could you please assist me to understand the below, I have searched a lot of places to understand this. But I am not getting the exact answer.

  1. What is the exact difference between decorator and translator.
  2. Which is the best one to use in impex.

Thanks in Advance!

By,

HV

Accepted Solutions (1)

Accepted Solutions (1)

arvind-kumar_avinash
Active Contributor
0 Kudos

Q. What is the exact difference between decorator and translator?

Ans. The formal name of decorator is cellDecorator. As the name suggests, it can be used to decorate (e.g. append/prepend/trim some value) the value of an attribute before it is translated e.g. if you want to trim all trailing/leading zeros from the value of an attribute. Another example can be appending user's country name (e.g. _US or _UK) to the values of the uid attribute of an itemtype. It's like putting a marker/flag to an attribute for easily identifying and classifying the values.

As already mentioned above, the translation comes next to decoration (if any). A translator is used to translate the value of an attribute (which may have been decorated by using some decorator) to a new value e.g. encoding a password before storing it into the database.

Can I not simply use translator then?

Of course, you can i.e. whatever you accomplish using a decorator before the value is sent to a translator, can be done in the translator itself but having a decorator promotes reusability and gives you more control on processing the values e.g. you can plugin a decorator to a translator on a need basis. In presence of the decorator, first the decoration will happen and then the translation; while in absence of the decorator the translation will happen directly.

Q. Which is the best one to use in impex?

Ans. As mentioned above, they are not competing things; rather, they are the stages in the ImpEx process pipeline.

Check this chapter to learn more about them.

Hi arvind-kumar-avinash ,

Thank you so much for your detailed answer. Now I am clear.

Answers (0)