-
Notifications
You must be signed in to change notification settings - Fork 17
Localizing Templates
Although Mustachio doesn't include explicit support for localizing templates, in many cases, only minor adjustments are needed in the content of a template, so it's simple to include the variations inline. For example, let's create a basic template that can use different language for Spanish, or English languages:
<html>
<body>
{{#english}}Good morning, {{../name}}{{/english}}
{{#spanish}}Buenos días, {{../name}}{{/spanish}}
</body>
</html>
Given a model like this:
{
"english" : true,
"name" : "Dave"
}
The template would produce the following result:
<html>
<body>
Good morning, Dave
</body>
</html>
Note that the presence of the "spanish" property is not necessary.
Many templates require only small modifications to their content for them to be properly localized, but this same technique could be used to create a large block of localized content for each target language. Additionally, using our advanced scoping features ../
, it's possible to navigate up and around the template model for more complex scenarios.