Public
Edited
Aug 31, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
translations = ({
HI: 'Hello {name}!',
ITEMS: [
{FOO: 'bar'},
{FOO: 'baz'},
],
'TestString': 'test',
'TestArray': [
'test',
'test',
],
'TestArrayObjects': [
{ text: 'test' },
{ text: 'test' },
],
'TestArrayArray': [
['test', 'test'],
['test', 'test']
],
'TestObject': {
0: [
{
text: 'test',
},
{
text: 'test',
},
],
},
})
Insert cell
formatters = ({
uppercase: (value) => value.toUpperCase()
})
Insert cell
LLL = i18n.i18nString(locale, formatters)
Insert cell
LLL('Hello {name|uppercase}!', { name: 'world' })
Insert cell
LLL('banana{{nrOfBananas:s}}', { nrOfBananas: 2 })
Insert cell
LLL('banana{{s}}', 1)
Insert cell
LLL('{{n:category|categories}}', { n: 1 })
Insert cell
function test () {
const LL = i18n.i18nObject('en', translations, {});
console.log('TestString', LL['TestString'], LL['TestString']())
Array.from(LL['TestArray']).forEach(item => {
console.log('Array', item, item())
})
Array.from(LL['TestArray']).forEach(item => {
console.log('Array', item, item())
})
console.log(LL['ITEMS'][0].FOO())
Array.from(LL['ITEMS']).forEach(item => {
console.log('ArrayObject ITEMS', item, typeof item.FOO, item.FOO)
})
for (let i = 0; i < Array.from(LL['ITEMS']).length; i++) {
console.log('FOR', LL['ITEMS'][i].FOO())
}
Array.from(LL['TestArrayObjects']).forEach(item => {
console.log('ArrayObject', item, item(), item.FOO)
})
Object.values(LL['TestObject']).forEach(item => {
console.log('Object', item, item())
})
}
Insert cell
test()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more