2018-10-24 17:43:19 -04:00
|
|
|
## `@superset-ui/translation`
|
|
|
|
|
|
|
|
[![Version](https://img.shields.io/npm/v/@superset-ui/translation.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/translation.svg?style=flat)
|
|
|
|
|
|
|
|
`i18n` locales and translation for Superset
|
|
|
|
|
|
|
|
### SupersetTranslation
|
|
|
|
|
|
|
|
#### Example usage
|
|
|
|
|
|
|
|
```js
|
2018-10-26 17:50:34 -04:00
|
|
|
import { configure, t, tn } from '@superset-ui/translation';
|
2018-10-24 17:43:19 -04:00
|
|
|
|
|
|
|
configure({
|
|
|
|
languagePack: {...},
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(t('text to be translated'));
|
2018-10-26 17:50:34 -04:00
|
|
|
console.log(tn('singular text', 'plural text', value));
|
2018-10-24 17:43:19 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
#### API
|
|
|
|
|
|
|
|
`configure({ [languagePack] })`
|
|
|
|
|
|
|
|
- Initialize the translator
|
|
|
|
- Initialize with the default language if no `languagePack` is specified.
|
|
|
|
|
|
|
|
`t(text[, args])`
|
|
|
|
|
2018-10-26 17:50:34 -04:00
|
|
|
- Translate `text`.
|
|
|
|
- If `args` is provided, substitute `args` into the `sprintf` placeholders specified within `text` translation.
|
2018-10-24 17:43:19 -04:00
|
|
|
|
|
|
|
For example
|
|
|
|
|
|
|
|
```js
|
2018-10-26 17:50:34 -04:00
|
|
|
t('Hello %(name)s', user);
|
2018-10-24 17:43:19 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
See [sprintf-js](https://github.com/alexei/sprintf.js) for more details on how to define placeholders.
|
|
|
|
|
2018-10-26 17:50:34 -04:00
|
|
|
`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);
|
|
|
|
```
|
|
|
|
|
2018-10-24 17:43:19 -04:00
|
|
|
### Development
|
|
|
|
|
|
|
|
`@data-ui/build-config` is used to manage the build configuration for this package including babel
|
|
|
|
builds, jest testing, eslint, and prettier.
|