Last week I’ve decided to translate my QVTo transformation to Portuguese. I’m preparing an experiment that uses this transformation, and my subjects are Brazilian students. So it wouldn’t be appropriate to have English texts in the obtained transformation. It would be a silly independent variable to consider…
So, how can I make my transformation outputs a Portuguese text? A simple solution would be to copy my existent code and just translate it. Easy… But an horrible solution. If I ever change my transformation code, due to this solution I would have to change in 2 places instead of just one. It’s the common “copy-paste in maintenance” problem.
So, how can I create an elegant localization solution? Using the Dictionary type defined in the QVTo Standard Library (defined in the QVT standard), I decided to use the following solution:
- Create 2 dictionaries: one for English text and one for Portuguese text.
- Create a “configuration property” so the user can select the language without touching the transformation code.
- Create a query that returns the message asked, considering the selected dictionary.
- Create a library for this localization query, separating it to my original code.