Skip to content
/ intly Public

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

License

Notifications You must be signed in to change notification settings

cats-oss/intly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

42e6180 Β· Jan 9, 2020

History

9 Commits
Jan 2, 2019
Jan 9, 2020
Jan 9, 2020
Oct 14, 2018
Oct 14, 2018
Oct 14, 2018
Oct 14, 2018
Oct 14, 2018
Jan 9, 2020
Jan 2, 2019
Oct 14, 2018
Oct 14, 2018
Jan 2, 2019
Jan 2, 2019

Repository files navigation

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