Use resources in helper



  • Hello I would like to translate with the resource system directly in a helper. In a function of a helper I make a return of an html code and I would like to translate according to the language pass in parameter via Api. Can you please show me an example that allows this kind of translation.
    cordially



  • Please try something like this if you use handlebars

    {{{helperA}}}
    
    function helperA() {
        return this.$localizedResource.message
    }
    

    The $localizedResource is a normal property available on the root data.



  • thank you for your response that help me well but I have another difficulty because I use the helper function inside a loop so this does not correspond and at resource level I have undefined how if you please i can fix this concern



  • the $localizedResource is just another prop on the templating engine root context.
    When you are inside a loop, you can reach it this way

    {{@root.$localizedResource.title}} 
    

    And just pass it as an argument to your helper call.


Log in to reply
 

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