ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.32k stars 382 forks source link

"Handlebars Intl" support #224

Closed nirmalbaldaniya-dream closed 6 years ago

nirmalbaldaniya-dream commented 6 years ago

Hi eric, I want to integrate localization support in my app. So I want to know that how can we use "handlebars Intl" in this?

nirmalbaldaniya-dream commented 6 years ago

I found the solution. It has been fixed by {{data.intl.messages.placeholder}}

SergioEnrique commented 5 years ago

Can you explain the full process of Handlebars Intl integration with express-handlebars? how can I registre the helpers in the main app.js? how the helpers can be used in my templates

SergioEnrique commented 5 years ago

Ok, I got the answer by myself

For those who want to use Handlebars Intl from https://formatjs.io/handlebars/

The code is as follows:

// app.js
import exphbs from 'express-handlebars'
import HandlebarsIntl from 'handlebars-intl'

const hbs = exphbs.create()

HandlebarsIntl.registerWith(hbs.handlebars)

app.set('view engine', 'handlebars')
app.engine('handlebars', hbs.engine)
/*
... your express code
*/
// template.handlebars using the formatNumber helper from Handlebars Intl
{{formatNumber 1000 style="currency" currency="USD"}}