Comments (4)
yeah, we want to improve the docs, thanks for the suggestions, we will look at it.
as for the locales, this is propagated down to the primitives defined in ECMA-402, more details here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation
Now, loading fr.js
locale data does not necessary means that we have data for locale fr
, that file might hold data for fr
and fr-CA
, since they have different rules. We don't want to provide data for every locale because it is relative small, even when we fold them by root locales. Here is an example of fr.js
:
IntlRelativeFormat.__addLocaleData({"locale":"fr","pluralRuleFunction":function (n) {var i=Math.floor(Math.abs(n));n=Math.floor(n);if(i===0||i===1)return"one";return"other";},"fields":{"second":{"displayName":"seconde","relative":{"0":"maintenant"},"relativeTime":{"future":{"one":"dans {0} seconde","other":"dans {0} secondes"},"past":{"one":"il y a {0} seconde","other":"il y a {0} secondes"}}},"minute":{"displayName":"minute","relativeTime":{"future":{"one":"dans {0} minute","other":"dans {0} minutes"},"past":{"one":"il y a {0} minute","other":"il y a {0} minutes"}}},"hour":{"displayName":"heure","relativeTime":{"future":{"one":"dans {0} heure","other":"dans {0} heures"},"past":{"one":"il y a {0} heure","other":"il y a {0} heures"}}},"day":{"displayName":"jour","relative":{"0":"aujourd’hui","1":"demain","2":"après-demain","-2":"avant-hier","-1":"hier"},"relativeTime":{"future":{"one":"dans {0} jour","other":"dans {0} jours"},"past":{"one":"il y a {0} jour","other":"il y a {0} jours"}}},"month":{"displayName":"mois","relative":{"0":"ce mois-ci","1":"le mois prochain","-1":"le mois dernier"},"relativeTime":{"future":{"one":"dans {0} mois","other":"dans {0} mois"},"past":{"one":"il y a {0} mois","other":"il y a {0} mois"}}},"year":{"displayName":"année","relative":{"0":"cette année","1":"l’année prochaine","-1":"l’année dernière"},"relativeTime":{"future":{"one":"dans {0} an","other":"dans {0} ans"},"past":{"one":"il y a {0} an","other":"il y a {0} ans"}}}}});
IntlRelativeFormat.__addLocaleData({"locale":"fr-ca","pluralRuleFunction":function (n) {var i=Math.floor(Math.abs(n));n=Math.floor(n);if(i===0||i===1)return"one";return"other";},"fields":{"second":{"displayName":"seconde","relative":{"0":"maintenant"},"relativeTime":{"future":{"one":"Dans {0} seconde","other":"Dans {0} secondes"},"past":{"one":"Il y a {0} seconde","other":"Il y a {0} secondes"}}},"minute":{"displayName":"minute","relativeTime":{"future":{"one":"Dans {0} minute","other":"Dans {0} minutes"},"past":{"one":"Il y a {0} minute","other":"Il y a {0} minutes"}}},"hour":{"displayName":"heure","relativeTime":{"future":{"one":"Dans {0} heure","other":"Dans {0} heures"},"past":{"one":"Il y a {0} heure","other":"Il y a {0} heures"}}},"day":{"displayName":"jour","relative":{"0":"aujourd’hui","1":"demain","2":"après-demain","-2":"avant-hier","-1":"hier"},"relativeTime":{"future":{"one":"Dans {0} jour","other":"Dans {0} jours"},"past":{"one":"Il y a {0} jour","other":"Il y a {0} jours"}}},"month":{"displayName":"mois","relative":{"0":"Ce mois-ci","1":"Le mois prochain","-1":"Le mois dernier"},"relativeTime":{"future":{"one":"Dans {0} mois","other":"Dans {0} mois"},"past":{"one":"Il y a {0} mois","other":"Il y a {0} mois"}}},"year":{"displayName":"année","relative":{"0":"Cette année","1":"L'année prochaine","-1":"L'année dernière"},"relativeTime":{"future":{"one":"Dans {0} an","other":"Dans {0} ans"},"past":{"one":"Il y a {0} an","other":"Il y a {0} ans"}}}}});
That's the reason why your application can use ['fr-CA', 'fr', 'us']
, which will be normalized under the hood to the best match, and it will pick up the right locale data to format the data.
from intl-messageformat.
to be clear, you normally don't need to worry much about this, and you just pass one locale in that array, and it will resolve the best match based on the locale data known by the library and the browser in case of primitives.
from intl-messageformat.
thanks
So i guess i'll only use one then :)
from intl-messageformat.
I will keep this open until we update the documentation.
from intl-messageformat.
Related Issues (20)
- Mustache (and Backbone) integration HOT 3
- Formatting dynamic lists? HOT 4
- Better way to display currently selected item from a list HOT 1
- How to use formatMessage API ? HOT 1
- Outdated browser support information in README
- values for 0
- Need default format for time Type HOT 1
- Support datetime type HOT 3
- JS Import, Webpack HOT 6
- Typescript typings HOT 1
- Allow passing date param in string format HOT 1
- Empty string in plural syntax throws error HOT 1
- Use Intl.PluralRules
- ES6 module for browser HOT 2
- Expose parentLocale info via public API HOT 3
- How can I output the 24 hour time format (14:00 instead 2:00 PM)? HOT 2
- If adding a judgement of environment variable can be better HOT 1
- Causing crash in production environment HOT 3
- How to define default value for context variables? HOT 2
- 3.0 - TypeError: Cannot read property 'parse' of undefined HOT 6
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 intl-messageformat.