mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
[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:
parent
e9f7c0c16b
commit
888cf9172b
9 changed files with 147 additions and 82 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue