Constructor
# new Fetch(url, options)
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 | URL | |
options |
Object |
- Since:
- 1.13.0
- Copyright:
- schukai GmbH
- Tutorials:
Example
das ist ein test
import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/providers/fetch.js';
// fetch from API
const translation = new Fetch('https://example.com/${language}.json').getTranslation('en-GB');
// ↦ https://example.com/en.json
Members
# defaults
Defaults
Properties
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fetch |
Object |
Properties
|
# url
Properties
| Type | Description |
|---|---|
| string |
Methods
# getTranslations(locale) → {Promise}
Parameters:
| Name | Type | Description |
|---|---|---|
locale |
Locale | string |
Returns:
- Type
- Promise