[SAPUI5] openui5-i18n-util a great tool for lazy developers to auto-magically fetch, build and manage traslations file
#tipoftheday will be a series of blog post that I’m mirroring from my Medium account.
Introduction
We all know, developers are pretty lazy, it’s a solid reality. That’s why I built openui5-i18n-util just for all of you (and me obviously)!
Lately I’m used to add directly i18n placeholder inside js/xml files without translating them everytime (because you perfectly know that translations will change dozen of times before release date).
So at some point, you are forced to take courage, a long cup of coffee mixed with patience and search each .xml view/dialog/fragment of your project and add every i18n entry to every damn language file. And than you have to search each .js file because you have also translations over there (don’t forget formatter too!).
This approch will save time at the start but it’s prone to errors and it will happen offten that you will miss some i18n string.
So I built an util script that will search all your i18n strings inside your project’s files and build auto-magically (while you’re drinking your deserved cup of coffe) every translations file for you.
Parameters, Parameters, Parameters!
I just want to take a moment to explain two parameters (the other ones are pretty much straightforward).
file-patterns: allows you to specify which files the script should parse to find i18n matches. You can specify them with wildcards combinations.
i18n-patterns: it’s a little bit trickier because it supports regular expression but it’s powerful. The default value is [‘{i18n>([^}]+)}’] that will parse common i18n strings inside your xml files. For istance, I’ve a BaseController that is extended by all Controllers. It offer an utility method called getTranslation: function (sKey, aParameters); that let you quickly get the i18n translation of the string. To also parse those i18n strings I’ve passed to the script this array as parameter [‘{i18n>([^}]+)}’, ‘\.getTranslation\(“([^”]+)”\)’]
Conclusion
I will keep working on the project adding some fancy feature and code examples. For every problem bug, don’t hesitate to create a pull/issue request.
There’s no better conclusion that a good (and deserved) huge cup of coffee.