Skip to content

Commit

Permalink
Continue on readme
Browse files Browse the repository at this point in the history
  • Loading branch information
drewjbartlett committed Nov 18, 2023
1 parent cdf3c88 commit b765401
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A 1.4kB internationalization library that acts is intended for projects needing

mini17n features :

- ✅ basic `{ "key": "value" }` translations `t('hello.world')`
- ✅ basic `{ "key": "value" }` translations `t('key')`
- ✅ interpolated values `t('Hello, {name}!', { name: 'Drew' })`
- ✅ count based translations `t('tree', { count: 1 }) // "tree"`, `t('tree', { count: 10 }) // "trees"`
- ✅ smart caching - after a key is resolved once it is read from a cache
Expand All @@ -24,14 +24,13 @@ Using internationalization is not just for languages. It helps create a consiste
### Installation

```bash
npm i @drewjbartlett/i17n
npm i @drewjbartlett/i17n --save
```

### Usage


```json
// translations.json
{
"helloWorld": "Hello World!",
"welcomeUser": "Welcome, {user}!",
Expand All @@ -44,7 +43,7 @@ npm i @drewjbartlett/i17n
"name__one": "Item",
"name__many": "Items",
},
};
}
```

```ts
Expand Down Expand Up @@ -72,18 +71,26 @@ export const lang = {
import { createI7n } from '@drewjbartlett/i17n'
import Translations from 'path/to/translations';

const i17n = createI17n({
export const i17n = createI17n({
translations: Translations,
});

// another-file.ts
import { i17n } from 'path/to/i17n'

i17n.t('helloWorld'); // "Hello World"
```

/**
* Optionally, export your own helpers to match your coding conventions.
*/
```ts
// Optionally, export your own helpers to match your conventions.
const $t = i18n.t;

export { $t }

// another-file.ts
import { $t } from 'path/to/i17n'

$t('helloWorld')
```

### Config
Expand Down

0 comments on commit b765401

Please sign in to comment.