formatjs / handlebars-intl

Handlebars helpers for internationalization.
http://formatjs.io/handlebars/
Other
265 stars 28 forks source link

Add support for `formatOptions` as a second arg to intlNumber/Date #23

Closed ericf closed 10 years ago

ericf commented 10 years ago

This allows for the following:

server.js:

var locales = ['en-US'], 
    formats = {
        number: {
            usd: {
                style   : 'currency',
                currency: 'USD'
            }
        }
    };

res.render({
    intl: {
        locales: locales,
        formats: formats
    }
});

template.hbs:

{{#intl locales=intl.locales formats=intl.formats}}
    {{intlNumber 1000 'usd'}}

    or

    {{intlNumber 1000 @intl.formats.number.usd}}
{{/intl}}
caridy commented 10 years ago

+1

drewfish commented 10 years ago

In your example I'm confused about where @intl.formats comes from. Is this something that is setup by the {{#intl}} block? Would @i18n.formats.number.usd have done the same thing?

caridy commented 10 years ago

@drewfish i18n is a context variable, and what is passed into the intl block is a member of it, so intlNumber doens't have access to that variable. Basically, {{#intl locales=i18n.locales formats=i18n.formats}} means we will have data.intl.formats as the entry point for @ references.

But it is true that you could do:

{{intlNumber 1000 i18n.formats.number.usd}}

without having to do the intl block (assuming the locales is in place)

drewfish commented 10 years ago

OK cool. It was just confusing having both intl and i18n and understanding the relationship between the two.

ericf commented 10 years ago

Okay, updated the example in the description to only use intl.