pdfCreatePagesGroup is not async-ready

  • I need to call i18Next to translate a parameter for my pdfCreatePagesGroup. As per suggestion from Jan I'm now instantiating i18next in a promise. It works superbly everywhere but not in pdfPagesGroup.

    pdfPagesGroup does not cope with async functions. In this case I could work around it by creating a special synchronous version of t(), since I know that i18Next has already been instantiated.

    Please make pdfPagesGroup handle async functions as well. It's a great concept to be able to use async helper functions.

    // title will be empty
    // title2 will get the correct translation
    {{{pdfCreatePagesGroup title=(t 'encasementList.title') title2=(tSync 'encasementList.title')}}}
    const i18next = require('i18next').createInstance()
    const initI18next = (i18nMeta) => i18next.init({
      //initialisation params..
    function tSync(key) {
      return i18next.t(key);
    async function t(key, options) {
      await initI18next(options.data.root.i18n);
      return i18next.t(key, options.hash);

  • It seems to be a problem with nested function calls as well.

    I have two helpers:

    • i18nLookup which takes a lookup section, a lookup key, and a field to get the translated value from
    • enclose which takes a value, a prefix and a suffix. If the value is blank, no prefix and suffix will be applied

    I want to lookup a language title by searching for a language code.

    Input: 'sv'
    Output: '(Swedish)'

    If the language title is not found I will get an empty string, i.e. not '()'

    {{enclose (i18nLookup 'languages' languageCode 'title') '(' ')'}}

    This does not work with async functions. Instead of the language title, I get '{#AsyncHelperResult ABCDEF}`.

  • Yes, our apologies.
    The helper's async implementation currently doesn't work well with nested helper calls or with async helper parameters.
    I submitted a task to our backlog to improve this.

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.