Monster.I18n.Providers. Fetch

The fetch provider retrieves a JSON file from the given URL and returns a translation object.

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:
NameTypeDescription
urlstring | URL
optionsObject

see Monster.I18n.Providers.Fetch#defaults

Since
  • 1.13.0
License
  • AGPLv3
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

Properties
NameTypeDescription
fetchObject
Properties
NameTypeDefaultDescription
methodStringGET
modeStringcors
cacheStringno-cache
credentialsStringomit
redirectStringfollow
referrerPolicyStringno-referrer

url

Properties
TypeDescription
string

Methods

getTranslations(locale) → {Promise}

Parameters:
NameTypeDescription
localeLocale | string
Returns:
Type: 
Promise