Comments (7)
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.
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.
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.
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.
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.
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.
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)
- bower package HOT 4
- How to change value after load ? HOT 2
- Issue with a plural in 'ru' locale HOT 1
- Support for padding currency values HOT 1
- intlGet: Print message path if it is undefined HOT 1
- Currency formatting incorrect when no 'cents' in value. HOT 1
- Invalid date
- How to capitalize month
- Dates interval with format long: do non repeat year
- handlebarsIntl is undefined
- Deprecate old NPM package HOT 4
- Using `formatMessage` in a loop construct
- formatNumber: only a number is accepted
- Currency style does not ensure trailing decimal digits HOT 1
- Why am I getting (US$) and not ($) HOT 6
- TypeError: Cannot read property 'escapeExpression' of undefined
- Express Handlebars support HOT 1
- Setting the locale of Handlebars Intl using Express HOT 4
- Noot noot
- Missing Variables Raise an Error and Cause the Entire Template to Fail to Render
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handlebars-intl.