Skip to Content

Is there a way to use the i18n resource bundle inside a NodeJS service implementation?


I was wondering if there is any mechanism to make use of the i18n resource bundle defined in a CAP service, from inside a NodeJS based service implementation? Its usage would be similar to how resource bundles are used in SAPUI5 Javascript controllers and Components.


Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Apr 24 at 01:11 PM

    well, it kinda works in CAP (v 3.33.1) in NodeJS

    const i18n = require('@sap/cds/lib/models/i18n')
    var sBlubb = cds.localize({_i18nfolders:[__dirname + "/../_i18n"]}, "de", "\"{i18n>blubb}\"") 

    Note that the string MUST contain the double quotes around the binding {...} and the result also has the double quotes inside of the string

    Add a comment
    10|10000 characters needed characters exceeded

    • nice. I did a search but only ever found other localization packages based on different other formats for bundle files.

      I support the Idea that CAP should be using it internally. And definitely will give it a try myself (currently using a self-made wrapper including parametrizing messages a la formatMessage("hello {0}", ['world']))

  • Posted on Apr 10 at 12:35 AM

    You could try to use this npm package in your custom hook functions:

    Add a comment
    10|10000 characters needed characters exceeded

    • Thanks for sharing this info, Wouter! The package looks interesting and could offer an alternative solution. I was more interested in knowing about the possibilities of achieving the i18n usage using the existing locale setup offered in CAP.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.