Localize number formats

  • Hello. Please help to figure out how to localize number formats.
    I've tried to install handlebars-intl and apply it but it seems to be doesn't work.
    I've put into js

    var handlebars = require('handlebars');

    var HandlebarsIntl = require('handlebars-intl');

    and tried to apply it like

    {{#intl locales="fr-FR"}}
    <b>{{formatDate date day="numeric" month="long"}}</b>
    <i>("fr-FR" locale)</i>

    But whenever locale I use format didn't change. Please help to figure out.

  • The problem was with node.js is not including localization by default.
    I had to customize run script and add package to node
    My Dockefile looks like

    FROM jsreport/jsreport:2.6.0-full
    RUN npm i handlebars-intl full-icu --save
    COPY jsreport.config.json /app
    COPY package.json /app
    COPY run.sh /app

    Also I need to modify run.sh script to run node with supporting locales

    node --icu-data-dir=node_modules/full-icu "/app/server.js"

    After that locales start working. Hope it helps someone else

  • I didn't know Handlebars had intl support. Out of curiosity, does it also handle timezones?

    I made my own formatDate and formatNumber (with intl, moment and moment-timezone) to also take care of time-zones. All my dates are stored as UTC in the database, so I need to convert them to correct timezone in each report.

  • administrators

    @msageryd we did a quick test with this and it seems that it can handle timezones too, you just need to pass timeZone param to the formatDate, we are in the process to add to the docs the steps needed to have full Intl support.

    PD: your steps to add Intl support were really helpful, thanks for sharing

Log in to reply

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