diff --git a/module/helpers/handlebarsHelper.mjs b/module/helpers/handlebarsHelper.mjs index 171255e2..83220307 100644 --- a/module/helpers/handlebarsHelper.mjs +++ b/module/helpers/handlebarsHelper.mjs @@ -13,7 +13,8 @@ export default class RegisterHandlebarsHelpers { hasProperty: foundry.utils.hasProperty, getProperty: foundry.utils.getProperty, setVar: this.setVar, - empty: this.empty + empty: this.empty, + pluralize: this.pluralize }); } static add(a, b) { @@ -64,7 +65,7 @@ export default class RegisterHandlebarsHelpers { return isNumerical ? (!result ? 0 : Number(result)) : result; } - static setVar(name, value, context) { + static setVar(name, value) { this[name] = value; } @@ -72,4 +73,20 @@ export default class RegisterHandlebarsHelpers { if (!(typeof object === 'object')) return true; return Object.keys(object).length === 0; } + + /** + * Pluralize helper that returns the appropriate localized string based on count + * @param {number} count - The number to check for plurality + * @param {string} baseKey - The base localization key (e.g., "DAGGERHEART.GENERAL.Target") + * @returns {string} The localized singular or plural string + * + * Usage: {{pluralize currentTargets.length "DAGGERHEART.GENERAL.Target"}} + * Returns: "Target" if count is exactly 1, "Targets" if count is 0, 2+, or invalid + */ + static pluralize(count, baseKey) { + const numericCount = Number(count); + const isSingular = !isNaN(numericCount) && numericCount === 1; + const key = isSingular ? `${baseKey}.single` : `${baseKey}.plural`; + return game.i18n.localize(key); + } } diff --git a/templates/ui/chat/parts/target-part.hbs b/templates/ui/chat/parts/target-part.hbs index b014032d..af7e93b0 100644 --- a/templates/ui/chat/parts/target-part.hbs +++ b/templates/ui/chat/parts/target-part.hbs @@ -1,11 +1,11 @@
-
{{#if (gt currentTargets.length 1)}}{{localize "DAGGERHEART.GENERAL.Target.plural"}}{{else}}{{localize "DAGGERHEART.GENERAL.Target.single"}}{{/if}}
+
{{pluralize currentTargets.length "DAGGERHEART.GENERAL.Target"}}
{{#if (or (and targets.length (or (gt targetShort.hit 0) (gt targetShort.miss 0))) (and hasSave pendingSaves))}}
{{#if (or (gt targetShort.hit 0) (gt targetShort.miss 0))}} -
{{targetShort.hit}} {{#if (gt targetShort.hit 1)}}{{localize "DAGGERHEART.GENERAL.hit.single"}}{{else}}{{localize "DAGGERHEART.GENERAL.hit.plural"}}{{/if}}
-
{{targetShort.miss}} {{#if (gt targetShort.miss 1)}}{{localize "DAGGERHEART.GENERAL.miss.single"}}{{else}}{{localize "DAGGERHEART.GENERAL.miss.plural"}}{{/if}}
+
{{targetShort.hit}} {{pluralize targetShort.hit "DAGGERHEART.GENERAL.hit"}}
+
{{targetShort.miss}} {{pluralize targetShort.miss "DAGGERHEART.GENERAL.miss"}}
{{/if}} {{#if (and hasSave pendingSaves)}}
{{/if}}