List of resource IDs
Function that returns a generator over FluentBundles
Format translations into {value, attributes} objects.
The fallback logic is the same as in formatValues
but it returns {value,
attributes} objects which are suitable for the translation of DOM
elements.
docL10n.formatMessages([
{id: 'hello', args: { who: 'Mary' }},
{id: 'welcome'}
]).then(console.log);
// [
// { value: 'Hello, Mary!', attributes: null },
// {
// value: 'Welcome!',
// attributes: [ { name: "title", value: 'Hello' } ]
// }
// ]
Returns a Promise resolving to an array of the translation strings.
}
Retrieve the translation corresponding to the id
identifier.
If passed, args
is a simple hash object with a list of variables that
will be interpolated in the value of the translation.
docL10n.formatValue(
'hello', { who: 'world' }
).then(console.log);
// 'Hello, world!'
Returns a Promise resolving to the translation string.
Use this sparingly for one-off messages which don't need to be retranslated when the user changes their language preferences, e.g. in notifications.
Identifier of the translation to format
Retrieve translations corresponding to the passed keys.
A generalized version of DOMLocalization.formatValue
. Keys must
be {id, args}
objects.
docL10n.formatValues([
{id: 'hello', args: { who: 'Mary' }},
{id: 'hello', args: { who: 'John' }},
{id: 'welcome'}
]).then(console.log);
// ['Hello, Mary!', 'Hello, John!', 'Welcome!']
Returns a Promise resolving to an array of the translation strings.
Format translations and handle fallback if needed.
Format translations for keys
from FluentBundle
instances on this
DOMLocalization. In case of errors, fetch the next context in the
fallback chain.
Translation keys to format.
Formatting function.
This method should be called when there's a reason to believe that language negotiation or available resources changed.
The
Localization
class is a central high-level API for vanilla JavaScript use of Fluent. It combines language negotiation, FluentBundle and I/O to provide a scriptable API to format translations.