Skip to Content
Technical Articles
Author's profile photo Facundo Ferrer

ui5-translator CLI tool

Hi everyone!

I’ve always found it frustrating to have to maintain several i18n files by hand. Maybe when you need to support 2 languages is not a big deal. But when you have to support 4 or more, you can easily add the entry on the main i18n file but forget to update the said entry on the other i18n languages.

With this in mind I created a nodejs based CLI ui5-translator tool to ease the developer experience.

Just to give a demonstration of it’s features I created a test project. project2 using the basic Project Template on BAS.

To begin, run the installer on the root of the UI5 Application project.
The CLI tool will look for the i18n file on ./webapp/i18n/i18n.properties

npm install -g @facuferrer86/ui5-translator


The CLI tools expects a list of target languages.
Also the source i18n file should be English.

ui5-translator spanish,german,italian

Note: The CLI tool looks for translations on 3 sources:

  1. Previously created i18n files with already translated entries.
  2. SAP Translation HUB.
  3. Google Translator.

If it can’t find the prior it will look it on the following source.

All languages on iso639-2 are supported.

Please do share feedbacks or thoughts in a comment section and feel free to follow me for more content updates.

Also, do follow SAPUI5 environment Topic page (https://community.sap.com/topics/ui5)

If you are interested in building your own CLI tools on nodejs look at:

https://dev.to/rushankhan1/build-a-cli-with-node-js-4jbi

 

–Edit 20/07/2023

I updated the library.

To get the latest version simply do:

npm update -g @facuferrer86/ui5-translator

I removed the dependency on https://www.npmjs.com/package/@vitalets/google-translate-api and replaced it with https://www.npmjs.com/package/google-translate-api-x

Also, all translations are now executed in bulk rather than in series. I was reaching a threshold of too many calls, so I now call once every 60 seconds. It’s slower.. but effective.

 

 

Assigned Tags

      14 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Yogesh Gupta
      Yogesh Gupta

      Hi Facundo,

      Thanks for publishing such informative blog.

      However when I'm trying to execute the mentioned commands I'm getting below error.

      bash: ui5-translator: command not found

      Any suggestions, how to overcome it?

      Author's profile photo Santiago González
      Santiago González

      Hi Yogesh,

      Try to install it with -g or else run it npx ui5-translator... 

      Hope it helps you

      Author's profile photo Yogesh Gupta
      Yogesh Gupta

      Thanks Santiago, it works now.

      Author's profile photo Facundo Ferrer
      Facundo Ferrer
      Blog Post Author

      Thanks Santiago for noticing! I just modified the post to reflect this

      npm install -g @facuferrer86/ui5-translator

       

      Author's profile photo Volker Buzek
      Volker Buzek

      excellent helper! maybe you could align the translation process with the similarly cut ui5 tooling task https://github.com/ui5-community/ui5-ecosystem-showcase/tree/main/packages/ui5-task-i18ncheck - then we‘d have both a cli and a task working by the same principle!

      Author's profile photo Facundo Ferrer
      Facundo Ferrer
      Blog Post Author

      I like that idea very much. I'll look into it!

      Author's profile photo Wolfgang Röckelein
      Wolfgang Röckelein

      There is also already https://blogs.sap.com/2021/01/21/ui5-tooling-custom-task-using-sap-translation-hub-for-i18n-of-ui5-apps/ and https://github.com/DerGuteWolf/ui5-task-translationhub

      Author's profile photo Rewati Raman
      Rewati Raman

      Hi @Facundo Ferrer,

       

      I am getting below error while using this module.

       

      Best Regards,

      Rewati

      Author's profile photo Facundo Ferrer
      Facundo Ferrer
      Blog Post Author

      Hi Rewati,

      So the cli uses under the hood this library @vitalets/google-translate-api. It seems that the response format has changed, there is an open issue on the library about it.

      https://github.com/vitalets/google-translate-api/issues/117

      Author's profile photo Rewati Raman
      Rewati Raman

      Thanks @Facundo for your response.

      Author's profile photo Facundo Ferrer
      Facundo Ferrer
      Blog Post Author

      Since the owner of the library did not fix the issue yet.. I moved to a different library. You can update the library version by doing "npm update -g @facuferrer86/ui5-translator". Hope it helps.

      Author's profile photo Niharika tammineni
      Niharika tammineni

      Hi,

      I am getting below error while executing the above commands. any leads would be helpful

      Author's profile photo Facundo Ferrer
      Facundo Ferrer
      Blog Post Author

      Hi @Niharika tammineni you may try updating the library by doing npm update -g @facuferrer86/ui5-translator and then try again. If the error continues to ocurr, please post the status of the response. My guess it that it was a 423 error code. Which happens when an api is called too many times. I've implemented a bulk feature and a sleep mechanism which should take care of this error.

       

      Best regards,

      Facundo

      Author's profile photo Bhaskar Kuntla
      Bhaskar Kuntla

      Hello Facundo,

      I am getting below error while executing the ui5-translator. Even i tried the same by changing it to npm update -g @facuferrer86/ui5-translator. Could you please check the issue. Thank you.

      user: testapp $ ui5-translator spanish,german,italian
      [ 'spanish,german,italian' ]

      /home/user/.node_modules_global/lib/node_modules/@facuferrer86/ui5-translator/node_modules/google-translate-api-x/lib/defaults.cjs:9
      requestFunction(url, fetchinit) { return fetch(url, fetchinit); },
      ^

      ReferenceError: fetch is not defined
      at Object.requestFunction (/home/user/.node_modules_global/lib/node_modules/@facuferrer86/ui5-translator/node_modules/google-translate-api-x/lib/defaults.cjs:9:36)
      at module.exports (/home/user/.node_modules_global/lib/node_modules/@facuferrer86/ui5-translator/node_modules/google-translate-api-x/lib/translation/batchTranslate.cjs:87:17)
      at module.exports (/home/user/.node_modules_global/lib/node_modules/@facuferrer86/ui5-translator/node_modules/google-translate-api-x/lib/translate.cjs:16:9)
      at googleTranslateMap (file:///home/user/.node_modules_global/lib/node_modules/@facuferrer86/ui5-translator/bin/utils.js:70:35)
      at file:///home/user/.node_modules_global/lib/node_modules/@facuferrer86/ui5-translator/bin/index.js:57:41
      at processTicksAndRejections (node:internal/process/task_queues:96:5)