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:
Name | Type | Description |
---|---|---|
elementOrId | HTMLElement | | |
options | Object |
- Since
- 1.13.0
- Copyright
- schukai GmbH
- 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
PropertiesType | Description |
---|---|
HTMLElement | |
translateElement
PropertiesType | Description |
---|---|
HTMLElement | |
Methods
getTranslations(locale) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
locale | Locale | |
Returns:
- Type:
- Promise
(static) assignTranslationsToElement(element) → {Promise.<Array.<unknown>>}
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:
Name | Type | Description |
---|---|---|
element |
Returns:
- Type:
- Promise.<Array.<unknown>>