🚧 This library is still alpha version! (active development)
intly is Type-safe (TS friendly) i18n library.
todo
- todo
todo
$ npm install --save intly
# or
$ yarn add intly
todo
import { Intly, nf } from 'intly';
const intly = new Intly('en', {
'text.hello': 'Hello World!',
'fn.default': (): string => 'A function without arguments.',
'fn.string': (s: string) => `"${s}"`,
'fn.boolean': (b: boolean): string => (b ? 'true' : 'false'),
'fn.object': ({ first, last }: { first: string; last: string }) => `Hi, ${first} ${last}!`,
'num.days': nf('{{count}} days', {
replacement: {
1: 'a day',
},
useGrouping: false,
}),
'num.currency': nf('{{count}}', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0,
}),
'num.point': nf('{{count}}pt', {
replacement: {
0: '💔',
},
minimumFractionDigits: 1,
maximumFractionDigits: 1,
}),
});
// Translation
intly.t('text.hello'); // <-- Hello World!
intly.t('fn.default'); // <-- A function without arguments.
intly.t('fn.string', 'string value'); // <-- "string value"
intly.t('fn.boolean', true); // <-- true
intly.t('fn.boolean', false); // <-- false
intly.t('fn.object', { first: 'firstname', last: 'lastname' }); // <-- Hi, firstname lastname!
// Number format
intly.t('num.days', { count: 1 }); // <-- a day
intly.t('num.days', { count: 3 }); // <-- 3 days
intly.t('num.days', { count: 10000 }); // <-- 10000 days
intly.t('num.currency', { count: 10 }); // <-- $10
intly.t('num.currency', { count: 1234 }); // <-- $1,234
intly.t('num.point', { count: 0 }); // <-- 💔
intly.t('num.point', { count: 1000 }); // <-- 1,000.0pt
intly.t('num.point', { count: 12300.12345 }); // <-- 12,300.1pt
intly.t('num.point', { count: 12300.987 }); // <-- 12,301.0pt
// Type-safe!
intly.t('not.exists_key'); // <-- Argument of type '"not.exists_key"' is not assignable to parameter of type '"text.hello" | "fn.default" | "fn.string" | "fn.boolean" | "fn.object" | "num.days" | "num.currency" | "num.point"'.
todo
todo
We are always welcoming your contribution 👏
- Fork it ! 🎉
- Create your feature branch:
$ git checkout -b my-new-feature
☕ - Commit your changes:
$ git commit -am 'Add some feature'
📝 - Push to the branch:
$ git push origin my-new-feature
💡 - Rebase your local changes against the
master
branch 💪 - Create new Pull Request 💌
Bugs, feature requests and comments are more than welcome in the issues.
todo
todo
todo
todo
todo
See CHANGELOG.md