Giter Site home page Giter Site logo

Comments (7)

ericf avatar ericf commented on June 18, 2024

You'll need to determine the user's locale, and conditionally load the Intl.js polyfill and its data for that locale:

http://formatjs.io/guide/#runtime-environments
http://formatjs.io/guide/#patch-runtime

from handlebars-intl.

bakura10 avatar bakura10 commented on June 18, 2024

The polyfill actually works as expected, because I load only "en". The problem comes when Intl is natively available, as it uses my locale (fr-FR) instead of en (that I want as a default as I didn't translate the app into French yet)

from handlebars-intl.

ericf avatar ericf commented on June 18, 2024

The details for how to set the locale when rendering a Handlebars template are specified here: http://formatjs.io/handlebars/

var intlData = {
    locales: 'en-US'
}

var context = {
    price: 1000
};

var html = template(context, {
    data: {intl: intlData}
});

If you can't specify the options when rendering the template for whatever reason, you can always use the {{#intl}} block helper to set the locale for part or all of the template by wrapping it with this helper. Details here: http://formatjs.io/handlebars/#intl

from handlebars-intl.

bakura10 avatar bakura10 commented on June 18, 2024

Hi,

Sorry for pinging you again, but I'm actually using this in context of an Ember app (side question: is there any Ember-CLI addon planned?). I've been able to successfully make bound helpers out of the Handlebars-Intl helper, but I have no idea about where am I suppose to write the configuration intl (like translation strings, date formats...). Obviously, I cannot use the template method you are saying to me, as I'm using only the Handlebars helpers in Handlebars template.

What I was looking for is: where am I supposed to write globally, in a file, all the string translations, date formats, locales... and having the library consumes it whenever I call the {{formatDate}}, {{formatMessage}}... helpers.

Sorry if this seems obvious, I've read several times the doc but cannot find it. I've looked at the code and couldn't find a place where I could set this.

from handlebars-intl.

ericf avatar ericf commented on June 18, 2024

An Ember integration is something we'd like to add, so that using FormatJS in Ember works out of the box and is more idiomatic Ember.

from handlebars-intl.

bakura10 avatar bakura10 commented on June 18, 2024

Thank you !

After more test, it appears the main problem is that the package does not give access to internal methods like simpleFormat. If I had access to those, I could easily write my own handlebars helpers and retrieve the local configs from my Ember config and automatically pass it as an option.

Right now, the simplest way is to not use this bundle and copy paste all the needed code, unless you have a better idea ? :)

from handlebars-intl.

ericf avatar ericf commented on June 18, 2024

We are considering the possibility of proving access to an intermediate library which wraps and caches Intl* instances and can do formatting — this lib would then be shared by the high-level FormatJS integration libs. But we're on the fence about it since we already provide the low-level packages.

from handlebars-intl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.