new consumable types

Tried adding localization strings for some new consumable types, but keep getting this ("DND5E.Consumable[...]") no matter what. I'm 99% I have followed all guides on localization to the point. en.json in the module.json, etc etc, with all the needed strings inside.
No description
40 Replies
Calego
Calego•3y ago
How are you adding new consumable types?
Zhell
Zhell•3y ago
Hooks.on('ready'), overriding CONFIG.DND5E.consumableTypes
Calego
Calego•3y ago
kk, looks like CONFIG.DND5E.consumableTypes has the output of game.i18n.localize cached during setup hook, So adding to that after that point you'll need to provide the already-localized versions
Calego
Calego•3y ago
https://gitlab.com/foundrynet/dnd5e/-/blob/master/dnd5e.js#L149 This little thing does that, it runs through the CONFIG.DND5E keys provided and replaces the values with their localized versions
GitLab
dnd5e.js · master · Foundry Network / Foundry VTT 5th Edition
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com). This work is permitted under the Open...
Zhell
Zhell•3y ago
I'd just add that hook (on 'setup'?), as is, with localizeKeys and sortKeys = ['consumableTypes'] ? Easy as that? 🤔
Calego
Calego•3y ago
nono, you'd want something like this:
Hooks.on('ready', () => {
CONFIG.DND5E.consumableTypes = {
foo: game.i18n.localize('MY_KEY')
}
})
Hooks.on('ready', () => {
CONFIG.DND5E.consumableTypes = {
foo: game.i18n.localize('MY_KEY')
}
})
the important thing is that you do the game.i18n.localize part yourself, since the 5e system believes it doesn't need to when it uses values from CONFIG.DND5E.consumableTypes
Zhell
Zhell•3y ago
What is MY_KEY in this example? Tried CONFIG.DND5E.consumableTypes.elixir = game.i18n.localize("DND5E.ConsumableElixir") in the console as a test, but that changes its name to... well DND5E.ConsumableElixir
Calego
Calego•3y ago
MY_KEY is a localization key you would define in your module's en.json. I wouldn't recommend using DND5E.Whatever as that implies it was added by the dnd5e package. Here's a more complete example:
// en.json
{
"my-module-id": {
"ELIXIR": "Elixir"
}
}
// en.json
{
"my-module-id": {
"ELIXIR": "Elixir"
}
}
Hooks.on('ready', () => {
CONFIG.DND5E.consumableTypes = {
elixir: game.i18n.localize('my-module-id.ELIXIR'),
somethingElse: "Something Else that Isn't Localized", // also works, just can't be translated
}
})
Hooks.on('ready', () => {
CONFIG.DND5E.consumableTypes = {
elixir: game.i18n.localize('my-module-id.ELIXIR'),
somethingElse: "Something Else that Isn't Localized", // also works, just can't be translated
}
})
// after the `ready` hook:
console.log(CONFIG.DND5E.consumableTypes.elixir); // Expected: "Elixir"
console.log(CONFIG.DND5E.consumableTypes.somethingElse); // Expected: "Something Else that Isn't Localized"
// after the `ready` hook:
console.log(CONFIG.DND5E.consumableTypes.elixir); // Expected: "Elixir"
console.log(CONFIG.DND5E.consumableTypes.somethingElse); // Expected: "Something Else that Isn't Localized"
You could do this in your en.json:
{
"DND5E.ConsumableElixir": "Elixir"
}
{
"DND5E.ConsumableElixir": "Elixir"
}
To make what you pasted here work, but this is not recommended.
Zhell
Zhell•3y ago
But that is what I had done. 🤔
Calego
Calego•3y ago
curious can you paste what you've got in here? or is it hosted somewhere we can see?
Zhell
Zhell•3y ago
en.json?
Calego
Calego•3y ago
and the bit of your js that deals with the hook
Zhell
Zhell•3y ago
{
"DND5E.ConsumablePotionTonic": "Tonic",
"DND5E.ConsumablePotionSalve": "Salve",
"DND5E.ConsumablePotionPill": "Pill",
"DND5E.ConsumablePotionWine": "Wine",
"DND5E.ConsumablePoisonIngested": "Ingested Poison",
"DND5E.ConsumablePoisonInhaled": "Inhaled Poison",
"DND5E.ConsumablePoisonInjury": "Injury Poison",
"DND5E.ConsumablePoisonContact": "Contact Poison",
"DND5E.ConsumableDrink": "Drink",
"DND5E.ConsumableTrap": "Trap",
"DND5E.ConsumableBomb": "Bomb",
"DND5E.ConsumableElixir": "Elixir",
}
{
"DND5E.ConsumablePotionTonic": "Tonic",
"DND5E.ConsumablePotionSalve": "Salve",
"DND5E.ConsumablePotionPill": "Pill",
"DND5E.ConsumablePotionWine": "Wine",
"DND5E.ConsumablePoisonIngested": "Ingested Poison",
"DND5E.ConsumablePoisonInhaled": "Inhaled Poison",
"DND5E.ConsumablePoisonInjury": "Injury Poison",
"DND5E.ConsumablePoisonContact": "Contact Poison",
"DND5E.ConsumableDrink": "Drink",
"DND5E.ConsumableTrap": "Trap",
"DND5E.ConsumableBomb": "Bomb",
"DND5E.ConsumableElixir": "Elixir",
}
custom-itemTypes.mjs:
Hooks.on('ready', () => {
if(!game.settings.get(MODULE_NAME, SETTING_NAMES.REPLACE_CONSUMABLE_TYPES)) return;

CONFIG.DND5E.consumableTypes = {
ammo: "Ammunition",
bomb: "Bomb",
drink: "Drink",
food: "Food",
poison: "Poison",
poisonContact: "Contact Poison",
poisonIngested: "Ingested Poison",
poisonInhaled: "Inhaled Poison",
poisonInjury: "Injury Poison",
potion: "Potion",
potionTonic: "Tonic",
potionSalve: "Salve",
potionPill: "Pill",
potionWine: "Wine",
scroll: "Scroll",
trap: "Trap",
trinket: "Trinket",
elixir: "Elixir"
};
});
Hooks.on('ready', () => {
if(!game.settings.get(MODULE_NAME, SETTING_NAMES.REPLACE_CONSUMABLE_TYPES)) return;

CONFIG.DND5E.consumableTypes = {
ammo: "Ammunition",
bomb: "Bomb",
drink: "Drink",
food: "Food",
poison: "Poison",
poisonContact: "Contact Poison",
poisonIngested: "Ingested Poison",
poisonInhaled: "Inhaled Poison",
poisonInjury: "Injury Poison",
potion: "Potion",
potionTonic: "Tonic",
potionSalve: "Salve",
potionPill: "Pill",
potionWine: "Wine",
scroll: "Scroll",
trap: "Trap",
trinket: "Trinket",
elixir: "Elixir"
};
});
Calego
Calego•3y ago
I take back half of what I have said
Zhell
Zhell•3y ago
😬
Calego
Calego•3y ago
https://gitlab.com/foundrynet/dnd5e/-/blob/master/module/apps/ability-use-dialog.js#L169 Here's where the string that's displayed is being composed. Spot the problem
GitLab
module/apps/ability-use-dialog.js · master · Foundry Network / Foun...
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com). This work is permitted under the Open...
Calego
Calego•3y ago
type: game.i18n.localize(`DND5E.Consumable${item.data.consumableType.capitalize()}`),
type: game.i18n.localize(`DND5E.Consumable${item.data.consumableType.capitalize()}`),
Instead of assuming that the value desired is in CONFIG.DND5E.consumableTypes... the localization string is constructed ad-hoc out of the consumable type on the item. sigh SO, You definitely need to add these strings to the en.json with the DND5E. prefix And, since this doesn't really care about the consumableTypes value, you need to make sure your key is structured so that it's going to work with that capitalize()
Zhell
Zhell•3y ago
ie 'elixir' should work but not 'potionPill'
Calego
Calego•3y ago
"DND5E.ConsumablePotionTonic": "Tonic", Might need to be: "DND5E.ConsumablePotiontonic": "Tonic", capitalize apparently isn't a normal string method... so I can't tell but in-foundry try this from console:
'potionTonic'.capitalize()
'potionTonic'.capitalize()
Zhell
Zhell•3y ago
returns 'PotionTonic'
Calego
Calego•3y ago
wtf
Zhell
Zhell•3y ago
🤷
No description
Calego
Calego•3y ago
so then potionTonic would end up looking for DND5E.ConsumablePotionTonic, which you have...
Zhell
Zhell•3y ago
Yeah and Elixir, Bomb, etc etc, they should all work (... also apparently 'ammo' doesn't work either. I didn't add that, I just kept it in because I wanted to keep it)
Calego
Calego•3y ago
Ok, you said you tried game.i18n.localize(... from console and it didn't do it? like just as a test of the localization setup
Zhell
Zhell•3y ago
No description
Zhell
Zhell•3y ago
Interestingly...
No description
Zhell
Zhell•3y ago
and just for good measure
No description
Calego
Calego•3y ago
if there's no key found it spits back what you give it show me your module manifest in full
Zhell
Zhell•3y ago
{
"name": "zhell-custom-stuff",
"title": "Zhell's Custom Stuff",
"description": "Personal module for replacing or adding to many things. Modular.",
"version": "3.83",
"author": "Zhell",
"minimumCoreVersion": "9",
"compatibleCoreVersion": "9",
"packs": [
{
"name": "base-items",
"label": "Base Items",
"path": "./packs/base-items.db",
"entity": "Item",
"type": "Item"
}
],
"esmodules": [
"./setup.js",
"./scripts/custom-conditions.mjs",
"./scripts/custom-languages.mjs",
"./scripts/custom-profs.mjs",
"./scripts/custom-progression.mjs",
"./scripts/custom-recharge.mjs",
"./scripts/custom-itemTypes.mjs"
],
"languages": [
{
"lang": "en",
"name": "English",
"path": "languages/en.json"
}
]
}
{
"name": "zhell-custom-stuff",
"title": "Zhell's Custom Stuff",
"description": "Personal module for replacing or adding to many things. Modular.",
"version": "3.83",
"author": "Zhell",
"minimumCoreVersion": "9",
"compatibleCoreVersion": "9",
"packs": [
{
"name": "base-items",
"label": "Base Items",
"path": "./packs/base-items.db",
"entity": "Item",
"type": "Item"
}
],
"esmodules": [
"./setup.js",
"./scripts/custom-conditions.mjs",
"./scripts/custom-languages.mjs",
"./scripts/custom-profs.mjs",
"./scripts/custom-progression.mjs",
"./scripts/custom-recharge.mjs",
"./scripts/custom-itemTypes.mjs"
],
"languages": [
{
"lang": "en",
"name": "English",
"path": "languages/en.json"
}
]
}
Calego
Calego•3y ago
oh you're gonna hate this
"DND5E.ConsumableElixir": "Elixir",
}
"DND5E.ConsumableElixir": "Elixir",
}
trailing comma
Zhell
Zhell•3y ago
You're right.
Calego
Calego•3y ago
did that do it?
Zhell
Zhell•3y ago
Gonna test real quick, but hold on, there are commas in the system folder's en.json
Calego
Calego•3y ago
it's the trailing comma that makes JSON mad i.e. the last one shouldn't have a comma, the rest should
Zhell
Zhell•3y ago
oh gosh darn it
Calego
Calego•3y ago
yup may I recommend #screaming-into-the-void that was a journey lol
Zhell
Zhell•3y ago
It works now. facepalmpicard Thank you.
Calego
Calego•3y ago
happy to help 🙂