Constructor
new I18nTranslation()
Properties:
Name | Type | Description |
---|---|---|
key |
string | an i18n key, presumably dot-delimited, however it can be any valid attribute value. |
value |
string | the value of the key, in the browser's locale. It may contain placeholders for interpolation using |
- Source:
Example
<brut-i18n-translation key="greeting" value="Hello %{username}"></brut-i18n-translation>
Methods
translation(interpolatedValues)
Called by other JavaScript to get the translated string.
Parameters:
Name | Type | Description |
---|---|---|
interpolatedValues |
Object | Object where the keys are placeholders in the string for interpolation and the values are the values to replace. Placeholders not in the translated value are ignored. Missing placeholders won't cause an error, but the placeholder will be present verbatim in the translated string. |
- Source:
Example
const element = document.querySeletor("brut-i18n-translation[key='greeting']")
if (element) {
const translation = element.translation({ username: "Pat" })
alert(translation) // Shows 'Hello Pat'
}