Skip to content

scopeLocalizer

Jason Godesky edited this page Jul 19, 2026 · 1 revision

scopeLocalizer returns a version of game.i18n.localize with a prefix always prepended to it.

Parameters

...prefix: string[]

The strings provided are concatenated with periods between them, so you can write it as one dot-separated string like you might normally, as an array of strings, or any combination.

// These all do the same thing.
scopeLocalizer('path.to.section')
scopeLocalizer('path', 'to', 'section')
scopeLocalizer('path.to', 'section')
scopeLocalizer('path', 'to.section')

Returns

A new method that you can call like game.i18n.localize, where the prefix can be assumed.

Examples

import { scopeLocalizer } from '@revolutionarygamesco/common-foundryvtt'

// If your dictionary has a bunch of entries under my-module.exclamations...
const t = scopeLocalizer('my-module', 'exclamations')
t('gadzooks') // my-module.exclamations.gadzooks
t('gumdang') // my-module.exclamations.gumdang
t('blast') // my-module.exclamations.blast

Clone this wiki locally