Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Can I translate a Roll Query within a Roll Template?

1513954115
Axel
Pro
Sheet Author
Hey! I need help translating the text in a roll query within a roll template. <button type="roll" name="roll_Roll_Test" value="&{template:rolltest} {{title=^{ROLL-TEST}}} {{dieroll=[[1d20+?{ MODIFIER |0}]]}}</button> The translation for the title works fine, but how do I translate the "MODIFIER" text in the roll query pop up? I've read the wiki, but it didn't help me here.
1513955295
Jakob
Sheet Author
API Scripter
Kind of. Replace the query with an attribute from a hidden field, say @{modifier_query}, which you can set on("sheet:opened") via sheet workers. In the sheet workers, you can use getTranslationByKey() to translate the query.
1514297773
Axel
Pro
Sheet Author
Ok, so I should do something like this? <button type="roll" name="roll_Roll_Test" value="&{template:rolltest} {{title=^{ROLL-TEST}}} {{dieroll=[[1d20+?{@{translation_modifier}|0}]]}}</button> <input type="hidden" name="attr_translation_modifier" value="Modifier"/> <script type="text/worker">     on('sheet:opened',function(){         setAttrs({             translation_modifier: getTranslationByKey('MODIFIER')         });     }); </script>
1514368821
Jakob
Sheet Author
API Scripter
Yes, that would work.\ Here's a thing I do to avoid attribute bloat: I check if the translated value is the same as the English version, and only set it if it isn't. <script type="text/worker"> on('sheet:opened', function () { getAttrs(['translation_modifier'], v => { if (v.translation_modifier !== getTranslationByKey('MODIFIER')) { setAttrs({ translation_modifier: getTranslationByKey('MODIFIER') }); } }); }); </script>
1514381488
Axel
Pro
Sheet Author
Thanks. Looks like it does work. I'm learning more about scripting. Thanks for all the help Jakob!