Constructor
new Fetch(url, options)
As options the key
fetch
can be passed.As options the key fetch
can be passed. This config object is passed to the fetch method as init.
The url may contain placeholders (language, script, region, variants, extlang, privateUse), so you can specify one url for all translations.
new Fetch('https://www.example.com/assets/${language}.json')
Parameters:
Name | Type | Description |
---|---|---|
url | string | | |
options | Object |
- Since
- 1.13.0
- Copyright
- schukai GmbH
- License
- AGPLv3
- Tutorials
- Tutorial: i18n-locale-and-formatter
Example
import {Fetch} from '@schukai/monster/source/i18n/providers/fetch.mjs';
// fetch from API
const translation = new Fetch('https://example.com/${language}.json').getTranslation('en-GB');
// ↦ https://example.com/en.json
Members
defaults
Defaults
.Defaults
Name | Type | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fetch | Object | Properties
|
url
PropertiesType | Description |
---|---|
string |
Methods
getTranslations(locale) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
locale | Locale | |
Returns:
- Type:
- Promise