Skip to content

Instantly share code, notes, and snippets.

@baldurh
Created October 17, 2019 07:29
Show Gist options
  • Save baldurh/f2155e522eae90aab7872d33d24608e8 to your computer and use it in GitHub Desktop.
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
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