Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw committed Oct 26, 2018
1 parent 671b971 commit 3e0b514
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/superset-ui-translation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#### Example usage

```js
import { configure, t } from '@superset-ui/translation';
import { configure, t, tn } from '@superset-ui/translation';

configure({
languagePack: {...},
});

console.log(t('text to be translated'));
console.log(tn('singular text', 'plural text', value));
```

#### API
Expand All @@ -27,17 +28,28 @@ console.log(t('text to be translated'));

`t(text[, args])`

- Translate `text` when no `args` is provided.
- Translate `text` and substitute `args` into the placeholders specified within `text`.
- Translate `text`.
- If `args` is provided, substitute `args` into the `sprintf` placeholders specified within `text` translation.

For example

```js
t('Hello %(name)s', user)
t('Hello %(name)s', user);
```

See [sprintf-js](https://github.com/alexei/sprintf.js) for more details on how to define placeholders.

`tn(singular, plural, num, [, args])`

- Translate and choose between `singular` and `plural` based on `num`.
- If `args` is provided, substitute `args` into the `sprintf` placeholders specified within `singular` or `plural` translations.

For example

```js
tn('%d duck', '%d ducks', 2, 2);
```

### Development

`@data-ui/build-config` is used to manage the build configuration for this package including babel
Expand Down

0 comments on commit 3e0b514

Please sign in to comment.