[Community PR] Localize hardcoded text (#1002)

* Localize remaining hardcoded user-facing strings

* Introduce pluralize helper for localizing strings

* Localize missing strings from ItemBrowser
This commit is contained in:
Luiz HD Costa 2025-08-21 22:35:36 -03:00 committed by GitHub
parent e9f7c0c16b
commit 888cf9172b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 147 additions and 82 deletions

View file

@ -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);
}
}