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, a translation of another shape than the default's, a text for a plural or a group, or a plural for a text, and each
{param} a translation uses that the message it translates doesn't take. An empty translation, '' or null, counts
as lacking, as the translator reads it as missing. 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. An object in the default catalog counts as
a plural only when its every key is a plural category, so a group with an other key is a group, and a translation
is read by the default catalog's shapes, as the translator reads it: one that keeps only a group's other message
lacks the group's other messages.
Parameters
| Name | Type |
|---|---|
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.')
})