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

Sheet Author: datalist translation

1680569476

Edited 1680590766
vÍnce
Pro
Sheet Author
I have a repeating attribute "ability_type2", that is a datalist input. &lt;input type="text" name="attr_ability_type2" list="feats" class="show-feats" title="@{repeating_ability_$X_ability_type2}" placeholder="General" data-i18n-placeholder="general" value="" accept="Feat Type" /&gt; &lt;datalist id="feats" class="hidden"&gt; &lt;option value="Achievement" data-i18n="achievement"&gt;Achievement&lt;/option&gt; &lt;option value="Animal Companion" data-i18n="animalcompanion"&gt;Animal Companion&lt;/option&gt; &lt;option value="Animal Familiar" data-i18n="animalfamiliar"&gt;Animal/Familiar&lt;/option&gt; &lt;/datalist&gt; I have added the key=value pairs to the translation.json and used the appropriate syntax in a macro ie ^{@{ability_type2}} But nothing from the datalist is being translated in chat when called using a macro with the sheet's roll template. ie [red text within square brackets] I found that datalist translation may be problematic on the wiki: <a href="https://wiki.roll20.net/Character_Sheet_Translation#Datalist" rel="nofollow">https://wiki.roll20.net/Character_Sheet_Translation#Datalist</a> Of course it is... lol so I tried to modify the wiki example to match my sheet; substituted "repeating_inventory" with "repeating_ability" and "name" with "ability_type2".&nbsp; I wasn't sure how to deal with the "GLOBAL__INVENTORY_INPUTS" or "GLOBAL__INVENTORY" variables since my code doesn't have either.&nbsp; I only need to translate the ability_type2 attribute.&nbsp; So I carefully removed them with a battle axe. ;-) Here's the wiki example along with the GLOBAL__INVENTORY_INPUTS and GLOBAL__INVENTORY shortened samples from the ARC sheet. const GLOBAL__INVENTORY_INPUTS = [ "name", "type", "description" ]; const GLOBAL__INVENTORY = { combat_scowling_face: { type: "damage_and_defense", complexity: 0, }, combat_pitchfork: { type: "damage_and_defense", complexity: 0, }, techniques_doompause: { type: "spells_and_techniques", complexity: 0, }, }; on("change:repeating_inventory:name", (eventInfo) =&gt; { const id = eventInfo.sourceAttribute.split("_")[2]; const updateAttrs = {}; const name = eventInfo.newValue.trim(); let translation = getTranslationByKey(name) if (translation) { updateAttrs[`repeating_inventory_${id}_name`] = translation; const searchInputs = _.difference(GLOBAL__INVENTORY_INPUTS, ["name"]); _.each(searchInputs, (key) =&gt; { const attr = `repeating_inventory_${id}_${key}`; const i18n = `${name}_${key}`; // check if property exists in global if (GLOBAL__INVENTORY[name][key]) { updateAttrs[attr] = GLOBAL__INVENTORY[name][key]; } // check if translation exists else if (getTranslationByKey(i18n)) { updateAttrs[attr] = getTranslationByKey(i18n); } }); log(updateAttrs) setAttrs(updateAttrs, { silent: true }); } }); And here's how I've tried to adjust the example to work for me.&nbsp; Console log shows when an unknown translation has been entered for ability_type2, but I'm still seeing untranslated text in chat. on("change:repeating_ability:ability_type2", (eventInfo) =&gt; { &nbsp;&nbsp;&nbsp; const id = eventInfo.sourceAttribute.split("_")[2]; &nbsp;&nbsp;&nbsp; const updateAttrs = {}; &nbsp;&nbsp;&nbsp; const featName = eventInfo.newValue.replace(/\s/g, '').toLowerCase(); &nbsp;&nbsp;&nbsp; let translation = getTranslationByKey(featName) &nbsp;&nbsp;&nbsp; if (translation) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; updateAttrs[`repeating_ability_${id}_ability_type2`] = translation; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; const attr = `repeating_ability_${id}_ability_type2`; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; const i18n = `${featName}`; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (getTranslationByKey(i18n)) { &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; updateAttrs[attr] = getTranslationByKey(i18n); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TAS.debug(updateAttrs); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setAttrs(updateAttrs, { silent: true }); &nbsp;&nbsp;&nbsp; } &nbsp; }); Thanks in advanced for any help/suggestions.
1680691663

Edited 1680692531
GiGs
Pro
Sheet Author
API Scripter
I havent done much with translations, and I'm watching eagerly to see if yo get an answer. Are you seeing untranslated text when a translation really exists? I'd be checking that the if branch is running properly with a console and examine whether the values it is finding are valid:: if (translation) { console.info({featName, translation});
1680740558

Edited 1680740656
vÍnce
Pro
Sheet Author
It appears that the translation happens on the sheet, but it's not happening in chat... The macro above included {{subtitle=^{@{rule_category}} - ^{@{ability_type2}}}} I did a similar test with the ARC sheet and it appears to translate on the sheet just fine, but also fails to translate in chat; In my ARC test, first line is a datalist attribute and the second line is a select. Seems like a bug, but I'm not 100% sure I'm implementing it correctly.&nbsp; IDK
1680752075
GiGs
Pro
Sheet Author
API Scripter
Interesting. is it confirmed to work in chat? As you suspect, it might be a bug.
1680754471
vÍnce
Pro
Sheet Author
The wiki mentions they work with translation "If your sheet is adapted to use CSE, you can have tranlstions for your datalist options." but directly below that is "There seems to be an issue with translation of datalists as the value of the option is entered as the value of the input which links to the list. The ARC sheet&nbsp; <a href="https://github.com/Roll20/roll20-character-sheets/tree/master/ARC" rel="nofollow">https://github.com/Roll20/roll20-character-sheets/tree/master/ARC</a> &nbsp;has a workaround with a sheet worker that replaces the value with the translated text." I wonder if I even need to use the special translation syntax in the macro ( ie ^{ [key] } ) since it appears the sheet worker IS changing the value of the datalist input to the translated text.&nbsp; Maybe I can test this by grabbing a non-english translation file, and simply use @{ability_type2} in the macro.&nbsp; If the text shows as translated, no need for&nbsp;^{ [key] }, but if the text is still the english version, there may be a bug or limitation with datalist translation in roll templates.
1680758496
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
translations don't really work with datalists unfortunately because the value that is entered is what the native speaker would enter, rather than the translation key.
1680760012
vÍnce
Pro
Sheet Author
1. The datalist with i18n options should show up as being translated, correct? 2. However, if a user picks from the list, it will only be displayed in chat as the selected option's value (ie English)?&nbsp; 3. Otherwise, if the user enters a custom value it will display as their custom value regardless of translations, correct? That kind of works I suppose.