Skip to content

Latest commit

 

History

History
131 lines (91 loc) · 3.12 KB

README.md

File metadata and controls

131 lines (91 loc) · 3.12 KB

intly

CircleCI npm

🚧 This library is still alpha version! (active development)

intly is Type-safe (TS friendly) i18n library.

todo

Table of Contents

Features

  • todo

Getting Started

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

API

todo

Contribution

We are always welcoming your contribution 👏

  1. Fork it ! 🎉
  2. Create your feature branch: $ git checkout -b my-new-feature
  3. Commit your changes: $ git commit -am 'Add some feature' 📝
  4. Push to the branch: $ git push origin my-new-feature 💡
  5. Rebase your local changes against the master branch 💪
  6. Create new Pull Request 💌

Bugs, feature requests and comments are more than welcome in the issues.

Development scripts

todo

yarn bootstrap

todo

yarn build

todo

yarn test

todo

yarn lint

todo

CHANGELOG

See CHANGELOG.md

License

MIT © Cyberagent, Inc