Created
October 17, 2019 07:29
-
-
Save baldurh/f2155e522eae90aab7872d33d24608e8 to your computer and use it in GitHub Desktop.
A script for generating plural rule files to use with i18next-icu. Based on https://github.com/formatjs/formatjs/blob/master/packages/intl-pluralrules/scripts/cldr.ts
This file contains 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
const { writeFileSync } = require("fs"); | |
const { resolve } = require("path"); | |
const serialize = require("serialize-javascript"); | |
const plural = require("make-plural"); | |
const languages = [ | |
"de", | |
"en", | |
"es", | |
"fr", | |
"it", | |
"ja", | |
"ko", | |
"pl", | |
"ru", | |
"th", | |
"zh", | |
]; | |
languages.forEach(lang => { | |
const data = { | |
locale: lang, | |
pluralRuleFunction: plural[lang], | |
}; | |
writeFileSync( | |
resolve(__dirname, `../static/locale-data/${lang}.js`), | |
`/* @generated */ | |
/* eslint-disable */ | |
export default ${serialize(data, { space: 2 })};` | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment