Comments (10)
@yamsellem it is in the "render" tab on every example here: http://formatjs.io/handlebars/#formatMessage
you will see something like this:
var intlData = {
"locales": "en-US",
"messages": {
"photos": "{name} took {numPhotos, plural,\n =0 {no photos}\n =1 {one photo}\n other {# photos}\n} on {takenDate, date, long}.\n"
}
};
var html = template(context, {
data: {intl: intlData}
});
where context
is:
var context = {
name : 'Annie',
numPhotos: 1000,
takenDate: Date.now()
};
from handlebars-intl.
Hi @caridy, thanks for your feedback.
I was talking about a global setup, something to avoid repeating the intl
data all around the place.
Something like: HandlebarsIntl.registerMessages(..)
.
To be honest, this is not realistic, in a web app, to require the messages
everywhere it's needed. We need to isolate this responsibility in one single place.
ps. the intl.messages
attributes is not shown a single time on the docs but it can be found in the github readme ;-). Maybe merging those two docs will help.
from handlebars-intl.
@yamsellem I'm pretty sure intlGet
looks for the message in the Handlebars context.
from handlebars-intl.
@juandopazo if it does, that still implies providing messages
every time, which is not realistic, don't you think?
from handlebars-intl.
Right. Caridy had answered correctly. I see your point now. In the server it's easy to add the messages in a centralized fashion, but it's not so clear how to do it in the client.
from handlebars-intl.
@juandopazo Cool, we're on the same page ;-).
Maybe someone else has an idea of how to do this client side, maybe it needs a patch?
Thanks again.
ps. by curiosity, how will you do this server side?
from handlebars-intl.
@yamsellem you call render once for the top level template, you pass the data
object, which is propagated thru all partials, there is not need to pass that anywhere else, only when calling render on your top level template.
If you want to have more control on the message resolution process, you can simply ignore getIntl
helper, and implement your own helper to locate your messages, there is nothing extraordinary about getIntl
, it just returns a string.
from handlebars-intl.
as for the centralized messages, it is not recommended, especially if you're doing isomorphic apps since the resolution of messages happens per request on the server.
from handlebars-intl.
@yamsellem checkout the "RENDER" tab on this example:
http://formatjs.io/handlebars/#formatMessage
from handlebars-intl.
@ericf my bad, it is there — well hidden, but there ;-).
Still, the issue remains on client-side templating — a global configuration is a must have.
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.