piral-translate
Advanced tools
Comparing version 0.8.0-pre.682 to 0.8.0-pre.683
{ | ||
"name": "piral-translate", | ||
"version": "0.8.0-pre.682", | ||
"version": "0.8.0-pre.683", | ||
"description": "Introduces the translate API extension for extending piral-core.", | ||
@@ -40,3 +40,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"piral-core": "^0.8.0-pre.682" | ||
"piral-core": "^0.8.0-pre.683" | ||
}, | ||
@@ -48,3 +48,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "04da0183524adea0bae44c0f30f2b3ee1ce36e88" | ||
"gitHead": "2a3db9bdcf5523446ac735eb5f064be6afd600ba" | ||
} |
@@ -11,4 +11,66 @@ [![Piral Logo](https://github.com/smapiot/piral/raw/master/docs/assets/logo.png)](https://piral.io) | ||
## Setup and Bootstrapping | ||
The provided library only brings API extensions for pilets to a Piral instance. | ||
For the setup of the library itself you'll need to import `createLocaleApi` from the `piral-translate` package. | ||
```tsx | ||
import { createLocaleApi } from 'piral-translate'; | ||
``` | ||
The integration looks like: | ||
```tsx | ||
const instance = createInstance({ | ||
// important part | ||
extendApi: [createLocaleApi()], | ||
// ... | ||
}); | ||
``` | ||
Via the options the available languages, translations, as well as the currently selected language can be chosen. | ||
For example: | ||
```tsx | ||
const localizer = setupLocalizer({ | ||
language: 'en', | ||
messages: { | ||
en: { | ||
'greeting': 'Hello', | ||
}, | ||
de: { | ||
'greeting': 'Hallo', | ||
}, | ||
}, | ||
}); | ||
const instance = createInstance({ | ||
// important part | ||
extendApi: [createLocaleApi(localizer)], | ||
// ... | ||
}); | ||
``` | ||
Alternatively, the current language can also be inferred via a function. | ||
```tsx | ||
const localizer = setupLocalizer({ | ||
language: getUserLocale, | ||
messages: { | ||
en: { | ||
'greeting': 'Hello', | ||
}, | ||
de: { | ||
'greeting': 'Hallo', | ||
}, | ||
}, | ||
}); | ||
``` | ||
The function `getUserLocale` retrieves either the cookie with name `_culture` or local storage value for key `locale`. In any case either the first found language or ultimately `en` is used as a fallback. | ||
## License | ||
Piral is released using the MIT license. For more information see the [license file](./LICENSE). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49896
76