@formatjs/intl-pluralrules 5.0.1 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BUILD +465 -0
- package/CHANGELOG.md +659 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/abstract/GetOperands.ts +75 -0
- package/abstract/InitializePluralRules.ts +61 -0
- package/abstract/ResolvePlural.ts +47 -0
- package/get_internal_slots.ts +14 -0
- package/index.ts +174 -0
- package/package.json +8 -4
- package/polyfill-force.ts +8 -0
- package/polyfill.ts +11 -0
- package/scripts/cldr-raw.ts +70 -0
- package/scripts/cldr.ts +29 -0
- package/scripts/test262-main-gen.ts +28 -0
- package/should-polyfill.ts +21 -0
- package/supported-locales.generated.ts +1 -0
- package/test262-main.ts +1071 -0
- package/tests/index.test.ts +57 -0
- package/{locale-data/en.js → tests/locale-data/en.ts} +3 -4
- package/{locale-data/fr.js → tests/locale-data/fr.ts} +3 -4
- package/tests/locale-data/zh.ts +6 -0
- package/tests/supported-locales-of.test.ts +23 -0
- package/tsconfig.json +5 -0
- package/abstract/GetOperands.d.ts +0 -32
- package/abstract/GetOperands.d.ts.map +0 -1
- package/abstract/GetOperands.js +0 -50
- package/abstract/InitializePluralRules.d.ts +0 -9
- package/abstract/InitializePluralRules.d.ts.map +0 -1
- package/abstract/InitializePluralRules.js +0 -21
- package/abstract/ResolvePlural.d.ts +0 -13
- package/abstract/ResolvePlural.d.ts.map +0 -1
- package/abstract/ResolvePlural.js +0 -27
- package/get_internal_slots.d.ts +0 -3
- package/get_internal_slots.d.ts.map +0 -1
- package/get_internal_slots.js +0 -12
- package/index.d.ts +0 -21
- package/index.d.ts.map +0 -1
- package/index.js +0 -141
- package/lib/abstract/GetOperands.d.ts +0 -32
- package/lib/abstract/GetOperands.d.ts.map +0 -1
- package/lib/abstract/GetOperands.js +0 -46
- package/lib/abstract/InitializePluralRules.d.ts +0 -9
- package/lib/abstract/InitializePluralRules.d.ts.map +0 -1
- package/lib/abstract/InitializePluralRules.js +0 -17
- package/lib/abstract/ResolvePlural.d.ts +0 -13
- package/lib/abstract/ResolvePlural.d.ts.map +0 -1
- package/lib/abstract/ResolvePlural.js +0 -23
- package/lib/get_internal_slots.d.ts +0 -3
- package/lib/get_internal_slots.d.ts.map +0 -1
- package/lib/get_internal_slots.js +0 -9
- package/lib/index.d.ts +0 -21
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -138
- package/lib/polyfill-force.d.ts +0 -2
- package/lib/polyfill-force.d.ts.map +0 -1
- package/lib/polyfill-force.js +0 -7
- package/lib/polyfill.d.ts +0 -2
- package/lib/polyfill.d.ts.map +0 -1
- package/lib/polyfill.js +0 -10
- package/lib/should-polyfill.d.ts +0 -2
- package/lib/should-polyfill.d.ts.map +0 -1
- package/lib/should-polyfill.js +0 -18
- package/lib/supported-locales.d.ts +0 -2
- package/lib/supported-locales.d.ts.map +0 -1
- package/lib/supported-locales.js +0 -2
- package/locale-data/af.d.ts +0 -1
- package/locale-data/af.js +0 -8
- package/locale-data/ak.d.ts +0 -1
- package/locale-data/ak.js +0 -8
- package/locale-data/am.d.ts +0 -1
- package/locale-data/am.js +0 -8
- package/locale-data/an.d.ts +0 -1
- package/locale-data/an.js +0 -8
- package/locale-data/ar.d.ts +0 -1
- package/locale-data/ar.js +0 -14
- package/locale-data/ars.d.ts +0 -1
- package/locale-data/ars.js +0 -14
- package/locale-data/as.d.ts +0 -1
- package/locale-data/as.js +0 -12
- package/locale-data/asa.d.ts +0 -1
- package/locale-data/asa.js +0 -8
- package/locale-data/ast.d.ts +0 -1
- package/locale-data/ast.js +0 -9
- package/locale-data/az.d.ts +0 -1
- package/locale-data/az.js +0 -12
- package/locale-data/bal.d.ts +0 -1
- package/locale-data/bal.js +0 -7
- package/locale-data/be.d.ts +0 -1
- package/locale-data/be.js +0 -12
- package/locale-data/bem.d.ts +0 -1
- package/locale-data/bem.js +0 -8
- package/locale-data/bez.d.ts +0 -1
- package/locale-data/bez.js +0 -8
- package/locale-data/bg.d.ts +0 -1
- package/locale-data/bg.js +0 -8
- package/locale-data/bho.d.ts +0 -1
- package/locale-data/bho.js +0 -8
- package/locale-data/bm.d.ts +0 -1
- package/locale-data/bm.js +0 -7
- package/locale-data/bn.d.ts +0 -1
- package/locale-data/bn.js +0 -12
- package/locale-data/bo.d.ts +0 -1
- package/locale-data/bo.js +0 -7
- package/locale-data/br.d.ts +0 -1
- package/locale-data/br.js +0 -13
- package/locale-data/brx.d.ts +0 -1
- package/locale-data/brx.js +0 -8
- package/locale-data/bs.d.ts +0 -1
- package/locale-data/bs.js +0 -11
- package/locale-data/ca.d.ts +0 -1
- package/locale-data/ca.js +0 -12
- package/locale-data/ce.d.ts +0 -1
- package/locale-data/ce.js +0 -8
- package/locale-data/ceb.d.ts +0 -1
- package/locale-data/ceb.js +0 -9
- package/locale-data/cgg.d.ts +0 -1
- package/locale-data/cgg.js +0 -8
- package/locale-data/chr.d.ts +0 -1
- package/locale-data/chr.js +0 -8
- package/locale-data/ckb.d.ts +0 -1
- package/locale-data/ckb.js +0 -8
- package/locale-data/cs.d.ts +0 -1
- package/locale-data/cs.js +0 -12
- package/locale-data/cy.d.ts +0 -1
- package/locale-data/cy.js +0 -18
- package/locale-data/da.d.ts +0 -1
- package/locale-data/da.js +0 -9
- package/locale-data/de.d.ts +0 -1
- package/locale-data/de.js +0 -9
- package/locale-data/doi.d.ts +0 -1
- package/locale-data/doi.js +0 -8
- package/locale-data/dsb.d.ts +0 -1
- package/locale-data/dsb.js +0 -12
- package/locale-data/dv.d.ts +0 -1
- package/locale-data/dv.js +0 -8
- package/locale-data/dz.d.ts +0 -1
- package/locale-data/dz.js +0 -7
- package/locale-data/ee.d.ts +0 -1
- package/locale-data/ee.js +0 -8
- package/locale-data/el.d.ts +0 -1
- package/locale-data/el.js +0 -8
- package/locale-data/en.d.ts +0 -1
- package/locale-data/eo.d.ts +0 -1
- package/locale-data/eo.js +0 -8
- package/locale-data/es.d.ts +0 -1
- package/locale-data/es.js +0 -11
- package/locale-data/et.d.ts +0 -1
- package/locale-data/et.js +0 -9
- package/locale-data/eu.d.ts +0 -1
- package/locale-data/eu.js +0 -8
- package/locale-data/fa.d.ts +0 -1
- package/locale-data/fa.js +0 -8
- package/locale-data/ff.d.ts +0 -1
- package/locale-data/ff.js +0 -8
- package/locale-data/fi.d.ts +0 -1
- package/locale-data/fi.js +0 -9
- package/locale-data/fil.d.ts +0 -1
- package/locale-data/fil.js +0 -9
- package/locale-data/fo.d.ts +0 -1
- package/locale-data/fo.js +0 -8
- package/locale-data/fr.d.ts +0 -1
- package/locale-data/fur.d.ts +0 -1
- package/locale-data/fur.js +0 -8
- package/locale-data/fy.d.ts +0 -1
- package/locale-data/fy.js +0 -9
- package/locale-data/ga.d.ts +0 -1
- package/locale-data/ga.js +0 -13
- package/locale-data/gd.d.ts +0 -1
- package/locale-data/gd.js +0 -15
- package/locale-data/gl.d.ts +0 -1
- package/locale-data/gl.js +0 -9
- package/locale-data/gsw.d.ts +0 -1
- package/locale-data/gsw.js +0 -8
- package/locale-data/gu.d.ts +0 -1
- package/locale-data/gu.js +0 -12
- package/locale-data/guw.d.ts +0 -1
- package/locale-data/guw.js +0 -8
- package/locale-data/gv.d.ts +0 -1
- package/locale-data/gv.js +0 -13
- package/locale-data/ha.d.ts +0 -1
- package/locale-data/ha.js +0 -8
- package/locale-data/haw.d.ts +0 -1
- package/locale-data/haw.js +0 -8
- package/locale-data/he.d.ts +0 -1
- package/locale-data/he.js +0 -12
- package/locale-data/hi.d.ts +0 -1
- package/locale-data/hi.js +0 -12
- package/locale-data/hnj.d.ts +0 -1
- package/locale-data/hnj.js +0 -7
- package/locale-data/hr.d.ts +0 -1
- package/locale-data/hr.js +0 -11
- package/locale-data/hsb.d.ts +0 -1
- package/locale-data/hsb.js +0 -12
- package/locale-data/hu.d.ts +0 -1
- package/locale-data/hu.js +0 -8
- package/locale-data/hy.d.ts +0 -1
- package/locale-data/hy.js +0 -8
- package/locale-data/ia.d.ts +0 -1
- package/locale-data/ia.js +0 -9
- package/locale-data/id.d.ts +0 -1
- package/locale-data/id.js +0 -7
- package/locale-data/ig.d.ts +0 -1
- package/locale-data/ig.js +0 -7
- package/locale-data/ii.d.ts +0 -1
- package/locale-data/ii.js +0 -7
- package/locale-data/io.d.ts +0 -1
- package/locale-data/io.js +0 -9
- package/locale-data/is.d.ts +0 -1
- package/locale-data/is.js +0 -9
- package/locale-data/it.d.ts +0 -1
- package/locale-data/it.js +0 -11
- package/locale-data/iu.d.ts +0 -1
- package/locale-data/iu.js +0 -10
- package/locale-data/ja.d.ts +0 -1
- package/locale-data/ja.js +0 -7
- package/locale-data/jbo.d.ts +0 -1
- package/locale-data/jbo.js +0 -7
- package/locale-data/jgo.d.ts +0 -1
- package/locale-data/jgo.js +0 -8
- package/locale-data/jmc.d.ts +0 -1
- package/locale-data/jmc.js +0 -8
- package/locale-data/jv.d.ts +0 -1
- package/locale-data/jv.js +0 -7
- package/locale-data/jw.d.ts +0 -1
- package/locale-data/jw.js +0 -7
- package/locale-data/ka.d.ts +0 -1
- package/locale-data/ka.js +0 -11
- package/locale-data/kab.d.ts +0 -1
- package/locale-data/kab.js +0 -8
- package/locale-data/kaj.d.ts +0 -1
- package/locale-data/kaj.js +0 -8
- package/locale-data/kcg.d.ts +0 -1
- package/locale-data/kcg.js +0 -8
- package/locale-data/kde.d.ts +0 -1
- package/locale-data/kde.js +0 -7
- package/locale-data/kea.d.ts +0 -1
- package/locale-data/kea.js +0 -7
- package/locale-data/kk.d.ts +0 -1
- package/locale-data/kk.js +0 -9
- package/locale-data/kkj.d.ts +0 -1
- package/locale-data/kkj.js +0 -8
- package/locale-data/kl.d.ts +0 -1
- package/locale-data/kl.js +0 -8
- package/locale-data/km.d.ts +0 -1
- package/locale-data/km.js +0 -7
- package/locale-data/kn.d.ts +0 -1
- package/locale-data/kn.js +0 -8
- package/locale-data/ko.d.ts +0 -1
- package/locale-data/ko.js +0 -7
- package/locale-data/ks.d.ts +0 -1
- package/locale-data/ks.js +0 -8
- package/locale-data/ksb.d.ts +0 -1
- package/locale-data/ksb.js +0 -8
- package/locale-data/ksh.d.ts +0 -1
- package/locale-data/ksh.js +0 -10
- package/locale-data/ku.d.ts +0 -1
- package/locale-data/ku.js +0 -8
- package/locale-data/kw.d.ts +0 -1
- package/locale-data/kw.js +0 -16
- package/locale-data/ky.d.ts +0 -1
- package/locale-data/ky.js +0 -8
- package/locale-data/lag.d.ts +0 -1
- package/locale-data/lag.js +0 -11
- package/locale-data/lb.d.ts +0 -1
- package/locale-data/lb.js +0 -8
- package/locale-data/lg.d.ts +0 -1
- package/locale-data/lg.js +0 -8
- package/locale-data/lij.d.ts +0 -1
- package/locale-data/lij.js +0 -9
- package/locale-data/lkt.d.ts +0 -1
- package/locale-data/lkt.js +0 -7
- package/locale-data/ln.d.ts +0 -1
- package/locale-data/ln.js +0 -8
- package/locale-data/lo.d.ts +0 -1
- package/locale-data/lo.js +0 -8
- package/locale-data/lt.d.ts +0 -1
- package/locale-data/lt.js +0 -12
- package/locale-data/lv.d.ts +0 -1
- package/locale-data/lv.js +0 -11
- package/locale-data/mas.d.ts +0 -1
- package/locale-data/mas.js +0 -8
- package/locale-data/mg.d.ts +0 -1
- package/locale-data/mg.js +0 -8
- package/locale-data/mgo.d.ts +0 -1
- package/locale-data/mgo.js +0 -8
- package/locale-data/mk.d.ts +0 -1
- package/locale-data/mk.js +0 -12
- package/locale-data/ml.d.ts +0 -1
- package/locale-data/ml.js +0 -8
- package/locale-data/mn.d.ts +0 -1
- package/locale-data/mn.js +0 -8
- package/locale-data/mo.d.ts +0 -1
- package/locale-data/mo.js +0 -11
- package/locale-data/mr.d.ts +0 -1
- package/locale-data/mr.js +0 -11
- package/locale-data/ms.d.ts +0 -1
- package/locale-data/ms.js +0 -8
- package/locale-data/mt.d.ts +0 -1
- package/locale-data/mt.js +0 -12
- package/locale-data/my.d.ts +0 -1
- package/locale-data/my.js +0 -7
- package/locale-data/nah.d.ts +0 -1
- package/locale-data/nah.js +0 -8
- package/locale-data/naq.d.ts +0 -1
- package/locale-data/naq.js +0 -10
- package/locale-data/nb.d.ts +0 -1
- package/locale-data/nb.js +0 -8
- package/locale-data/nd.d.ts +0 -1
- package/locale-data/nd.js +0 -8
- package/locale-data/ne.d.ts +0 -1
- package/locale-data/ne.js +0 -9
- package/locale-data/nl.d.ts +0 -1
- package/locale-data/nl.js +0 -9
- package/locale-data/nn.d.ts +0 -1
- package/locale-data/nn.js +0 -8
- package/locale-data/nnh.d.ts +0 -1
- package/locale-data/nnh.js +0 -8
- package/locale-data/no.d.ts +0 -1
- package/locale-data/no.js +0 -8
- package/locale-data/nqo.d.ts +0 -1
- package/locale-data/nqo.js +0 -7
- package/locale-data/nr.d.ts +0 -1
- package/locale-data/nr.js +0 -8
- package/locale-data/nso.d.ts +0 -1
- package/locale-data/nso.js +0 -8
- package/locale-data/ny.d.ts +0 -1
- package/locale-data/ny.js +0 -8
- package/locale-data/nyn.d.ts +0 -1
- package/locale-data/nyn.js +0 -8
- package/locale-data/om.d.ts +0 -1
- package/locale-data/om.js +0 -8
- package/locale-data/or.d.ts +0 -1
- package/locale-data/or.js +0 -13
- package/locale-data/os.d.ts +0 -1
- package/locale-data/os.js +0 -8
- package/locale-data/osa.d.ts +0 -1
- package/locale-data/osa.js +0 -7
- package/locale-data/pa.d.ts +0 -1
- package/locale-data/pa.js +0 -8
- package/locale-data/pap.d.ts +0 -1
- package/locale-data/pap.js +0 -8
- package/locale-data/pcm.d.ts +0 -1
- package/locale-data/pcm.js +0 -8
- package/locale-data/pl.d.ts +0 -1
- package/locale-data/pl.js +0 -12
- package/locale-data/prg.d.ts +0 -1
- package/locale-data/prg.js +0 -11
- package/locale-data/ps.d.ts +0 -1
- package/locale-data/ps.js +0 -8
- package/locale-data/pt-PT.d.ts +0 -1
- package/locale-data/pt-PT.js +0 -11
- package/locale-data/pt.d.ts +0 -1
- package/locale-data/pt.js +0 -11
- package/locale-data/rm.d.ts +0 -1
- package/locale-data/rm.js +0 -8
- package/locale-data/ro.d.ts +0 -1
- package/locale-data/ro.js +0 -11
- package/locale-data/rof.d.ts +0 -1
- package/locale-data/rof.js +0 -8
- package/locale-data/ru.d.ts +0 -1
- package/locale-data/ru.js +0 -12
- package/locale-data/rwk.d.ts +0 -1
- package/locale-data/rwk.js +0 -8
- package/locale-data/sah.d.ts +0 -1
- package/locale-data/sah.js +0 -7
- package/locale-data/saq.d.ts +0 -1
- package/locale-data/saq.js +0 -8
- package/locale-data/sat.d.ts +0 -1
- package/locale-data/sat.js +0 -10
- package/locale-data/sc.d.ts +0 -1
- package/locale-data/sc.js +0 -9
- package/locale-data/scn.d.ts +0 -1
- package/locale-data/scn.js +0 -9
- package/locale-data/sd.d.ts +0 -1
- package/locale-data/sd.js +0 -8
- package/locale-data/sdh.d.ts +0 -1
- package/locale-data/sdh.js +0 -8
- package/locale-data/se.d.ts +0 -1
- package/locale-data/se.js +0 -10
- package/locale-data/seh.d.ts +0 -1
- package/locale-data/seh.js +0 -8
- package/locale-data/ses.d.ts +0 -1
- package/locale-data/ses.js +0 -7
- package/locale-data/sg.d.ts +0 -1
- package/locale-data/sg.js +0 -7
- package/locale-data/sh.d.ts +0 -1
- package/locale-data/sh.js +0 -11
- package/locale-data/shi.d.ts +0 -1
- package/locale-data/shi.js +0 -11
- package/locale-data/si.d.ts +0 -1
- package/locale-data/si.js +0 -9
- package/locale-data/sk.d.ts +0 -1
- package/locale-data/sk.js +0 -12
- package/locale-data/sl.d.ts +0 -1
- package/locale-data/sl.js +0 -12
- package/locale-data/sma.d.ts +0 -1
- package/locale-data/sma.js +0 -10
- package/locale-data/smi.d.ts +0 -1
- package/locale-data/smi.js +0 -10
- package/locale-data/smj.d.ts +0 -1
- package/locale-data/smj.js +0 -10
- package/locale-data/smn.d.ts +0 -1
- package/locale-data/smn.js +0 -10
- package/locale-data/sms.d.ts +0 -1
- package/locale-data/sms.js +0 -10
- package/locale-data/sn.d.ts +0 -1
- package/locale-data/sn.js +0 -8
- package/locale-data/so.d.ts +0 -1
- package/locale-data/so.js +0 -8
- package/locale-data/sq.d.ts +0 -1
- package/locale-data/sq.js +0 -11
- package/locale-data/sr.d.ts +0 -1
- package/locale-data/sr.js +0 -11
- package/locale-data/ss.d.ts +0 -1
- package/locale-data/ss.js +0 -8
- package/locale-data/ssy.d.ts +0 -1
- package/locale-data/ssy.js +0 -8
- package/locale-data/st.d.ts +0 -1
- package/locale-data/st.js +0 -8
- package/locale-data/su.d.ts +0 -1
- package/locale-data/su.js +0 -7
- package/locale-data/sv.d.ts +0 -1
- package/locale-data/sv.js +0 -9
- package/locale-data/sw.d.ts +0 -1
- package/locale-data/sw.js +0 -9
- package/locale-data/syr.d.ts +0 -1
- package/locale-data/syr.js +0 -8
- package/locale-data/ta.d.ts +0 -1
- package/locale-data/ta.js +0 -8
- package/locale-data/te.d.ts +0 -1
- package/locale-data/te.js +0 -8
- package/locale-data/teo.d.ts +0 -1
- package/locale-data/teo.js +0 -8
- package/locale-data/th.d.ts +0 -1
- package/locale-data/th.js +0 -7
- package/locale-data/ti.d.ts +0 -1
- package/locale-data/ti.js +0 -8
- package/locale-data/tig.d.ts +0 -1
- package/locale-data/tig.js +0 -8
- package/locale-data/tk.d.ts +0 -1
- package/locale-data/tk.js +0 -9
- package/locale-data/tl.d.ts +0 -1
- package/locale-data/tl.js +0 -9
- package/locale-data/tn.d.ts +0 -1
- package/locale-data/tn.js +0 -8
- package/locale-data/to.d.ts +0 -1
- package/locale-data/to.js +0 -7
- package/locale-data/tpi.d.ts +0 -1
- package/locale-data/tpi.js +0 -7
- package/locale-data/tr.d.ts +0 -1
- package/locale-data/tr.js +0 -8
- package/locale-data/ts.d.ts +0 -1
- package/locale-data/ts.js +0 -8
- package/locale-data/tzm.d.ts +0 -1
- package/locale-data/tzm.js +0 -9
- package/locale-data/ug.d.ts +0 -1
- package/locale-data/ug.js +0 -8
- package/locale-data/uk.d.ts +0 -1
- package/locale-data/uk.js +0 -12
- package/locale-data/und.d.ts +0 -1
- package/locale-data/und.js +0 -7
- package/locale-data/ur.d.ts +0 -1
- package/locale-data/ur.js +0 -9
- package/locale-data/uz.d.ts +0 -1
- package/locale-data/uz.js +0 -8
- package/locale-data/ve.d.ts +0 -1
- package/locale-data/ve.js +0 -8
- package/locale-data/vi.d.ts +0 -1
- package/locale-data/vi.js +0 -8
- package/locale-data/vo.d.ts +0 -1
- package/locale-data/vo.js +0 -8
- package/locale-data/vun.d.ts +0 -1
- package/locale-data/vun.js +0 -8
- package/locale-data/wa.d.ts +0 -1
- package/locale-data/wa.js +0 -8
- package/locale-data/wae.d.ts +0 -1
- package/locale-data/wae.js +0 -8
- package/locale-data/wo.d.ts +0 -1
- package/locale-data/wo.js +0 -7
- package/locale-data/xh.d.ts +0 -1
- package/locale-data/xh.js +0 -8
- package/locale-data/xog.d.ts +0 -1
- package/locale-data/xog.js +0 -8
- package/locale-data/yi.d.ts +0 -1
- package/locale-data/yi.js +0 -9
- package/locale-data/yo.d.ts +0 -1
- package/locale-data/yo.js +0 -7
- package/locale-data/yue.d.ts +0 -1
- package/locale-data/yue.js +0 -7
- package/locale-data/zh.d.ts +0 -1
- package/locale-data/zh.js +0 -7
- package/locale-data/zu.d.ts +0 -1
- package/locale-data/zu.js +0 -8
- package/polyfill-force.d.ts +0 -2
- package/polyfill-force.d.ts.map +0 -1
- package/polyfill-force.js +0 -9
- package/polyfill.d.ts +0 -2
- package/polyfill.d.ts.map +0 -1
- package/polyfill.iife.js +0 -2753
- package/polyfill.js +0 -12
- package/should-polyfill.d.ts +0 -2
- package/should-polyfill.d.ts.map +0 -1
- package/should-polyfill.js +0 -22
- package/supported-locales.d.ts +0 -2
- package/supported-locales.d.ts.map +0 -1
- package/supported-locales.js +0 -5
package/LICENSE.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {invariant, ToNumber} from '@formatjs/ecma402-abstract'
|
|
2
|
+
|
|
3
|
+
export interface OperandsRecord {
|
|
4
|
+
/**
|
|
5
|
+
* Absolute value of the source number (integer and decimals)
|
|
6
|
+
*/
|
|
7
|
+
Number: number
|
|
8
|
+
/**
|
|
9
|
+
* Number of digits of `number`
|
|
10
|
+
*/
|
|
11
|
+
IntegerDigits: number
|
|
12
|
+
/**
|
|
13
|
+
* Number of visible fraction digits in [[Number]], with trailing zeroes.
|
|
14
|
+
*/
|
|
15
|
+
NumberOfFractionDigits: number
|
|
16
|
+
/**
|
|
17
|
+
* Number of visible fraction digits in [[Number]], without trailing zeroes.
|
|
18
|
+
*/
|
|
19
|
+
NumberOfFractionDigitsWithoutTrailing: number
|
|
20
|
+
/**
|
|
21
|
+
* Number of visible fractional digits in [[Number]], with trailing zeroes.
|
|
22
|
+
*/
|
|
23
|
+
FractionDigits: number
|
|
24
|
+
/**
|
|
25
|
+
* Number of visible fractional digits in [[Number]], without trailing zeroes.
|
|
26
|
+
*/
|
|
27
|
+
FractionDigitsWithoutTrailing: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-getoperands
|
|
32
|
+
* @param s
|
|
33
|
+
*/
|
|
34
|
+
export function GetOperands(s: string): OperandsRecord {
|
|
35
|
+
invariant(
|
|
36
|
+
typeof s === 'string',
|
|
37
|
+
`GetOperands should have been called with a string`
|
|
38
|
+
)
|
|
39
|
+
const n = ToNumber(s)
|
|
40
|
+
invariant(isFinite(n), 'n should be finite')
|
|
41
|
+
let dp = s.indexOf('.')
|
|
42
|
+
let iv: string | number
|
|
43
|
+
let f: number
|
|
44
|
+
let v: number
|
|
45
|
+
let fv = ''
|
|
46
|
+
if (dp === -1) {
|
|
47
|
+
iv = n
|
|
48
|
+
f = 0
|
|
49
|
+
v = 0
|
|
50
|
+
} else {
|
|
51
|
+
iv = s.slice(0, dp)
|
|
52
|
+
fv = s.slice(dp, s.length)
|
|
53
|
+
f = ToNumber(fv)
|
|
54
|
+
v = fv.length
|
|
55
|
+
}
|
|
56
|
+
const i = Math.abs(ToNumber(iv))
|
|
57
|
+
let w: number
|
|
58
|
+
let t: number
|
|
59
|
+
if (f !== 0) {
|
|
60
|
+
const ft = fv.replace(/0+$/, '')
|
|
61
|
+
w = ft.length
|
|
62
|
+
t = ToNumber(ft)
|
|
63
|
+
} else {
|
|
64
|
+
w = 0
|
|
65
|
+
t = 0
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
Number: n,
|
|
69
|
+
IntegerDigits: i,
|
|
70
|
+
NumberOfFractionDigits: v,
|
|
71
|
+
NumberOfFractionDigitsWithoutTrailing: w,
|
|
72
|
+
FractionDigits: f,
|
|
73
|
+
FractionDigitsWithoutTrailing: t,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PluralRulesInternal,
|
|
3
|
+
PluralRulesData,
|
|
4
|
+
CanonicalizeLocaleList,
|
|
5
|
+
CoerceOptionsToObject,
|
|
6
|
+
GetOption,
|
|
7
|
+
SetNumberFormatDigitOptions,
|
|
8
|
+
} from '@formatjs/ecma402-abstract'
|
|
9
|
+
import {ResolveLocale} from '@formatjs/intl-localematcher'
|
|
10
|
+
|
|
11
|
+
export function InitializePluralRules(
|
|
12
|
+
pl: Intl.PluralRules,
|
|
13
|
+
locales: string | string[] | undefined,
|
|
14
|
+
options: Intl.PluralRulesOptions | undefined,
|
|
15
|
+
{
|
|
16
|
+
availableLocales,
|
|
17
|
+
relevantExtensionKeys,
|
|
18
|
+
localeData,
|
|
19
|
+
getDefaultLocale,
|
|
20
|
+
getInternalSlots,
|
|
21
|
+
}: {
|
|
22
|
+
availableLocales: Set<string>
|
|
23
|
+
relevantExtensionKeys: string[]
|
|
24
|
+
localeData: Record<string, PluralRulesData | undefined>
|
|
25
|
+
getDefaultLocale(): string
|
|
26
|
+
getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal
|
|
27
|
+
}
|
|
28
|
+
) {
|
|
29
|
+
const requestedLocales = CanonicalizeLocaleList(locales)
|
|
30
|
+
const opt: any = Object.create(null)
|
|
31
|
+
const opts = CoerceOptionsToObject<Intl.PluralRulesOptions>(options)
|
|
32
|
+
const internalSlots = getInternalSlots(pl)
|
|
33
|
+
internalSlots.initializedPluralRules = true
|
|
34
|
+
const matcher = GetOption(
|
|
35
|
+
opts,
|
|
36
|
+
'localeMatcher',
|
|
37
|
+
'string',
|
|
38
|
+
['best fit', 'lookup'],
|
|
39
|
+
'best fit'
|
|
40
|
+
)
|
|
41
|
+
opt.localeMatcher = matcher
|
|
42
|
+
internalSlots.type = GetOption(
|
|
43
|
+
opts,
|
|
44
|
+
'type',
|
|
45
|
+
'string',
|
|
46
|
+
['cardinal', 'ordinal'],
|
|
47
|
+
'cardinal'
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, 'standard')
|
|
51
|
+
const r = ResolveLocale(
|
|
52
|
+
availableLocales,
|
|
53
|
+
requestedLocales,
|
|
54
|
+
opt,
|
|
55
|
+
relevantExtensionKeys,
|
|
56
|
+
localeData,
|
|
57
|
+
getDefaultLocale
|
|
58
|
+
)
|
|
59
|
+
internalSlots.locale = r.locale
|
|
60
|
+
return pl
|
|
61
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Type,
|
|
3
|
+
invariant,
|
|
4
|
+
PluralRulesInternal,
|
|
5
|
+
LDMLPluralRule,
|
|
6
|
+
FormatNumericToString,
|
|
7
|
+
} from '@formatjs/ecma402-abstract'
|
|
8
|
+
import {GetOperands, OperandsRecord} from './GetOperands'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
|
|
12
|
+
* @param pl
|
|
13
|
+
* @param n
|
|
14
|
+
* @param PluralRuleSelect Has to pass in bc it's implementation-specific
|
|
15
|
+
*/
|
|
16
|
+
export function ResolvePlural(
|
|
17
|
+
pl: Intl.PluralRules,
|
|
18
|
+
n: number,
|
|
19
|
+
{
|
|
20
|
+
getInternalSlots,
|
|
21
|
+
PluralRuleSelect,
|
|
22
|
+
}: {
|
|
23
|
+
getInternalSlots(pl: Intl.PluralRules): PluralRulesInternal
|
|
24
|
+
PluralRuleSelect: (
|
|
25
|
+
locale: string,
|
|
26
|
+
type: 'cardinal' | 'ordinal',
|
|
27
|
+
n: number,
|
|
28
|
+
operands: OperandsRecord
|
|
29
|
+
) => LDMLPluralRule
|
|
30
|
+
}
|
|
31
|
+
): LDMLPluralRule {
|
|
32
|
+
const internalSlots = getInternalSlots(pl)
|
|
33
|
+
invariant(Type(internalSlots) === 'Object', 'pl has to be an object')
|
|
34
|
+
invariant(
|
|
35
|
+
'initializedPluralRules' in internalSlots,
|
|
36
|
+
'pluralrules must be initialized'
|
|
37
|
+
)
|
|
38
|
+
invariant(Type(n) === 'Number', 'n must be a number')
|
|
39
|
+
if (!isFinite(n)) {
|
|
40
|
+
return 'other'
|
|
41
|
+
}
|
|
42
|
+
const {locale, type} = internalSlots
|
|
43
|
+
const res = FormatNumericToString(internalSlots, n)
|
|
44
|
+
const s = res.formattedString
|
|
45
|
+
const operands = GetOperands(s)
|
|
46
|
+
return PluralRuleSelect(locale, type, n, operands)
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Type-only circular import
|
|
2
|
+
// eslint-disable-next-line import/no-cycle
|
|
3
|
+
import {PluralRules, PluralRulesInternal} from '.'
|
|
4
|
+
|
|
5
|
+
const internalSlotMap = new WeakMap<PluralRules, PluralRulesInternal>()
|
|
6
|
+
|
|
7
|
+
export default function getInternalSlots(x: PluralRules): PluralRulesInternal {
|
|
8
|
+
let internalSlots = internalSlotMap.get(x)
|
|
9
|
+
if (!internalSlots) {
|
|
10
|
+
internalSlots = Object.create(null) as PluralRulesInternal
|
|
11
|
+
internalSlotMap.set(x, internalSlots)
|
|
12
|
+
}
|
|
13
|
+
return internalSlots
|
|
14
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LDMLPluralRule,
|
|
3
|
+
PluralRulesLocaleData,
|
|
4
|
+
PluralRulesData,
|
|
5
|
+
SupportedLocales,
|
|
6
|
+
NumberFormatDigitInternalSlots,
|
|
7
|
+
ToNumber,
|
|
8
|
+
CanonicalizeLocaleList,
|
|
9
|
+
} from '@formatjs/ecma402-abstract'
|
|
10
|
+
import {OperandsRecord} from './abstract/GetOperands'
|
|
11
|
+
import {InitializePluralRules} from './abstract/InitializePluralRules'
|
|
12
|
+
import {ResolvePlural} from './abstract/ResolvePlural'
|
|
13
|
+
import getInternalSlots from './get_internal_slots'
|
|
14
|
+
|
|
15
|
+
function validateInstance(instance: any, method: string) {
|
|
16
|
+
if (!(instance instanceof PluralRules)) {
|
|
17
|
+
throw new TypeError(
|
|
18
|
+
`Method Intl.PluralRules.prototype.${method} called on incompatible receiver ${String(
|
|
19
|
+
instance
|
|
20
|
+
)}`
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
26
|
+
initializedPluralRules: boolean
|
|
27
|
+
locale: string
|
|
28
|
+
type: 'cardinal' | 'ordinal'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* http://ecma-international.org/ecma-402/7.0/index.html#sec-pluralruleselect
|
|
33
|
+
* @param locale
|
|
34
|
+
* @param type
|
|
35
|
+
* @param _n
|
|
36
|
+
* @param param3
|
|
37
|
+
*/
|
|
38
|
+
function PluralRuleSelect(
|
|
39
|
+
locale: string,
|
|
40
|
+
type: 'cardinal' | 'ordinal',
|
|
41
|
+
_n: number,
|
|
42
|
+
{IntegerDigits, NumberOfFractionDigits, FractionDigits}: OperandsRecord
|
|
43
|
+
): LDMLPluralRule {
|
|
44
|
+
return PluralRules.localeData[locale].fn(
|
|
45
|
+
NumberOfFractionDigits
|
|
46
|
+
? `${IntegerDigits}.${FractionDigits}`
|
|
47
|
+
: IntegerDigits,
|
|
48
|
+
type === 'ordinal'
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class PluralRules implements Intl.PluralRules {
|
|
53
|
+
constructor(locales?: string | string[], options?: Intl.PluralRulesOptions) {
|
|
54
|
+
// test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
|
|
55
|
+
// Cannot use `new.target` bc of IE11 & TS transpiles it to something else
|
|
56
|
+
const newTarget =
|
|
57
|
+
this && this instanceof PluralRules ? this.constructor : void 0
|
|
58
|
+
if (!newTarget) {
|
|
59
|
+
throw new TypeError("Intl.PluralRules must be called with 'new'")
|
|
60
|
+
}
|
|
61
|
+
return InitializePluralRules(this, locales, options, {
|
|
62
|
+
availableLocales: PluralRules.availableLocales,
|
|
63
|
+
relevantExtensionKeys: PluralRules.relevantExtensionKeys,
|
|
64
|
+
localeData: PluralRules.localeData,
|
|
65
|
+
getDefaultLocale: PluralRules.getDefaultLocale,
|
|
66
|
+
getInternalSlots,
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
public resolvedOptions() {
|
|
70
|
+
validateInstance(this, 'resolvedOptions')
|
|
71
|
+
const opts = Object.create(null)
|
|
72
|
+
const internalSlots = getInternalSlots(this)
|
|
73
|
+
opts.locale = internalSlots.locale
|
|
74
|
+
opts.type = internalSlots.type
|
|
75
|
+
;(
|
|
76
|
+
[
|
|
77
|
+
'minimumIntegerDigits',
|
|
78
|
+
'minimumFractionDigits',
|
|
79
|
+
'maximumFractionDigits',
|
|
80
|
+
'minimumSignificantDigits',
|
|
81
|
+
'maximumSignificantDigits',
|
|
82
|
+
] as Array<keyof PluralRulesInternal>
|
|
83
|
+
).forEach(field => {
|
|
84
|
+
const val = internalSlots[field]
|
|
85
|
+
if (val !== undefined) {
|
|
86
|
+
opts[field] = val
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
opts.pluralCategories = [
|
|
91
|
+
...PluralRules.localeData[opts.locale].categories[
|
|
92
|
+
opts.type as 'cardinal'
|
|
93
|
+
],
|
|
94
|
+
]
|
|
95
|
+
return opts
|
|
96
|
+
}
|
|
97
|
+
public select(val: number): LDMLPluralRule {
|
|
98
|
+
const pr = this
|
|
99
|
+
validateInstance(pr, 'select')
|
|
100
|
+
const n = ToNumber(val)
|
|
101
|
+
return ResolvePlural(pr, n, {getInternalSlots, PluralRuleSelect})
|
|
102
|
+
}
|
|
103
|
+
toString() {
|
|
104
|
+
return '[object Intl.PluralRules]'
|
|
105
|
+
}
|
|
106
|
+
public static supportedLocalesOf(
|
|
107
|
+
locales?: string | string[],
|
|
108
|
+
options?: Pick<Intl.PluralRulesOptions, 'localeMatcher'>
|
|
109
|
+
) {
|
|
110
|
+
return SupportedLocales(
|
|
111
|
+
PluralRules.availableLocales,
|
|
112
|
+
CanonicalizeLocaleList(locales),
|
|
113
|
+
options
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
public static __addLocaleData(...data: PluralRulesLocaleData[]) {
|
|
117
|
+
for (const {data: d, locale} of data) {
|
|
118
|
+
PluralRules.localeData[locale] = d
|
|
119
|
+
PluralRules.availableLocales.add(locale)
|
|
120
|
+
if (!PluralRules.__defaultLocale) {
|
|
121
|
+
PluralRules.__defaultLocale = locale
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
static localeData: Record<string, PluralRulesData> = {}
|
|
126
|
+
static availableLocales = new Set<string>()
|
|
127
|
+
static __defaultLocale = ''
|
|
128
|
+
static getDefaultLocale() {
|
|
129
|
+
return PluralRules.__defaultLocale
|
|
130
|
+
}
|
|
131
|
+
static relevantExtensionKeys = []
|
|
132
|
+
public static polyfilled = true
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
// IE11 does not have Symbol
|
|
137
|
+
if (typeof Symbol !== 'undefined') {
|
|
138
|
+
Object.defineProperty(PluralRules.prototype, Symbol.toStringTag, {
|
|
139
|
+
value: 'Intl.PluralRules',
|
|
140
|
+
writable: false,
|
|
141
|
+
enumerable: false,
|
|
142
|
+
configurable: true,
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
// https://github.com/tc39/test262/blob/master/test/intl402/PluralRules/length.js
|
|
148
|
+
Object.defineProperty(PluralRules, 'length', {
|
|
149
|
+
value: 0,
|
|
150
|
+
writable: false,
|
|
151
|
+
enumerable: false,
|
|
152
|
+
configurable: true,
|
|
153
|
+
})
|
|
154
|
+
} catch (error) {
|
|
155
|
+
// IE 11 sets Function.prototype.length to be non-configurable which will cause the
|
|
156
|
+
// above Object.defineProperty to throw an error.
|
|
157
|
+
}
|
|
158
|
+
// https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/length.js
|
|
159
|
+
Object.defineProperty(PluralRules.prototype.constructor, 'length', {
|
|
160
|
+
value: 0,
|
|
161
|
+
writable: false,
|
|
162
|
+
enumerable: false,
|
|
163
|
+
configurable: true,
|
|
164
|
+
})
|
|
165
|
+
// https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length.js
|
|
166
|
+
Object.defineProperty(PluralRules.supportedLocalesOf, 'length', {
|
|
167
|
+
value: 1,
|
|
168
|
+
writable: false,
|
|
169
|
+
enumerable: false,
|
|
170
|
+
configurable: true,
|
|
171
|
+
})
|
|
172
|
+
} catch (ex) {
|
|
173
|
+
// Meta fixes for test262
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-pluralrules",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Polyfill for Intl.PluralRules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"polyfill",
|
|
@@ -20,12 +20,16 @@
|
|
|
20
20
|
"url": "git+https://github.com/formatjs/formatjs.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@formatjs/ecma402-abstract": "1.11.
|
|
24
|
-
"@formatjs/intl-localematcher": "0.2.
|
|
23
|
+
"@formatjs/ecma402-abstract": "1.11.9",
|
|
24
|
+
"@formatjs/intl-localematcher": "0.2.29",
|
|
25
25
|
"tslib": "2.4.0"
|
|
26
26
|
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@formatjs/intl-getcanonicallocales": "2.0.3",
|
|
29
|
+
"@formatjs/intl-locale": "3.0.4"
|
|
30
|
+
},
|
|
27
31
|
"bugs": {
|
|
28
32
|
"url": "https://github.com/formatjs/formatjs/issues"
|
|
29
33
|
},
|
|
30
34
|
"gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c"
|
|
31
|
-
}
|
|
35
|
+
}
|
package/polyfill.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {join} from 'path'
|
|
2
|
+
import {outputFileSync} from 'fs-extra'
|
|
3
|
+
import serialize from 'serialize-javascript'
|
|
4
|
+
import {PluralRulesLocaleData} from '@formatjs/ecma402-abstract'
|
|
5
|
+
import plurals from 'cldr-core/supplemental/plurals.json'
|
|
6
|
+
import minimist from 'minimist'
|
|
7
|
+
|
|
8
|
+
const Compiler = require('make-plural-compiler')
|
|
9
|
+
Compiler.load(
|
|
10
|
+
require('cldr-core/supplemental/plurals.json'),
|
|
11
|
+
require('cldr-core/supplemental/ordinals.json')
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
const languages = Object.keys(plurals.supplemental['plurals-type-cardinal'])
|
|
15
|
+
|
|
16
|
+
function generateLocaleData(locale: string): PluralRulesLocaleData | undefined {
|
|
17
|
+
let compiler, fn
|
|
18
|
+
compiler = new Compiler(locale, {cardinals: true, ordinals: true})
|
|
19
|
+
fn = compiler.compile()
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
data: {
|
|
23
|
+
categories: compiler.categories,
|
|
24
|
+
fn,
|
|
25
|
+
},
|
|
26
|
+
locale,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Args extends minimist.ParsedArgs {
|
|
31
|
+
outDir: string
|
|
32
|
+
out: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function main(args: Args) {
|
|
36
|
+
const {outDir, out} = args
|
|
37
|
+
|
|
38
|
+
const locales = languages
|
|
39
|
+
.filter(locale => {
|
|
40
|
+
try {
|
|
41
|
+
;(Intl as any).getCanonicalLocales(locale)
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.warn(`Invalid locale ${locale}`)
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
return true
|
|
47
|
+
})
|
|
48
|
+
.sort()
|
|
49
|
+
|
|
50
|
+
if (outDir) {
|
|
51
|
+
locales.forEach(
|
|
52
|
+
locale =>
|
|
53
|
+
+console.log(join(outDir, `${locale}.js`)) ||
|
|
54
|
+
outputFileSync(
|
|
55
|
+
join(outDir, `${locale}.js`),
|
|
56
|
+
serialize(generateLocaleData(locale))
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
} else if (out) {
|
|
60
|
+
outputFileSync(
|
|
61
|
+
out,
|
|
62
|
+
`// This file is generated from supported-locales-gen.ts
|
|
63
|
+
export const supportedLocales: string[] = ${JSON.stringify(locales)}
|
|
64
|
+
`
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (require.main === module) {
|
|
69
|
+
main(minimist<Args>(process.argv))
|
|
70
|
+
}
|
package/scripts/cldr.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {join, basename} from 'path'
|
|
2
|
+
import {outputFileSync, readFileSync} from 'fs-extra'
|
|
3
|
+
import minimist from 'minimist'
|
|
4
|
+
|
|
5
|
+
interface Args extends minimist.ParsedArgs {
|
|
6
|
+
cldrFile: string[]
|
|
7
|
+
}
|
|
8
|
+
function main(args: Args) {
|
|
9
|
+
const {cldrFile: cldrFiles, outDir} = args
|
|
10
|
+
cldrFiles.sort()
|
|
11
|
+
cldrFiles.forEach(cldrFile => {
|
|
12
|
+
const locale = basename(cldrFile, '.js')
|
|
13
|
+
// Dist all locale files to locale-data (JS)
|
|
14
|
+
const data = readFileSync(cldrFile)
|
|
15
|
+
outputFileSync(
|
|
16
|
+
join(outDir, locale + '.js'),
|
|
17
|
+
`/* @generated */
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
if (Intl.PluralRules && typeof Intl.PluralRules.__addLocaleData === 'function') {
|
|
20
|
+
Intl.PluralRules.__addLocaleData(${data})
|
|
21
|
+
}
|
|
22
|
+
`
|
|
23
|
+
)
|
|
24
|
+
outputFileSync(join(outDir, locale + '.d.ts'), 'export {}')
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
if (require.main === module) {
|
|
28
|
+
main(minimist<Args>(process.argv))
|
|
29
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {outputFileSync, readFileSync} from 'fs-extra'
|
|
2
|
+
import minimist from 'minimist'
|
|
3
|
+
|
|
4
|
+
interface Args extends minimist.ParsedArgs {
|
|
5
|
+
cldrFile: string[]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function main(args: Args) {
|
|
9
|
+
const {cldrFile: cldrFiles, out} = args
|
|
10
|
+
cldrFiles.sort()
|
|
11
|
+
|
|
12
|
+
// Aggregate all into ../test262-main.js
|
|
13
|
+
const allData = cldrFiles.map(f => readFileSync(f))
|
|
14
|
+
outputFileSync(
|
|
15
|
+
out,
|
|
16
|
+
`/* @generated */
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
// @ts-nocheck
|
|
19
|
+
import './polyfill-force'
|
|
20
|
+
if (Intl.PluralRules && typeof Intl.PluralRules.__addLocaleData === 'function') {
|
|
21
|
+
Intl.PluralRules.__addLocaleData(${allData.join(',\n')})
|
|
22
|
+
}
|
|
23
|
+
`
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
if (require.main === module) {
|
|
27
|
+
main(minimist<Args>(process.argv))
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {match} from '@formatjs/intl-localematcher'
|
|
2
|
+
import {supportedLocales} from './supported-locales.generated'
|
|
3
|
+
|
|
4
|
+
function supportedLocalesOf(locale?: string | string[]) {
|
|
5
|
+
if (!locale) {
|
|
6
|
+
return true
|
|
7
|
+
}
|
|
8
|
+
const locales = Array.isArray(locale) ? locale : [locale]
|
|
9
|
+
return Intl.PluralRules.supportedLocalesOf(locales).length === locales.length
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function shouldPolyfill(locale = 'en') {
|
|
13
|
+
if (
|
|
14
|
+
!('PluralRules' in Intl) ||
|
|
15
|
+
new Intl.PluralRules('en', {minimumFractionDigits: 2} as any).select(1) ===
|
|
16
|
+
'one' ||
|
|
17
|
+
!supportedLocalesOf(locale)
|
|
18
|
+
) {
|
|
19
|
+
return locale ? match([locale], supportedLocales, 'en') : undefined
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const supportedLocales: string[] = ["af", "ak", "am", "an", "ar", "ars", "as", "asa", "ast", "az", "bal", "be", "bem", "bez", "bg", "bho", "bm", "bn", "bo", "br", "brx", "bs", "ca", "ce", "ceb", "cgg", "chr", "ckb", "cs", "cy", "da", "de", "doi", "dsb", "dv", "dz", "ee", "el", "en", "eo", "es", "et", "eu", "fa", "ff", "fi", "fil", "fo", "fr", "fur", "fy", "ga", "gd", "gl", "gsw", "gu", "guw", "gv", "ha", "haw", "he", "hi", "hnj", "hr", "hsb", "hu", "hy", "ia", "id", "ig", "ii", "io", "is", "it", "iu", "ja", "jbo", "jgo", "jmc", "jv", "jw", "ka", "kab", "kaj", "kcg", "kde", "kea", "kk", "kkj", "kl", "km", "kn", "ko", "ks", "ksb", "ksh", "ku", "kw", "ky", "lag", "lb", "lg", "lij", "lkt", "ln", "lo", "lt", "lv", "mas", "mg", "mgo", "mk", "ml", "mn", "mo", "mr", "ms", "mt", "my", "nah", "naq", "nb", "nd", "ne", "nl", "nn", "nnh", "no", "nqo", "nr", "nso", "ny", "nyn", "om", "or", "os", "osa", "pa", "pap", "pcm", "pl", "prg", "ps", "pt", "pt-PT", "rm", "ro", "rof", "ru", "rwk", "sah", "saq", "sat", "sc", "scn", "sd", "sdh", "se", "seh", "ses", "sg", "sh", "shi", "si", "sk", "sl", "sma", "smi", "smj", "smn", "sms", "sn", "so", "sq", "sr", "ss", "ssy", "st", "su", "sv", "sw", "syr", "ta", "te", "teo", "th", "ti", "tig", "tk", "tl", "tn", "to", "tpi", "tr", "ts", "tzm", "ug", "uk", "und", "ur", "uz", "ve", "vi", "vo", "vun", "wa", "wae", "wo", "xh", "xog", "yi", "yo", "yue", "zh", "zu"]
|