Created
May 26, 2019 12:42
-
-
Save jkasaudhan/2be3fecf9696a88d1cfff7872dffadc3 to your computer and use it in GitHub Desktop.
Internationalization ListFormat api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// English version | |
const formatter = new Intl.ListFormat('en'); | |
formatter.format(['january', 'february', 'march']) | |
// january, february, and march | |
const formatterConj = new Intl.ListFormat('en', {type: 'conjunction'}); | |
// january, february, and march => by defaut type is 'conjunction' | |
const formatterDisj = new Intl.ListFormat('en', {type: 'disjunction'}); | |
formatterDisj.format(['january', 'february', 'march']) | |
formatterConj.format(['january', 'february', 'march']) | |
// january, february, or march | |
// For german version | |
const formatterde = new Intl.ListFormat('de'); | |
formatterde.format(['january', 'february', 'march']) | |
// january, february und march | |
const formatterConjDe = new Intl.ListFormat('de', {type: 'conjunction'}); | |
formatterConjDe.format(['january', 'february', 'march']) | |
// january, february und march => by defaut type is 'conjunction' | |
const formatterDisjDe = new Intl.ListFormat('de', {type: 'disjunction'}); | |
formatterDisjDe.format(['january', 'february', 'march']) | |
// january, february oder march | |
// It can be applied to any supported character for Eg. chinese characters | |
const lf = new Intl.ListFormat('zh'); | |
lf.format(['永鋒', '新宇', '芳遠']); | |
// 永鋒、新宇和芳遠 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment