Skip to content
GitHub

defineCatalog

function in meocord/common Since 4.1.0

defineCatalog<const T extends CatalogShape>(catalog: CatalogDefinition<T>): T

Declares a message catalog, keeping each message's text as its type so the params it takes can be checked.

A default catalog declared apart from createTranslator needs it, or as const. Other locales compile without it, but only one that keeps its text has its {params} checked when the code compiles.

Parameters

NameTypeDescription
catalogCatalogDefinition<T>

Messages, plurals and nested groups of them.

Returns

T

The catalog, unchanged.

Examples

TypeScript
// src/locales/en-US.ts
export default defineCatalog({
  ban: { description: 'Ban a member', done: 'Banned {user}.' },
  warnings: { one: '{count} warning', other: '{count} warnings' },
})