@messagevisor/module-missing-translations 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [0.1.0](https://github.com/messagevisor/messagevisor/compare/v0.0.2...v0.1.0) (2026-05-31)
7
+
8
+ **Note:** Version bump only for package @messagevisor/module-missing-translations
9
+
10
+
11
+
12
+
13
+
14
+ ## 0.0.2 (2026-05-31)
15
+
16
+ **Note:** Version bump only for package @messagevisor/module-missing-translations
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Fahad Heylaal (https://fahad19.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @messagevisor/module-missing-translations
2
+
3
+ Visit [https://messagevisor.com/docs/modules/missing-translations/](https://messagevisor.com/docs/modules/missing-translations/) for more information.
4
+
5
+ ## License
6
+
7
+ MIT © [Fahad Heylaal](https://fahad19.com)
package/jest.config.js ADDED
@@ -0,0 +1,11 @@
1
+ const base = require("../../jest.config");
2
+
3
+ module.exports = {
4
+ ...base,
5
+ rootDir: "../..",
6
+ testRegex: undefined,
7
+ testMatch: ["<rootDir>/packages/module-missing-translations/src/**/*.spec.ts"],
8
+ moduleNameMapper: {
9
+ "^@messagevisor/sdk$": "<rootDir>/packages/sdk/src/index.ts",
10
+ },
11
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { MessagevisorDiagnostic, MessagevisorModule, MessagevisorTranslationSource } from "@messagevisor/sdk";
2
+ export interface MissingTranslationPayload {
3
+ messageKey: string;
4
+ locale: string | null;
5
+ revision?: string;
6
+ source?: MessagevisorTranslationSource;
7
+ diagnostic: MessagevisorDiagnostic;
8
+ }
9
+ export interface MissingTranslationsModuleOptions {
10
+ name?: string;
11
+ handler: (payload: MissingTranslationPayload) => void;
12
+ dedupe?: boolean;
13
+ }
14
+ export declare function createMissingTranslationsModule(options: MissingTranslationsModuleOptions): MessagevisorModule;
package/lib/index.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMissingTranslationsModule = createMissingTranslationsModule;
4
+ function getDedupeKey(payload) {
5
+ return JSON.stringify([
6
+ payload.messageKey,
7
+ payload.locale,
8
+ payload.revision || null,
9
+ payload.source || null,
10
+ ]);
11
+ }
12
+ function createMissingTranslationsModule(options) {
13
+ const name = (options === null || options === void 0 ? void 0 : options.name) || "missing-translations";
14
+ const handler = options === null || options === void 0 ? void 0 : options.handler;
15
+ const dedupe = (options === null || options === void 0 ? void 0 : options.dedupe) === true;
16
+ const seen = new Set();
17
+ return {
18
+ name,
19
+ setup({ getRevision, onDiagnostic }) {
20
+ if (typeof handler !== "function") {
21
+ throw new Error("Missing translations module requires a handler.");
22
+ }
23
+ onDiagnostic((diagnostic) => {
24
+ if (diagnostic.code !== "missing_translation" || !diagnostic.messageKey) {
25
+ return;
26
+ }
27
+ const locale = diagnostic.locale || null;
28
+ let revision;
29
+ if (locale) {
30
+ try {
31
+ revision = getRevision(locale);
32
+ }
33
+ catch (_a) {
34
+ revision = undefined;
35
+ }
36
+ }
37
+ const payload = {
38
+ messageKey: diagnostic.messageKey,
39
+ locale,
40
+ revision,
41
+ source: diagnostic.source,
42
+ diagnostic,
43
+ };
44
+ if (dedupe) {
45
+ const dedupeKey = getDedupeKey(payload);
46
+ if (seen.has(dedupeKey)) {
47
+ return;
48
+ }
49
+ seen.add(dedupeKey);
50
+ }
51
+ handler(payload);
52
+ }, { logLevel: "error" });
53
+ },
54
+ };
55
+ }
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AA6BA,0EAwDC;AAjED,SAAS,YAAY,CAAC,OAAkC;IACtD,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,OAAO,CAAC,UAAU;QAClB,OAAO,CAAC,MAAM;QACd,OAAO,CAAC,QAAQ,IAAI,IAAI;QACxB,OAAO,CAAC,MAAM,IAAI,IAAI;KACvB,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,+BAA+B,CAC7C,OAAyC;IAEzC,MAAM,IAAI,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,KAAI,sBAAsB,CAAC;IACrD,MAAM,OAAO,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC;IACjC,MAAM,MAAM,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,MAAK,IAAI,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,OAAO;QACL,IAAI;QACJ,KAAK,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE;YACjC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACrE,CAAC;YAED,YAAY,CACV,CAAC,UAAU,EAAE,EAAE;gBACb,IAAI,UAAU,CAAC,IAAI,KAAK,qBAAqB,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;oBACxE,OAAO;gBACT,CAAC;gBAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,IAAI,IAAI,CAAC;gBACzC,IAAI,QAA4B,CAAC;gBAEjC,IAAI,MAAM,EAAE,CAAC;oBACX,IAAI,CAAC;wBACH,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;oBACjC,CAAC;oBAAC,WAAM,CAAC;wBACP,QAAQ,GAAG,SAAS,CAAC;oBACvB,CAAC;gBACH,CAAC;gBAED,MAAM,OAAO,GAA8B;oBACzC,UAAU,EAAE,UAAU,CAAC,UAAU;oBACjC,MAAM;oBACN,QAAQ;oBACR,MAAM,EAAE,UAAU,CAAC,MAAM;oBACzB,UAAU;iBACX,CAAC;gBAEF,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;oBAExC,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;wBACxB,OAAO;oBACT,CAAC;oBAED,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBACtB,CAAC;gBAED,OAAO,CAAC,OAAO,CAAC,CAAC;YACnB,CAAC,EACD,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,44 @@
1
1
  {
2
- "name": "@messagevisor/module-missing-translations",
3
- "version": "0.0.1",
4
- "description": "Messagevisor package",
5
- "license": "ISC",
6
- "author": "",
7
- "type": "commonjs",
8
- "main": "index.js",
9
- "publishConfig": {
10
- "access": "public"
11
- },
12
- "scripts": {
13
- "test": "echo \"Error: no test specified\" && exit 1"
14
- }
2
+ "name": "@messagevisor/module-missing-translations",
3
+ "version": "0.1.0",
4
+ "description": "Missing translations reporting module for Messagevisor",
5
+ "main": "lib/index.js",
6
+ "module": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "require": "./lib/index.js",
12
+ "import": "./lib/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "scripts": {
17
+ "transpile": "rimraf lib && tsc --project tsconfig.cjs.json",
18
+ "dist": "echo 'Nothing to dist here'",
19
+ "build": "npm run transpile",
20
+ "test": "jest --config jest.config.js --verbose",
21
+ "typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.typecheck.json"
22
+ },
23
+ "author": {
24
+ "name": "Fahad Heylaal",
25
+ "url": "https://fahad19.com"
26
+ },
27
+ "homepage": "https://messagevisor.com",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/messagevisor/messagevisor.git"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "registry": "https://registry.npmjs.org/"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/messagevisor/messagevisor/issues"
38
+ },
39
+ "license": "MIT",
40
+ "dependencies": {
41
+ "@messagevisor/sdk": "0.1.0"
42
+ },
43
+ "gitHead": "555119ab05473127a658ed0cfb6a2743ea3a6db8"
15
44
  }
@@ -0,0 +1,130 @@
1
+ import { createMessagevisor } from "@messagevisor/sdk";
2
+ import type { DatafileContent } from "@messagevisor/types";
3
+
4
+ import { createMissingTranslationsModule, type MissingTranslationPayload } from "./index";
5
+
6
+ const datafile: DatafileContent = {
7
+ schemaVersion: "1",
8
+ messagevisorVersion: "0.0.1",
9
+ revision: "rev-1",
10
+ target: "web",
11
+ locale: "en-US",
12
+ segments: {},
13
+ messages: {
14
+ greeting: {},
15
+ },
16
+ translations: {
17
+ greeting: "Hello",
18
+ },
19
+ };
20
+
21
+ describe("@messagevisor/module-missing-translations", function () {
22
+ it("calls the handler when a translation is missing", function () {
23
+ const calls: MissingTranslationPayload[] = [];
24
+ const m = createMessagevisor({
25
+ datafile,
26
+ logLevel: "fatal",
27
+ modules: [
28
+ createMissingTranslationsModule({
29
+ handler(payload) {
30
+ calls.push(payload);
31
+ },
32
+ }),
33
+ ],
34
+ });
35
+
36
+ expect(m.translate("missing.key")).toEqual("missing.key");
37
+
38
+ expect(calls).toHaveLength(1);
39
+ expect(calls[0]).toMatchObject({
40
+ messageKey: "missing.key",
41
+ locale: "en-US",
42
+ revision: "rev-1",
43
+ source: "translation",
44
+ diagnostic: {
45
+ code: "missing_translation",
46
+ level: "error",
47
+ messageKey: "missing.key",
48
+ locale: "en-US",
49
+ },
50
+ });
51
+ });
52
+
53
+ it("does not call the handler for non-missing diagnostics or successful translations", function () {
54
+ const calls: MissingTranslationPayload[] = [];
55
+ const m = createMessagevisor({
56
+ datafile,
57
+ logLevel: "fatal",
58
+ modules: [
59
+ createMissingTranslationsModule({
60
+ handler(payload) {
61
+ calls.push(payload);
62
+ },
63
+ }),
64
+ ],
65
+ });
66
+
67
+ expect(m.translate("greeting")).toEqual("Hello");
68
+ expect(calls).toEqual([]);
69
+ });
70
+
71
+ it("calls the handler every time by default", function () {
72
+ const calls: MissingTranslationPayload[] = [];
73
+ const m = createMessagevisor({
74
+ datafile,
75
+ logLevel: "fatal",
76
+ modules: [
77
+ createMissingTranslationsModule({
78
+ handler(payload) {
79
+ calls.push(payload);
80
+ },
81
+ }),
82
+ ],
83
+ });
84
+
85
+ m.translate("missing.key");
86
+ m.translate("missing.key");
87
+
88
+ expect(calls.map((call) => call.messageKey)).toEqual(["missing.key", "missing.key"]);
89
+ });
90
+
91
+ it("dedupes repeated missing translations when enabled", function () {
92
+ const calls: MissingTranslationPayload[] = [];
93
+ const m = createMessagevisor({
94
+ datafile,
95
+ logLevel: "fatal",
96
+ modules: [
97
+ createMissingTranslationsModule({
98
+ dedupe: true,
99
+ handler(payload) {
100
+ calls.push(payload);
101
+ },
102
+ }),
103
+ ],
104
+ });
105
+
106
+ m.translate("missing.key");
107
+ m.translate("missing.key");
108
+ m.getRawTranslation("missing.key");
109
+ m.translate("another.missing");
110
+
111
+ expect(calls.map((call) => call.messageKey)).toEqual(["missing.key", "another.missing"]);
112
+ });
113
+
114
+ it("requires a handler", function () {
115
+ expect(() =>
116
+ createMessagevisor({
117
+ datafile,
118
+ logLevel: "fatal",
119
+ modules: [createMissingTranslationsModule({} as any)],
120
+ }),
121
+ ).toThrow("Missing translations module requires a handler.");
122
+ });
123
+
124
+ it("uses a stable default module name and supports custom names", function () {
125
+ expect(createMissingTranslationsModule({ handler() {} }).name).toEqual("missing-translations");
126
+ expect(createMissingTranslationsModule({ name: "tracker", handler() {} }).name).toEqual(
127
+ "tracker",
128
+ );
129
+ });
130
+ });
package/src/index.ts ADDED
@@ -0,0 +1,86 @@
1
+ import type {
2
+ MessagevisorDiagnostic,
3
+ MessagevisorModule,
4
+ MessagevisorTranslationSource,
5
+ } from "@messagevisor/sdk";
6
+
7
+ export interface MissingTranslationPayload {
8
+ messageKey: string;
9
+ locale: string | null;
10
+ revision?: string;
11
+ source?: MessagevisorTranslationSource;
12
+ diagnostic: MessagevisorDiagnostic;
13
+ }
14
+
15
+ export interface MissingTranslationsModuleOptions {
16
+ name?: string;
17
+ handler: (payload: MissingTranslationPayload) => void;
18
+ dedupe?: boolean;
19
+ }
20
+
21
+ function getDedupeKey(payload: MissingTranslationPayload) {
22
+ return JSON.stringify([
23
+ payload.messageKey,
24
+ payload.locale,
25
+ payload.revision || null,
26
+ payload.source || null,
27
+ ]);
28
+ }
29
+
30
+ export function createMissingTranslationsModule(
31
+ options: MissingTranslationsModuleOptions,
32
+ ): MessagevisorModule {
33
+ const name = options?.name || "missing-translations";
34
+ const handler = options?.handler;
35
+ const dedupe = options?.dedupe === true;
36
+ const seen = new Set<string>();
37
+
38
+ return {
39
+ name,
40
+ setup({ getRevision, onDiagnostic }) {
41
+ if (typeof handler !== "function") {
42
+ throw new Error("Missing translations module requires a handler.");
43
+ }
44
+
45
+ onDiagnostic(
46
+ (diagnostic) => {
47
+ if (diagnostic.code !== "missing_translation" || !diagnostic.messageKey) {
48
+ return;
49
+ }
50
+
51
+ const locale = diagnostic.locale || null;
52
+ let revision: string | undefined;
53
+
54
+ if (locale) {
55
+ try {
56
+ revision = getRevision(locale);
57
+ } catch {
58
+ revision = undefined;
59
+ }
60
+ }
61
+
62
+ const payload: MissingTranslationPayload = {
63
+ messageKey: diagnostic.messageKey,
64
+ locale,
65
+ revision,
66
+ source: diagnostic.source,
67
+ diagnostic,
68
+ };
69
+
70
+ if (dedupe) {
71
+ const dedupeKey = getDedupeKey(payload);
72
+
73
+ if (seen.has(dedupeKey)) {
74
+ return;
75
+ }
76
+
77
+ seen.add(dedupeKey);
78
+ }
79
+
80
+ handler(payload);
81
+ },
82
+ { logLevel: "error" },
83
+ );
84
+ },
85
+ };
86
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "../../tsconfig.cjs.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "rootDir": "./src",
6
+ "moduleResolution": "node",
7
+ "esModuleInterop": true,
8
+ "target": "es2018",
9
+ "lib": ["es2021", "es2021.intl", "dom"],
10
+ "skipLibCheck": true
11
+ },
12
+ "include": ["./src/**/*.ts"],
13
+ "exclude": ["./src/**/*.spec.ts"]
14
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.cjs.json",
3
+ "exclude": []
4
+ }