Here is an example tutorial for switching between multiple languages using a DocumentEngine template:
{
"en": {
"greeting": "Hello",
"goodbye": "Goodbye"
},
"fr": {
"greeting": "Bonjour",
"goodbye": "Au revoir"
}
}
{{#with}}
helper to switch between the different languages. The
{{#with}}
helper takes an object as an argument, and it allows you to access the properties of the object using dot notation. Here is an example:
{{#with languages.en}}
{{greeting}}, world!
{{/with}}
{{#with}}
helper inside another
{{#with}}
helper. This allows you to specify the language that you want to use, and then access the text for that language using dot notation. Here is an example that switches between the English and French languages:
{{#with languages}}
{{#with en}}
{{greeting}}, world!
{{/with}}
{{#with fr}}
{{greeting}}, monde!
{{/with}}
{{/with}}
{{#with}}
helper in combination with the
{{lookup}}
helper. The
{{lookup}}
helper allows you to access a property of an object using a variable as the key. Here is an example that uses a variable
selectedLanguage
to switch between languages:
{{#with languages}}
{{#with (lookup . selectedLanguage)}}
{{greeting}}, world!
{{/with}}
{{/with}}