@generaltranslation/compiler 1.3.25-odysseus.1 → 1.3.25-odysseus.4

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.
@@ -12,11 +12,11 @@ export interface TranslationContent {
12
12
  message: string;
13
13
  /** Pre-calculated hash for this content */
14
14
  hash: string;
15
- /** Optional ID from options: t("text", {id: "greeting"}) → "greeting" */
15
+ /** Optional ID from options: t("text", {$id: "greeting"}) → "greeting" */
16
16
  id?: string;
17
- /** Optional context from options: t("text", {context: "nav"}) → "nav" */
17
+ /** Optional context from options: t("text", {$context: "nav"}) → "nav" */
18
18
  context?: string;
19
- /** Optional maxChars from options: t("text", {maxChars: 10}) → 10 */
19
+ /** Optional maxChars from options: t("text", {$maxChars: 10}) → 10 */
20
20
  maxChars?: number;
21
21
  /** Optional format from options: t("text", {$format: "STRING"}) → "STRING" */
22
22
  format?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"StringCollector.d.ts","sourceRoot":"","sources":["../../src/state/StringCollector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6BAA6B;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,OAAO,CAAC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AE,GAAG,SAAS;IAI1E;;OAEG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIhE;;OAEG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIlE;;OAEG;IACH,KAAK,IAAI,IAAI;IAQb;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB;;OAEG;IACH,UAAU,IAAI,OAAO;IAUrB;;OAEG;IACH,wBAAwB,IAAI,kBAAkB,EAAE;IAIhD;;OAEG;IACH,oBAAoB,IAAI,cAAc,EAAE;IAIxC;;OAEG;IACH,sBAAsB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAIzD;;OAEG;IACH,qBAAqB,IAAI,kBAAkB,EAAE;IAI7C;;OAEG;IACH,SAAS,IAAI,yBAAyB;IAUtC;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI;CAqBpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"StringCollector.js","names":[],"sources":["../../src/state/StringCollector.ts"],"sourcesContent":["/**\n * String Collector - Manages translation content across two-pass transformation\n *\n * Pass 1: Collects translation strings, JSX content, and hash data\n * Pass 2: Injects collected data back into useGT()/getGT() calls\n */\n\n/**\n * Content extracted from a t() function call\n */\nexport interface TranslationContent {\n /** The string message: t(\"Hello world\") → \"Hello world\" */\n message: string;\n /** Pre-calculated hash for this content */\n hash: string;\n /** Optional ID from options: t(\"text\", {id: \"greeting\"}) → \"greeting\" */\n id?: string;\n /** Optional context from options: t(\"text\", {context: \"nav\"}) → \"nav\" */\n context?: string;\n /** Optional maxChars from options: t(\"text\", {maxChars: 10}) → 10 */\n maxChars?: number;\n /** Optional format from options: t(\"text\", {$format: \"STRING\"}) → \"STRING\" */\n format?: string;\n}\n\n/**\n * Content extracted from JSX translation components like <T>\n */\nexport interface TranslationJsx {\n /** Pre-calculated hash for this JSX content */\n hash: string;\n /** JSX children structure (serializable) */\n children?: unknown;\n /** Optional ID from props */\n id?: string;\n /** Optional context from props */\n context?: string;\n}\n\n/**\n * Just a hash value for simple hash injection\n */\nexport interface TranslationHash {\n /** The hash value to inject */\n hash: string;\n}\n\ntype SerializedStringCollector = {\n contentAggregators: Record<string, TranslationContent[]>;\n jsxAggregators: Record<string, TranslationJsx>;\n hashAggregators: Record<string, TranslationHash>;\n globalCallCounter: number;\n};\n\n/**\n * String collector for two-pass transformation system\n */\nexport class StringCollector {\n /** Vector of translation calls indexed by counter ID */\n private contentAggregators: Map<number, TranslationContent[]> = new Map();\n private jsxAggregators: Map<number, TranslationJsx> = new Map();\n private hashAggregators: Map<number, TranslationHash> = new Map();\n /** Global counter incremented for each useGT/getGT call encountered */\n private globalCallCounter: number = 0;\n /** Runtime-only entries for standalone strings consumed by runtime translate */\n private runtimeOnlyEntries: TranslationContent[] = [];\n\n /**\n * Increment counter and return the current counter ID for a useGT/getGT call\n * These IDs are deterministic\n */\n incrementCounter(): number {\n this.globalCallCounter += 1;\n return this.globalCallCounter;\n }\n\n /**\n * Get current global counter value\n */\n getCounter(): number {\n return this.globalCallCounter;\n }\n\n /**\n * Pass 1: Add translation content from a gt() call to a specific useGT/getGT aggregator\n * Multiple content items can be added to the same call\n */\n pushTranslationContent(counterId: number, content: TranslationContent): void {\n if (counterId === -1) {\n throw new Error(\n 'Cannot have a counterId of -1. This likely means you are trying to register content from a namespace method invocation.'\n );\n }\n // Get the agreggator\n let aggregator = this.contentAggregators.get(counterId);\n if (!aggregator) {\n aggregator = [content];\n this.contentAggregators.set(counterId, aggregator);\n } else {\n aggregator.push(content);\n }\n }\n\n /**\n * Pass 1: Set JSX translation content for a specific useGT/getGT\n * Only one JSX item can be set per call (overwrites if called multiple times)\n */\n setTranslationJsx(counterId: number, jsx: TranslationJsx): void {\n this.jsxAggregators.set(counterId, jsx);\n }\n\n /**\n * Pass 1: Set hash-only content for a specific useGT/getGT\n * Only one hash can be set per call (overwrites if called multiple times)\n */\n setTranslationHash(counterId: number, hash: TranslationHash): void {\n this.hashAggregators.set(counterId, hash);\n }\n\n /**\n * Pass 2: Get translation call data for injection into a specific useGT/getGT call\n */\n getTranslationData(counterId: number):\n | {\n type: 'content' | 'jsx' | 'hash';\n value: TranslationContent[] | TranslationJsx | TranslationHash;\n }\n | undefined {\n if (this.contentAggregators.has(counterId)) {\n return {\n type: 'content',\n value: this.contentAggregators.get(counterId)!,\n };\n } else if (this.jsxAggregators.has(counterId)) {\n return { type: 'jsx', value: this.jsxAggregators.get(counterId)! };\n } else if (this.hashAggregators.has(counterId)) {\n return { type: 'hash', value: this.hashAggregators.get(counterId)! };\n }\n }\n\n /**\n * Get the translation content for a specific useGT/getGT call\n */\n getTranslationContent(counterId: number): TranslationContent[] | undefined {\n return this.contentAggregators.get(counterId);\n }\n\n /**\n * Get the translation JSX for a specific <T> component\n */\n getTranslationJsx(counterId: number): TranslationJsx | undefined {\n return this.jsxAggregators.get(counterId);\n }\n\n /**\n * Get the translation hash for a specific other call\n */\n getTranslationHash(counterId: number): TranslationHash | undefined {\n return this.hashAggregators.get(counterId);\n }\n\n /**\n * Reset all state (useful for testing)\n */\n clear(): void {\n this.contentAggregators.clear();\n this.jsxAggregators.clear();\n this.hashAggregators.clear();\n this.runtimeOnlyEntries = [];\n this.globalCallCounter = 0;\n }\n\n /**\n * Reset the counter to zero\n */\n resetCounter(): void {\n this.globalCallCounter = 0;\n }\n\n /**\n * Has content\n */\n hasContent(): boolean {\n return (\n this.contentAggregators.size +\n this.jsxAggregators.size +\n this.hashAggregators.size +\n this.runtimeOnlyEntries.length >\n 0\n );\n }\n\n /**\n * Get all translation content entries (flattened across all aggregators)\n */\n getAllTranslationContent(): TranslationContent[] {\n return Array.from(this.contentAggregators.values()).flat();\n }\n\n /**\n * Get all translation JSX entries\n */\n getAllTranslationJsx(): TranslationJsx[] {\n return Array.from(this.jsxAggregators.values());\n }\n\n /**\n * Add a runtime-only translation entry for the runtime translate pass.\n */\n pushRuntimeOnlyContent(content: TranslationContent): void {\n this.runtimeOnlyEntries.push(content);\n }\n\n /**\n * Get all runtime-only translation entries\n */\n getRuntimeOnlyContent(): TranslationContent[] {\n return this.runtimeOnlyEntries;\n }\n\n /**\n * Helper convert to string\n */\n serialize(): SerializedStringCollector {\n const output = {\n contentAggregators: Object.fromEntries(this.contentAggregators),\n jsxAggregators: Object.fromEntries(this.jsxAggregators),\n hashAggregators: Object.fromEntries(this.hashAggregators),\n globalCallCounter: this.globalCallCounter,\n };\n return output;\n }\n\n /**\n * Helper to repopulate\n */\n unserialize(input: SerializedStringCollector): void {\n this.contentAggregators = Object.entries(\n input.contentAggregators as Record<number, TranslationContent[]>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationContent[]>());\n this.jsxAggregators = Object.entries(\n input.jsxAggregators as Record<number, TranslationJsx>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationJsx>());\n this.hashAggregators = Object.entries(\n input.hashAggregators as Record<number, TranslationHash>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationHash>());\n this.globalCallCounter = input.globalCallCounter;\n }\n}\n"],"mappings":";;;;;AAyDA,IAAa,kBAAb,MAA6B;;4CAEqC,IAAI,KAAK;wCACnB,IAAI,KAAK;yCACP,IAAI,KAAK;2BAE7B;4BAEe,EAAE;;;;;;CAMrD,mBAA2B;AACzB,OAAK,qBAAqB;AAC1B,SAAO,KAAK;;;;;CAMd,aAAqB;AACnB,SAAO,KAAK;;;;;;CAOd,uBAAuB,WAAmB,SAAmC;AAC3E,MAAI,cAAc,GAChB,OAAM,IAAI,MACR,0HACD;EAGH,IAAI,aAAa,KAAK,mBAAmB,IAAI,UAAU;AACvD,MAAI,CAAC,YAAY;AACf,gBAAa,CAAC,QAAQ;AACtB,QAAK,mBAAmB,IAAI,WAAW,WAAW;QAElD,YAAW,KAAK,QAAQ;;;;;;CAQ5B,kBAAkB,WAAmB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AO;GALL,oBAAoB,OAAO,YAAY,KAAK,mBAAmB;GAC/D,gBAAgB,OAAO,YAAY,KAAK,eAAe;GACvD,iBAAiB,OAAO,YAAY,KAAK,gBAAgB;GACzD,mBAAmB,KAAK;GAEb;;;;;CAMf,YAAY,OAAwC;AAClD,OAAK,qBAAqB,OAAO,QAC/B,MAAM,mBACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAAmC,CAAC;AAC3C,OAAK,iBAAiB,OAAO,QAC3B,MAAM,eACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAA6B,CAAC;AACrC,OAAK,kBAAkB,OAAO,QAC5B,MAAM,gBACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAA8B,CAAC;AACtC,OAAK,oBAAoB,MAAM"}
1
+ {"version":3,"file":"StringCollector.js","names":[],"sources":["../../src/state/StringCollector.ts"],"sourcesContent":["/**\n * String Collector - Manages translation content across two-pass transformation\n *\n * Pass 1: Collects translation strings, JSX content, and hash data\n * Pass 2: Injects collected data back into useGT()/getGT() calls\n */\n\n/**\n * Content extracted from a t() function call\n */\nexport interface TranslationContent {\n /** The string message: t(\"Hello world\") → \"Hello world\" */\n message: string;\n /** Pre-calculated hash for this content */\n hash: string;\n /** Optional ID from options: t(\"text\", {$id: \"greeting\"}) → \"greeting\" */\n id?: string;\n /** Optional context from options: t(\"text\", {$context: \"nav\"}) → \"nav\" */\n context?: string;\n /** Optional maxChars from options: t(\"text\", {$maxChars: 10}) → 10 */\n maxChars?: number;\n /** Optional format from options: t(\"text\", {$format: \"STRING\"}) → \"STRING\" */\n format?: string;\n}\n\n/**\n * Content extracted from JSX translation components like <T>\n */\nexport interface TranslationJsx {\n /** Pre-calculated hash for this JSX content */\n hash: string;\n /** JSX children structure (serializable) */\n children?: unknown;\n /** Optional ID from props */\n id?: string;\n /** Optional context from props */\n context?: string;\n}\n\n/**\n * Just a hash value for simple hash injection\n */\nexport interface TranslationHash {\n /** The hash value to inject */\n hash: string;\n}\n\ntype SerializedStringCollector = {\n contentAggregators: Record<string, TranslationContent[]>;\n jsxAggregators: Record<string, TranslationJsx>;\n hashAggregators: Record<string, TranslationHash>;\n globalCallCounter: number;\n};\n\n/**\n * String collector for two-pass transformation system\n */\nexport class StringCollector {\n /** Vector of translation calls indexed by counter ID */\n private contentAggregators: Map<number, TranslationContent[]> = new Map();\n private jsxAggregators: Map<number, TranslationJsx> = new Map();\n private hashAggregators: Map<number, TranslationHash> = new Map();\n /** Global counter incremented for each useGT/getGT call encountered */\n private globalCallCounter: number = 0;\n /** Runtime-only entries for standalone strings consumed by runtime translate */\n private runtimeOnlyEntries: TranslationContent[] = [];\n\n /**\n * Increment counter and return the current counter ID for a useGT/getGT call\n * These IDs are deterministic\n */\n incrementCounter(): number {\n this.globalCallCounter += 1;\n return this.globalCallCounter;\n }\n\n /**\n * Get current global counter value\n */\n getCounter(): number {\n return this.globalCallCounter;\n }\n\n /**\n * Pass 1: Add translation content from a gt() call to a specific useGT/getGT aggregator\n * Multiple content items can be added to the same call\n */\n pushTranslationContent(counterId: number, content: TranslationContent): void {\n if (counterId === -1) {\n throw new Error(\n 'Cannot have a counterId of -1. This likely means you are trying to register content from a namespace method invocation.'\n );\n }\n // Get the agreggator\n let aggregator = this.contentAggregators.get(counterId);\n if (!aggregator) {\n aggregator = [content];\n this.contentAggregators.set(counterId, aggregator);\n } else {\n aggregator.push(content);\n }\n }\n\n /**\n * Pass 1: Set JSX translation content for a specific useGT/getGT\n * Only one JSX item can be set per call (overwrites if called multiple times)\n */\n setTranslationJsx(counterId: number, jsx: TranslationJsx): void {\n this.jsxAggregators.set(counterId, jsx);\n }\n\n /**\n * Pass 1: Set hash-only content for a specific useGT/getGT\n * Only one hash can be set per call (overwrites if called multiple times)\n */\n setTranslationHash(counterId: number, hash: TranslationHash): void {\n this.hashAggregators.set(counterId, hash);\n }\n\n /**\n * Pass 2: Get translation call data for injection into a specific useGT/getGT call\n */\n getTranslationData(counterId: number):\n | {\n type: 'content' | 'jsx' | 'hash';\n value: TranslationContent[] | TranslationJsx | TranslationHash;\n }\n | undefined {\n if (this.contentAggregators.has(counterId)) {\n return {\n type: 'content',\n value: this.contentAggregators.get(counterId)!,\n };\n } else if (this.jsxAggregators.has(counterId)) {\n return { type: 'jsx', value: this.jsxAggregators.get(counterId)! };\n } else if (this.hashAggregators.has(counterId)) {\n return { type: 'hash', value: this.hashAggregators.get(counterId)! };\n }\n }\n\n /**\n * Get the translation content for a specific useGT/getGT call\n */\n getTranslationContent(counterId: number): TranslationContent[] | undefined {\n return this.contentAggregators.get(counterId);\n }\n\n /**\n * Get the translation JSX for a specific <T> component\n */\n getTranslationJsx(counterId: number): TranslationJsx | undefined {\n return this.jsxAggregators.get(counterId);\n }\n\n /**\n * Get the translation hash for a specific other call\n */\n getTranslationHash(counterId: number): TranslationHash | undefined {\n return this.hashAggregators.get(counterId);\n }\n\n /**\n * Reset all state (useful for testing)\n */\n clear(): void {\n this.contentAggregators.clear();\n this.jsxAggregators.clear();\n this.hashAggregators.clear();\n this.runtimeOnlyEntries = [];\n this.globalCallCounter = 0;\n }\n\n /**\n * Reset the counter to zero\n */\n resetCounter(): void {\n this.globalCallCounter = 0;\n }\n\n /**\n * Has content\n */\n hasContent(): boolean {\n return (\n this.contentAggregators.size +\n this.jsxAggregators.size +\n this.hashAggregators.size +\n this.runtimeOnlyEntries.length >\n 0\n );\n }\n\n /**\n * Get all translation content entries (flattened across all aggregators)\n */\n getAllTranslationContent(): TranslationContent[] {\n return Array.from(this.contentAggregators.values()).flat();\n }\n\n /**\n * Get all translation JSX entries\n */\n getAllTranslationJsx(): TranslationJsx[] {\n return Array.from(this.jsxAggregators.values());\n }\n\n /**\n * Add a runtime-only translation entry for the runtime translate pass.\n */\n pushRuntimeOnlyContent(content: TranslationContent): void {\n this.runtimeOnlyEntries.push(content);\n }\n\n /**\n * Get all runtime-only translation entries\n */\n getRuntimeOnlyContent(): TranslationContent[] {\n return this.runtimeOnlyEntries;\n }\n\n /**\n * Helper convert to string\n */\n serialize(): SerializedStringCollector {\n const output = {\n contentAggregators: Object.fromEntries(this.contentAggregators),\n jsxAggregators: Object.fromEntries(this.jsxAggregators),\n hashAggregators: Object.fromEntries(this.hashAggregators),\n globalCallCounter: this.globalCallCounter,\n };\n return output;\n }\n\n /**\n * Helper to repopulate\n */\n unserialize(input: SerializedStringCollector): void {\n this.contentAggregators = Object.entries(\n input.contentAggregators as Record<number, TranslationContent[]>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationContent[]>());\n this.jsxAggregators = Object.entries(\n input.jsxAggregators as Record<number, TranslationJsx>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationJsx>());\n this.hashAggregators = Object.entries(\n input.hashAggregators as Record<number, TranslationHash>\n ).reduce((acc, [key, value]) => {\n acc.set(Number(key), value);\n return acc;\n }, new Map<number, TranslationHash>());\n this.globalCallCounter = input.globalCallCounter;\n }\n}\n"],"mappings":";;;;;AAyDA,IAAa,kBAAb,MAA6B;;4CAEqC,IAAI,KAAK;wCACnB,IAAI,KAAK;yCACP,IAAI,KAAK;2BAE7B;4BAEe,EAAE;;;;;;CAMrD,mBAA2B;AACzB,OAAK,qBAAqB;AAC1B,SAAO,KAAK;;;;;CAMd,aAAqB;AACnB,SAAO,KAAK;;;;;;CAOd,uBAAuB,WAAmB,SAAmC;AAC3E,MAAI,cAAc,GAChB,OAAM,IAAI,MACR,0HACD;EAGH,IAAI,aAAa,KAAK,mBAAmB,IAAI,UAAU;AACvD,MAAI,CAAC,YAAY;AACf,gBAAa,CAAC,QAAQ;AACtB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BAAmB,KAAK,QAAQ;;;;;CAMvC,wBAA8C;AAC5C,SAAO,KAAK;;;;;CAMd,YAAuC;AAOrC,SAAO;GALL,oBAAoB,OAAO,YAAY,KAAK,mBAAmB;GAC/D,gBAAgB,OAAO,YAAY,KAAK,eAAe;GACvD,iBAAiB,OAAO,YAAY,KAAK,gBAAgB;GACzD,mBAAmB,KAAK;GAEb;;;;;CAMf,YAAY,OAAwC;AAClD,OAAK,qBAAqB,OAAO,QAC/B,MAAM,mBACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAAmC,CAAC;AAC3C,OAAK,iBAAiB,OAAO,QAC3B,MAAM,eACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAA6B,CAAC;AACrC,OAAK,kBAAkB,OAAO,QAC5B,MAAM,gBACP,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC9B,OAAI,IAAI,OAAO,IAAI,EAAE,MAAM;AAC3B,UAAO;qBACN,IAAI,KAA8B,CAAC;AACtC,OAAK,oBAAoB,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@generaltranslation/compiler",
3
- "version": "1.3.25-odysseus.1",
3
+ "version": "1.3.25-odysseus.4",
4
4
  "description": "Universal plugin for compile-time optimization of GT translation components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,8 +24,8 @@
24
24
  "@babel/traverse": "^7.23.0",
25
25
  "@babel/types": "^7.23.0",
26
26
  "unplugin": "^2.3.10",
27
- "@generaltranslation/format": "0.1.2-odysseus.0",
28
- "generaltranslation": "9.0.0-odysseus.1"
27
+ "@generaltranslation/format": "0.1.2-odysseus.1",
28
+ "generaltranslation": "9.0.0-odysseus.4"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/babel__core": "^7.20.0",