expectCompleteCatalog
function in meocord/testing Since 4.1.0
expectCompleteCatalog(
translator: Translator<any>,
options?: { meocord?: boolean },
): voidChecks that every locale translates every message, and throws listing each gap, locale by locale.
Use it in a test for a team that wants no fallback in production. It reports the messages a locale lacks, the
messages the default catalog doesn't have, the plural forms a language needs but a plural lacks, such as few for
Russian, and each {param} a translation uses that the message it translates doesn't take. It reads the catalogs'
own strings, so it checks the params of a catalog from a plain variable or a JSON file too, which the compiler
can't.
Parameters
| Name | Type | Description |
|---|---|---|
translator | Translator<any> | A translator made by |
options? | { meocord?: boolean } | |
options.meocord? | boolean | Whether every locale that is not English must translate each of MeoCord's own texts. |
Throws
Error listing every gap; nothing when the catalogs are complete.
Examples
import { expect, it } from 'vitest'
const t = createTranslator({
default: 'en-US',
locales: { 'en-US': { greet: 'Hello' }, id: { greet: 'Halo' } },
})
it('translates every message', () => {
expectCompleteCatalog(t)
})
it("names MeoCord's texts a locale has not translated", () => {
expect(() => expectCompleteCatalog(t, { meocord: true })).toThrow('missing meocord.')
})