Translating rollTemplates

A rollTemplate is the printout you get in chat from a button. I have a whole guide on them, but you probably want to translate them, too. If you know how rolltemplates work, adding translations does require some extra work, but it’s not very complicated. The wiki page on translations has a section on rolltemplates. It’s a really short section, but it is not very helpful, honestly. I’ll try to describe how it works here.

Creating a RollTemplate

Refer to the guide mentioned for creating the basics of your rolltemplate. Here’s a basic template for making simple attack rolls and displaying the result.

<rolltemplate class="sheet-rolltemplate-example">
   {{#title}}<div class="sheet-template-title">{{title}}</div>{{/title}}
   <div class="sheet-rolls">
      {{#allprops() title}}
         <div class="sheet-roll-title">{{key}}</div>
         <div class="sheet-roll-result">{{value}}</div>
      {{/allprops() title}}
</rolltemplate>Code language: HTML, XML (xml)

This is a simple rollTemplate, of the sort described back in rollTemplate Keys and Values. You’d launch this with a macro like:

&{template:example} {{title=An Example Attack}} {{Attack Roll=[[1d20+@{attack}]] }}Code language: Markdown (markdown)

You should be able to follow what’s happening here. A title is supplied, then roll keys and values (the parts inside {{ key = value }} are placed in the rollTemplate and output in that sequence. But notice: nothing is being translated here – and there is no way to place i18n tags, because the output varies constantly.

Dynamic Translations within a rollTemplate

This is where a special code comes into play: ^{something}. For example:

&{template:example} {{title=^{example-attack-title} }} {{^{attack-roll}=[[1d20+@{attack}]] }}Code language: Markdown (markdown)

When you place an existing translation key inside ^{ }, that will be translated. So for this to work, you’d need something like this in the sheet:

<span class="hidden" data-18n="example-attack-title">An Example Attack</span>
<span class="hidden" data-18n="attack-roll">Attack Roll</span>Code language: HTML, XML (xml)

Now this attack macro is functionally the same as the original macro, but this one will be translated.

When using the ^{ } syntax, the translation keys must exist already or the key will not be translated.


When using this kind if structure, it;s very common to use allprops(). This lets you declare which keys should not included in this loop. See how title is excluded – if it wasn’t you’d see that title twice: once for the hardcoded title at the start of the rolltemaple, and again when allprops loops through all keys.

A problem with the key check here is it does not check for dynamic jeys, You can’t do this:

      {{#allprops() title ^{stat-key} }}
         <div class="sheet-roll-title">{{key}}</div>
         <div class="sheet-roll-result">{{value}}</div>
      {{/allprops() title ^{stat-key}}}Code language: HTML, XML (xml)

You must include the actual translated value. If you had a key named strength, and didnt want it to show up in the loop (for whatever reason), you’d have to include all known valid translations of strength.

      {{#allprops() title strength fortaleza}}
         <div class="sheet-roll-title">{{key}}</div>
         <div class="sheet-roll-result">{{value}}</div>
      {{/allprops() title strength fortaleza}}Code language: HTML, XML (xml)

Here we see the English and Spanish translations of Strength.

This is a huge failing. If you know a way to make this dynamic, please let me know and I’ll update the article.

i18n Keys in a RollTemplate

You can use any translation tools within the rollTemplate itself, like i18n tags. For example, here’s a simple template where everything is hardcoded:

<rolltemplate class="sheet-rolltemplate-simple">
   <div class="sheet-template-title" data-18n="template-title">A Simple Template</div>
   <div class="sheet-roll-title" data-18n="template-roll-title">A Simple Roll</div>
   <div class="sheet-roll-result">{{roll}}</div>
</rolltemplate>Code language: HTML, XML (xml)

Here we have a template that uses simple translation keys. You don’t need to add anything extra, this just work as is.

Mix and Match

In any real template, you might mix and match the techniques described here. You can do that, and it will be fine. Have fun!

Series Navigation<< Translating Lists and QueriesTranslating Default Sheet Settings >>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.