Monster.I18n.Providers. Embed

The Embed provider retrieves a JSON file from the given Script Tag.

Constructor

new Embed(elementOrId, options)

<script id="translations" type="application/json">
{
    "hello": "Hallo"
}
</script>
new Embed('translations')
.
<script id="translations" type="application/json">
{
    "hello": "Hallo"
}
</script>
new Embed('translations')
Parameters:
NameTypeDescription
elementOrIdHTMLElement | string
optionsObject
Since
  • 1.13.0
License
  • AGPLv3
Tutorials
  • Tutorial: i18n-locale-and-formatter
Example
import {Embed} from '@schukai/monster/source/i18n/providers/embed.mjs';

// read from script tag with id i18n
const translation = new Embed('i18n');

Members

defaults

Defaults

.

Defaults

translateElement

Properties
TypeDescription
HTMLElement | string

translateElement

Properties
TypeDescription
HTMLElement | string

Methods

getTranslations(locale) → {Promise}

Parameters:
NameTypeDescription
localeLocale | string
Returns:
Type: 
Promise

(static) assignTranslationsToElement(element)

Initializes the translations for the current document.

Initializes the translations for the current document.

script[data-monster-role=translations] is searched for and the translations are assigned to the element.

Parameters:
NameTypeDescription
element
Returns: