Missing translations module
The Missing translations module turns Messagevisor's built-in missing-translation diagnostics into a small handler API for application logging, analytics, or developer tooling.
Installation#
$ npm install @messagevisor/module-missing-translationsUsage#
import { createMessagevisor } from "@messagevisor/sdk";import { createMissingTranslationsModule } from "@messagevisor/module-missing-translations";const m = createMessagevisor({ datafile, modules: [ createMissingTranslationsModule({ handler({ messageKey, locale, revision }) { console.warn("Missing translation", { messageKey, locale, revision }); }, }), ],});The module listens for the SDK's missing_translation diagnostic. It does not change translation fallback behavior.
Handler payload#
The handler receives:
| Field | Description |
|---|---|
messageKey | Message key whose translation could not be resolved |
locale | Locale active when the missing translation was reported, or null |
revision | Datafile revision for the locale, when available |
source | Diagnostic source such as translation or formatMessage |
diagnostic | Original MessagevisorDiagnostic object emitted by the SDK |
revision is read through the SDK module API. If the locale has no loaded datafile, the module omits revision rather than interrupting translation evaluation.
Deduping#
By default, the handler runs every time a missing translation is reported.
createMissingTranslationsModule({ handler(payload) { analytics.track("missing_translation", payload); },});Enable dedupe when you only want one call per message key, locale, revision, and source for the lifetime of the module instance:
createMissingTranslationsModule({ dedupe: true, handler(payload) { analytics.track("missing_translation", payload); },});Custom name#
The default module name is missing-translations. You can override it when registering multiple diagnostics-related modules:
createMissingTranslationsModule({ name: "missing-copy-reporter", handler(payload) { reportMissingTranslation(payload); },});
