Sha
Sha

Reputation: 1974

JS Report - Using $localizedResource inside JS function

I have a part of table like below.

<tr>
<td class='col-narrow'>{{$localizedResource.DATE}}</td>
<td class='col-narrow'>{{$localizedResource.TIME}}</td>
<td class='col-narrow'>{{$localizedResource.DAY}}</td>
</tr>
<tr>
<td class='col-narrow'>{{date}}</td>
<td class='col-narrow'>{{time}}</td>
<td class='col-narrow'>{{day}}</td> // need to translate this
</tr>

I need to translate the {{Day}} in different languages which i receive from api response. I have added the keys in the locales files for all the days and tried doing the below which unfortunately did not work

function translateKey(key){
    if(key){
    const message = key.toUpperCase();
    const newKey = this.$localizedresource.message;
    return newKey;
    }
}

and in the template i tried the following

 <td class='col-narrow'>{{ translateKey day}}</td>

Can anyone help me figure out the issue here

Upvotes: 0

Views: 164

Answers (1)

Jefferson Raposo
Jefferson Raposo

Reputation: 183

jsreport already has a function for that, try {{localize day "localization"}}, "localization" is the folder name of locale files

https://jsreport.net/learn/localization#documentation

Upvotes: 0

Related Questions