fvtt-fria-ligan / morkborg-foundry-vtt

An unoffical, community-supported system for playing MÖRK BORG on Foundry VTT.
Other
33 stars 17 forks source link

Localize broken table #161

Open mcglincy opened 1 year ago

mcglincy commented 1 year ago

Switching Broken to a roll table is nice, but is there a way for a roll table result to automatically be localized? (e.g., have keys to localizable strings, that also handle [[d4]] embedding?)

mcglincy commented 1 year ago

It'd be possible to localize the result text before handing back, if the text started with a translation key token or similar.

e.g.,

const isTranslationKey = (str) => { return str?.startsWith("MB.");};
export const localizedDrawFromTable = async (actor) => { const tableDraw = await drawFromTable("morkborg.random-tables", "Broken");
 for (const tableResult of tableDraw.results) { if (tableResult.text && isTranslationKey(tableResult.text)) { tableResult.text = game.i18n.localize(tableResult.text); console.log(tableResult.text); } } return tableDraw;};

But that means roll tables manually rolled on from a compendium etc wouldn't do the translation. I guess a more fully featured module could override default Foundry's table draw?