better-translation 0.2.2 → 0.2.3-canary.1

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/dist/ai.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as TranslateFn } from "./types-DxcBf0RB.mjs";
1
+ import { s as TranslateFn } from "./types-Ca8X5uZF.mjs";
2
2
  import { generateText } from "ai";
3
3
 
4
4
  //#region src/ai.d.ts
@@ -10,6 +10,8 @@ interface CreateAiTranslateOptions {
10
10
  prompt?: string;
11
11
  /** Optional temperature forwarded to the selected model provider. */
12
12
  temperature?: number;
13
+ /** Maximum number of per-message translation requests to run at once. */
14
+ concurrency?: number;
13
15
  }
14
16
  declare function createAiTranslate(options?: CreateAiTranslateOptions): TranslateFn;
15
17
  //#endregion
package/dist/ai.d.mts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ai.d.mts","names":[],"sources":["../src/ai.ts"],"mappings":";;;;KAKK,OAAA,GAAU,UAAU,QAAQ,YAAA;AAAA,UAEhB,wBAAA;EAFZ;EAIH,KAAA,GAAQ,OAAO;;EAEf,MAAA;EAN2C;EAQ3C,WAAA;AAAA;AAAA,iBAGc,iBAAA,CAAkB,OAAA,GAAS,wBAAA,GAAgC,WAAW"}
1
+ {"version":3,"file":"ai.d.mts","names":[],"sources":["../src/ai.ts"],"mappings":";;;;KAMK,OAAA,GAAU,UAAU,QAAQ,YAAA;AAAA,UAEhB,wBAAA;EAFZ;EAIH,KAAA,GAAQ,OAAO;;EAEf,MAAA;EAN2C;EAQ3C,WAAA;EANuC;EAQvC,WAAA;AAAA;AAAA,iBAGc,iBAAA,CAAkB,OAAA,GAAS,wBAAA,GAAgC,WAAW"}
package/dist/ai.mjs CHANGED
@@ -1,12 +1,23 @@
1
1
  //#region src/ai.ts
2
2
  const DEFAULT_GATEWAY_MODEL = "openai/gpt-5.5";
3
+ const DEFAULT_CONCURRENCY = 10;
3
4
  function createAiTranslate(options = {}) {
4
5
  return async (messages, locale) => {
5
6
  const result = {};
6
- for (const message of messages) result[message.id] = await translateMessage(message, locale, options);
7
+ const concurrency = normalizeConcurrency(options.concurrency);
8
+ await Promise.all(Array.from({ length: Math.min(concurrency, messages.length) }, async (_, workerIndex) => {
9
+ for (let index = workerIndex; index < messages.length; index += concurrency) {
10
+ const message = messages[index];
11
+ result[message.id] = await translateMessage(message, locale, options);
12
+ }
13
+ }));
7
14
  return result;
8
15
  };
9
16
  }
17
+ function normalizeConcurrency(concurrency = DEFAULT_CONCURRENCY) {
18
+ if (!Number.isFinite(concurrency)) return DEFAULT_CONCURRENCY;
19
+ return Math.max(1, Math.floor(concurrency));
20
+ }
10
21
  async function translateMessage(message, locale, options) {
11
22
  return (await translateWithAi(message, locale, options)).trim() || message.text;
12
23
  }
@@ -29,7 +40,7 @@ ${locale}
29
40
 
30
41
  ## Output Contract
31
42
  Return only the translated text for the provided source message.
32
- Do not include the message id, labels, explanations, markdown, code fences, or surrounding quotes.
43
+ Do not include the lookup id, labels, explanations, markdown, code fences, or surrounding quotes.
33
44
  Use the message context when provided.`].join("\n\n");
34
45
  }
35
46
  function createUserPrompt(message, locale) {
package/dist/ai.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ai.mjs","names":[],"sources":["../src/ai.ts"],"sourcesContent":["import type { generateText } from \"ai\"\n\nimport type { TranslateFn, TranslateMessage } from \"./types.js\"\n\nconst DEFAULT_GATEWAY_MODEL = \"openai/gpt-5.5\"\ntype AiModel = Parameters<typeof generateText>[0][\"model\"]\n\nexport interface CreateAiTranslateOptions {\n /** AI SDK model value. Defaults to a Vercel AI Gateway model string. */\n model?: AiModel\n /** Primary translation brief for product, tone, glossary, or domain instructions. */\n prompt?: string\n /** Optional temperature forwarded to the selected model provider. */\n temperature?: number\n}\n\nexport function createAiTranslate(options: CreateAiTranslateOptions = {}): TranslateFn {\n return async (messages, locale) => {\n const result: Record<string, string> = {}\n\n for (const message of messages) {\n result[message.id] = await translateMessage(message, locale, options)\n }\n\n return result\n }\n}\n\nasync function translateMessage(message: TranslateMessage, locale: string, options: CreateAiTranslateOptions) {\n const translated = (await translateWithAi(message, locale, options)).trim()\n\n return translated || message.text\n}\n\nasync function translateWithAi(message: TranslateMessage, locale: string, options: CreateAiTranslateOptions) {\n const { generateText } = await import(\"ai\")\n const { text } = await generateText({\n model: options.model ?? DEFAULT_GATEWAY_MODEL,\n system: createSystemPrompt(locale, options.prompt),\n prompt: createUserPrompt(message, locale),\n ...(options.temperature === undefined ? {} : { temperature: options.temperature }),\n })\n\n return text\n}\n\nfunction createSystemPrompt(locale: string, prompt?: string) {\n const translationBrief = prompt?.trim() || \"Translate the provided UI messages as concise, natural application UI copy.\"\n\n return [\n `## Translation Brief\n${translationBrief}\n\n## Target Locale\n${locale}\n\n## Output Contract\nReturn only the translated text for the provided source message.\nDo not include the message id, labels, explanations, markdown, code fences, or surrounding quotes.\nUse the message context when provided.`,\n ].join(\"\\n\\n\")\n}\n\nfunction createUserPrompt(message: TranslateMessage, locale: string) {\n return JSON.stringify({\n targetLocale: locale,\n message: {\n id: message.id,\n text: message.text,\n context: message.meta.context,\n },\n })\n}\n"],"mappings":";AAIA,MAAM,wBAAwB;AAY9B,SAAgB,kBAAkB,UAAoC,CAAC,GAAgB;CACrF,OAAO,OAAO,UAAU,WAAW;EACjC,MAAM,SAAiC,CAAC;EAExC,KAAK,MAAM,WAAW,UACpB,OAAO,QAAQ,MAAM,MAAM,iBAAiB,SAAS,QAAQ,OAAO;EAGtE,OAAO;CACT;AACF;AAEA,eAAe,iBAAiB,SAA2B,QAAgB,SAAmC;CAG5G,QAFoB,MAAM,gBAAgB,SAAS,QAAQ,OAAO,GAAG,KAErD,KAAK,QAAQ;AAC/B;AAEA,eAAe,gBAAgB,SAA2B,QAAgB,SAAmC;CAC3G,MAAM,EAAE,iBAAiB,MAAM,OAAO;CACtC,MAAM,EAAE,SAAS,MAAM,aAAa;EAClC,OAAO,QAAQ,SAAS;EACxB,QAAQ,mBAAmB,QAAQ,QAAQ,MAAM;EACjD,QAAQ,iBAAiB,SAAS,MAAM;EACxC,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAClF,CAAC;CAED,OAAO;AACT;AAEA,SAAS,mBAAmB,QAAgB,QAAiB;CAG3D,OAAO,CACL;EAHuB,QAAQ,KAAK,KAAK,8EAI1B;;;EAGjB,OAAO;;;;;uCAMP,EAAE,KAAK,MAAM;AACf;AAEA,SAAS,iBAAiB,SAA2B,QAAgB;CACnE,OAAO,KAAK,UAAU;EACpB,cAAc;EACd,SAAS;GACP,IAAI,QAAQ;GACZ,MAAM,QAAQ;GACd,SAAS,QAAQ,KAAK;EACxB;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"ai.mjs","names":[],"sources":["../src/ai.ts"],"sourcesContent":["import type { generateText } from \"ai\"\n\nimport type { TranslateFn, TranslateMessage } from \"./types.js\"\n\nconst DEFAULT_GATEWAY_MODEL = \"openai/gpt-5.5\"\nconst DEFAULT_CONCURRENCY = 10\ntype AiModel = Parameters<typeof generateText>[0][\"model\"]\n\nexport interface CreateAiTranslateOptions {\n /** AI SDK model value. Defaults to a Vercel AI Gateway model string. */\n model?: AiModel\n /** Primary translation brief for product, tone, glossary, or domain instructions. */\n prompt?: string\n /** Optional temperature forwarded to the selected model provider. */\n temperature?: number\n /** Maximum number of per-message translation requests to run at once. */\n concurrency?: number\n}\n\nexport function createAiTranslate(options: CreateAiTranslateOptions = {}): TranslateFn {\n return async (messages, locale) => {\n const result: Record<string, string> = {}\n const concurrency = normalizeConcurrency(options.concurrency)\n\n await Promise.all(\n Array.from({ length: Math.min(concurrency, messages.length) }, async (_, workerIndex) => {\n for (let index = workerIndex; index < messages.length; index += concurrency) {\n const message = messages[index]!\n result[message.id] = await translateMessage(message, locale, options)\n }\n }),\n )\n\n return result\n }\n}\n\nfunction normalizeConcurrency(concurrency = DEFAULT_CONCURRENCY) {\n if (!Number.isFinite(concurrency)) return DEFAULT_CONCURRENCY\n return Math.max(1, Math.floor(concurrency))\n}\n\nasync function translateMessage(message: TranslateMessage, locale: string, options: CreateAiTranslateOptions) {\n const translated = (await translateWithAi(message, locale, options)).trim()\n\n return translated || message.text\n}\n\nasync function translateWithAi(message: TranslateMessage, locale: string, options: CreateAiTranslateOptions) {\n const { generateText } = await import(\"ai\")\n const { text } = await generateText({\n model: options.model ?? DEFAULT_GATEWAY_MODEL,\n system: createSystemPrompt(locale, options.prompt),\n prompt: createUserPrompt(message, locale),\n ...(options.temperature === undefined ? {} : { temperature: options.temperature }),\n })\n\n return text\n}\n\nfunction createSystemPrompt(locale: string, prompt?: string) {\n const translationBrief = prompt?.trim() || \"Translate the provided UI messages as concise, natural application UI copy.\"\n\n return [\n `## Translation Brief\n${translationBrief}\n\n## Target Locale\n${locale}\n\n## Output Contract\nReturn only the translated text for the provided source message.\nDo not include the lookup id, labels, explanations, markdown, code fences, or surrounding quotes.\nUse the message context when provided.`,\n ].join(\"\\n\\n\")\n}\n\nfunction createUserPrompt(message: TranslateMessage, locale: string) {\n return JSON.stringify({\n targetLocale: locale,\n message: {\n id: message.id,\n text: message.text,\n context: message.meta.context,\n },\n })\n}\n"],"mappings":";AAIA,MAAM,wBAAwB;AAC9B,MAAM,sBAAsB;AAc5B,SAAgB,kBAAkB,UAAoC,CAAC,GAAgB;CACrF,OAAO,OAAO,UAAU,WAAW;EACjC,MAAM,SAAiC,CAAC;EACxC,MAAM,cAAc,qBAAqB,QAAQ,WAAW;EAE5D,MAAM,QAAQ,IACZ,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,aAAa,SAAS,MAAM,EAAE,GAAG,OAAO,GAAG,gBAAgB;GACvF,KAAK,IAAI,QAAQ,aAAa,QAAQ,SAAS,QAAQ,SAAS,aAAa;IAC3E,MAAM,UAAU,SAAS;IACzB,OAAO,QAAQ,MAAM,MAAM,iBAAiB,SAAS,QAAQ,OAAO;GACtE;EACF,CAAC,CACH;EAEA,OAAO;CACT;AACF;AAEA,SAAS,qBAAqB,cAAc,qBAAqB;CAC/D,IAAI,CAAC,OAAO,SAAS,WAAW,GAAG,OAAO;CAC1C,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,WAAW,CAAC;AAC5C;AAEA,eAAe,iBAAiB,SAA2B,QAAgB,SAAmC;CAG5G,QAFoB,MAAM,gBAAgB,SAAS,QAAQ,OAAO,GAAG,KAErD,KAAK,QAAQ;AAC/B;AAEA,eAAe,gBAAgB,SAA2B,QAAgB,SAAmC;CAC3G,MAAM,EAAE,iBAAiB,MAAM,OAAO;CACtC,MAAM,EAAE,SAAS,MAAM,aAAa;EAClC,OAAO,QAAQ,SAAS;EACxB,QAAQ,mBAAmB,QAAQ,QAAQ,MAAM;EACjD,QAAQ,iBAAiB,SAAS,MAAM;EACxC,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;CAClF,CAAC;CAED,OAAO;AACT;AAEA,SAAS,mBAAmB,QAAgB,QAAiB;CAG3D,OAAO,CACL;EAHuB,QAAQ,KAAK,KAAK,8EAI1B;;;EAGjB,OAAO;;;;;uCAMP,EAAE,KAAK,MAAM;AACf;AAEA,SAAS,iBAAiB,SAA2B,QAAgB;CACnE,OAAO,KAAK,UAAU;EACpB,cAAc;EACd,SAAS;GACP,IAAI,QAAQ;GACZ,MAAM,QAAQ;GACd,SAAS,QAAQ,KAAK;EACxB;CACF,CAAC;AACH"}
@@ -12,7 +12,7 @@ function getMessageIdentity(message, meta) {
12
12
  const serializedMeta = serializeMeta(meta);
13
13
  return serializedMeta ? `${message}\0${serializedMeta}` : message;
14
14
  }
15
- /** Generates the stable hashed id used to store and look up a translated message. */
15
+ /** Generates the stable hashed lookup id used to store and look up a translated message. */
16
16
  function getMessageId(message, meta) {
17
17
  const value = getMessageIdentity(message, meta);
18
18
  let hash = 2166136261;
@@ -29,4 +29,4 @@ function getCallMessageId(message, options) {
29
29
  //#endregion
30
30
  export { getMessageId as n, serializeMeta as r, getCallMessageId as t };
31
31
 
32
- //# sourceMappingURL=message-id-B8zJjADZ.mjs.map
32
+ //# sourceMappingURL=message-id-DGUI8H5w.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-id-DGUI8H5w.mjs","names":[],"sources":["../src/message-id.ts"],"sourcesContent":["import type { TranslateOptions } from \"./types.js\"\n\nexport function normalizeMeta(meta?: TranslateOptions): TranslateOptions {\n if (!meta) return {}\n\n return Object.fromEntries(\n Object.entries(meta)\n .filter(([key, value]) => key !== \"id\" && value !== undefined)\n .sort(([a], [b]) => a.localeCompare(b)),\n ) as TranslateOptions\n}\n\nexport function serializeMeta(meta?: TranslateOptions) {\n if (!meta) return \"\"\n\n const normalized = normalizeMeta(meta)\n return Object.keys(normalized).length > 0 ? JSON.stringify(normalized) : \"\"\n}\n\nexport function getMessageIdentity(message: string, meta?: TranslateOptions) {\n const serializedMeta = serializeMeta(meta)\n return serializedMeta ? `${message}\\0${serializedMeta}` : message\n}\n\n/** Generates the stable hashed lookup id used to store and look up a translated message. */\nexport function getMessageId(message: string, meta?: TranslateOptions) {\n const value = getMessageIdentity(message, meta)\n let hash = 2166136261\n\n for (let i = 0; i < value.length; i++) {\n hash ^= value.charCodeAt(i)\n hash = Math.imul(hash, 16777619)\n }\n\n return `m_${(hash >>> 0).toString(36)}`\n}\n\n/** Resolves the lookup id for function-style `t()` calls, preferring an explicit `options.id`. */\nexport function getCallMessageId(message: string, options?: TranslateOptions) {\n return options?.id ?? getMessageId(message, options)\n}\n"],"mappings":";AAEA,SAAgB,cAAc,MAA2C;CACvE,IAAI,CAAC,MAAM,OAAO,CAAC;CAEnB,OAAO,OAAO,YACZ,OAAO,QAAQ,IAAI,EAChB,QAAQ,CAAC,KAAK,WAAW,QAAQ,QAAQ,UAAU,KAAA,CAAS,EAC5D,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAC1C;AACF;AAEA,SAAgB,cAAc,MAAyB;CACrD,IAAI,CAAC,MAAM,OAAO;CAElB,MAAM,aAAa,cAAc,IAAI;CACrC,OAAO,OAAO,KAAK,UAAU,EAAE,SAAS,IAAI,KAAK,UAAU,UAAU,IAAI;AAC3E;AAEA,SAAgB,mBAAmB,SAAiB,MAAyB;CAC3E,MAAM,iBAAiB,cAAc,IAAI;CACzC,OAAO,iBAAiB,GAAG,QAAQ,IAAI,mBAAmB;AAC5D;;AAGA,SAAgB,aAAa,SAAiB,MAAyB;CACrE,MAAM,QAAQ,mBAAmB,SAAS,IAAI;CAC9C,IAAI,OAAO;CAEX,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,QAAQ,MAAM,WAAW,CAAC;EAC1B,OAAO,KAAK,KAAK,MAAM,QAAQ;CACjC;CAEA,OAAO,MAAM,SAAS,GAAG,SAAS,EAAE;AACtC;;AAGA,SAAgB,iBAAiB,SAAiB,SAA4B;CAC5E,OAAO,SAAS,MAAM,aAAa,SAAS,OAAO;AACrD"}
@@ -1,4 +1,4 @@
1
- import { u as RuntimeMessages } from "./types-DxcBf0RB.mjs";
1
+ import { o as RuntimeMessages } from "./types-Ca8X5uZF.mjs";
2
2
 
3
3
  //#region src/messages.d.ts
4
4
  declare const locales: readonly string[];
package/dist/react.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import { p as TranslateOptions } from "./types-DxcBf0RB.mjs";
1
+ import { l as TranslateOptions } from "./types-Ca8X5uZF.mjs";
2
2
  import { ReactNode } from "react";
3
3
 
4
4
  //#region src/react.d.ts
5
5
  /** Props for `TranslateProvider`. */
6
6
  interface TranslateProviderProps {
7
- /** Flattened locale message map keyed by stable message id. */
7
+ /** Flattened locale message map keyed by stable lookup id. */
8
8
  messages: Record<string, string>;
9
9
  /** React subtree that should have access to translations. */
10
10
  children: ReactNode;
@@ -28,7 +28,7 @@ type VarProps = {
28
28
  declare function Var(props: VarProps): import("react/jsx-runtime").JSX.Element;
29
29
  /** Props for `T`. */
30
30
  interface TProps {
31
- /** Explicit stable id to use instead of hashing the rendered source text, whether provided manually or by a transform. */
31
+ /** Explicit stable lookup id to use instead of hashing the rendered source text, whether provided manually or by a transform. */
32
32
  id?: string;
33
33
  /** Extra disambiguating context for translators and custom grouping. */
34
34
  context?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.mts","names":[],"sources":["../src/react.tsx"],"mappings":";;;;;UAaiB,sBAAA;EAAA;EAEf,QAAA,EAAU,MAAA;;EAEV,QAAA,EAAU,SAAS;AAAA;;iBAIL,iBAAA,CAAA;EAAoB,QAAA;EAAU;AAAA,GAAY,sBAAA,+BAAsB,GAAA,CAAA,OAAA;;iBAMhE,WAAA,CAAA,GAAW,MAAA;AAAA,KAItB,aAAA,GAAgB,MAAM;AAAA,KACtB,WAAA,IAAe,OAAA,UAAiB,eAAA,GAAkB,aAAA,GAAgB,gBAAA,EAAkB,OAAA,GAAU,gBAAA;;iBAGnF,IAAA,CAAA,GAAQ,WAAW;;KAevB,QAAA;EA7B8C,sFA+BxD,QAAA,GAAW,SAAA;AAAA,IACT,MAAA,SAAe,SAAA;;iBAGH,GAAA,CAAI,KAAA,EAAO,QAAQ,+BAAA,GAAA,CAAA,OAAA;;UAKlB,MAAA;EAxCyC;EA0CxD,EAAA;EA1C8E;EA4C9E,OAAA;EA5C8E;EA8C9E,QAAA,GAAW,SAAS;AAAA;;iBAIN,CAAA,CAAA;EAAI,EAAA;EAAI,OAAA;EAAS;AAAA,GAAY,MAAA,+BAAM,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"react.d.mts","names":[],"sources":["../src/react.tsx"],"mappings":";;;;;UAaiB,sBAAA;EAAA;EAEf,QAAA,EAAU,MAAA;;EAEV,QAAA,EAAU,SAAS;AAAA;;iBAIL,iBAAA;EAAoB,QAAA;EAAU;AAAA,GAAY,sBAAA,+BAAsB,GAAA,CAAA,OAAA;;iBAMhE,WAAA,IAAW,MAAA;AAAA,KAItB,aAAA,GAAgB,MAAM;AAAA,KACtB,WAAA,IAAe,OAAA,UAAiB,eAAA,GAAkB,aAAA,GAAgB,gBAAA,EAAkB,OAAA,GAAU,gBAAA;;iBAGnF,IAAA,IAAQ,WAAW;;KAevB,QAAA;EA7B8C,sFA+BxD,QAAA,GAAW,SAAA;AAAA,IACT,MAAA,SAAe,SAAA;;iBAGH,GAAA,CAAI,KAAA,EAAO,QAAQ,+BAAA,GAAA,CAAA,OAAA;;UAKlB,MAAA;EAxCyC;EA0CxD,EAAA;EA1C8E;EA4C9E,OAAA;EA5C8E;EA8C9E,QAAA,GAAW,SAAS;AAAA;;iBAIN,CAAA;EAAI,EAAA;EAAI,OAAA;EAAS;AAAA,GAAY,MAAA,+BAAM,GAAA,CAAA,OAAA"}
package/dist/react.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as getMessageId, t as getCallMessageId } from "./message-id-B8zJjADZ.mjs";
1
+ import { n as getMessageId, t as getCallMessageId } from "./message-id-DGUI8H5w.mjs";
2
2
  import { Children, createContext, isValidElement, use, useMemo } from "react";
3
3
  import { Fragment, jsx } from "react/jsx-runtime";
4
4
  //#region src/react.tsx
@@ -1 +1 @@
1
- {"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import { Children, createContext, isValidElement, use, useMemo, type ReactNode } from \"react\"\n\nimport type { TranslateOptions } from \"./types.js\"\n\nimport { getCallMessageId, getMessageId } from \"./message-id.js\"\n\ninterface TranslateContextValue {\n messages: Record<string, string>\n}\n\nconst TranslateContext = createContext<TranslateContextValue>({ messages: {} })\n\n/** Props for `TranslateProvider`. */\nexport interface TranslateProviderProps {\n /** Flattened locale message map keyed by stable message id. */\n messages: Record<string, string>\n /** React subtree that should have access to translations. */\n children: ReactNode\n}\n\n/** Provides translated messages to React components below it. */\nexport function TranslateProvider({ messages, children }: TranslateProviderProps) {\n const value = useMemo(() => ({ messages }), [messages])\n return <TranslateContext.Provider value={value}>{children}</TranslateContext.Provider>\n}\n\n/** Returns the raw locale message map from the current provider. */\nexport function useMessages() {\n return use(TranslateContext).messages\n}\n\ntype MessageValues = Record<string, unknown>\ntype TranslateFn = (message: string, valuesOrOptions?: MessageValues | TranslateOptions, options?: TranslateOptions) => string\n\n/** Returns a translator function for text used in props, labels, and other non-JSX positions. */\nexport function useT(): TranslateFn {\n const { messages } = use(TranslateContext)\n return useMemo<TranslateFn>(\n () => (message, valuesOrOptions, options) => {\n const values = isTranslateOptions(valuesOrOptions) ? undefined : normalizeValues(valuesOrOptions)\n const resolvedOptions = isTranslateOptions(valuesOrOptions) ? valuesOrOptions : options\n const template = messages[getCallMessageId(message, resolvedOptions)] ?? message\n if (!values) return template\n return template.replace(/\\{(\\w+)\\}/g, (_, name: string) => values[name] ?? `{${name}}`)\n },\n [messages],\n )\n}\n\n/** Props for `Var`. */\nexport type VarProps = {\n /** Optional shorthand child form, normalized at build time for simple identifiers. */\n children?: ReactNode\n} & Record<string, ReactNode | undefined>\n\n/** Marks a runtime value for placeholder interpolation inside `<T>` content. */\nexport function Var(props: VarProps) {\n return <>{getRuntimeVarEntry(props)?.value ?? props.children}</>\n}\n\n/** Props for `T`. */\nexport interface TProps {\n /** Explicit stable id to use instead of hashing the rendered source text, whether provided manually or by a transform. */\n id?: string\n /** Extra disambiguating context for translators and custom grouping. */\n context?: string\n /** Source-language JSX content to translate. */\n children?: ReactNode\n}\n\n/** Renders translated JSX content and supports placeholders through `<Var>`. */\nexport function T({ id, context, children }: TProps) {\n const { messages } = use(TranslateContext)\n const resolvedMeta = context ? { context } : undefined\n const runtimeContent = useMemo(() => extractRuntimeContent(children), [children])\n const template = messages[id ?? (runtimeContent.message ? getMessageId(runtimeContent.message, resolvedMeta) : \"\")]\n const vars = template?.includes(\"{\") ? runtimeContent.vars : undefined\n const interpolated = useMemo(() => interpolate(template, vars), [template, vars])\n\n if (!template) return <>{children}</>\n if (!vars) return <>{template}</>\n if (!interpolated.length) return <>{children}</>\n return <>{interpolated}</>\n}\n\nfunction interpolate(template?: string, vars?: Record<string, ReactNode>): ReactNode[] {\n if (!template || !vars) return []\n const result: ReactNode[] = []\n const re = /\\{(\\w+)\\}/g\n let lastIndex = 0\n let match: RegExpExecArray | null\n\n while ((match = re.exec(template)) !== null) {\n if (match.index > lastIndex) result.push(template.slice(lastIndex, match.index))\n result.push(vars[match[1]!] ?? `{${match[1]}}`)\n lastIndex = re.lastIndex\n }\n\n if (lastIndex < template.length) result.push(template.slice(lastIndex))\n return result\n}\n\nfunction extractRuntimeContent(children: ReactNode) {\n const parts: string[] = []\n const vars: Record<string, ReactNode> = {}\n\n Children.forEach(children, (child) => {\n if (typeof child === \"string\" || typeof child === \"number\") {\n parts.push(String(child))\n return\n }\n\n if (isValidElement<VarProps>(child) && child.type === Var) {\n const entry = getRuntimeVarEntry(child.props)\n if (entry) {\n parts.push(`{${entry.name}}`)\n vars[entry.name] = entry.value\n }\n }\n })\n\n return {\n message: parts.join(\"\").replace(/\\s+/g, \" \").trim(),\n vars: Object.keys(vars).length > 0 ? vars : undefined,\n }\n}\n\nfunction getRuntimeVarEntry(props: VarProps) {\n if (typeof props.name === \"string\" && props.children !== undefined) {\n return { name: props.name, value: props.children }\n }\n\n const entries = Object.entries(props).filter(([key]) => key !== \"children\")\n if (entries.length !== 1) return undefined\n\n const [name, value] = entries[0]!\n return { name, value }\n}\n\nfunction isTranslateOptions(value?: MessageValues | TranslateOptions): value is TranslateOptions {\n if (!value || Array.isArray(value)) return false\n return Object.keys(value).every((key) => key === \"id\" || key === \"context\")\n}\n\nfunction normalizeValues(values?: MessageValues) {\n if (!values) return undefined\n const entries = Object.entries(values).map(([name, value]) => [name, String(value)] as const)\n return entries.length > 0 ? Object.fromEntries(entries) : undefined\n}\n"],"mappings":";;;;AAUA,MAAM,mBAAmB,cAAqC,EAAE,UAAU,CAAC,EAAE,CAAC;;AAW9E,SAAgB,kBAAkB,EAAE,UAAU,YAAoC;CAChF,MAAM,QAAQ,eAAe,EAAE,SAAS,IAAI,CAAC,QAAQ,CAAC;CACtD,OAAO,oBAAC,iBAAiB,U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E,QAAQ,CAAC,SAAS,QAAQ,UAAU;CAC1E,IAAI,QAAQ,WAAW,GAAG,OAAO,KAAA;CAEjC,MAAM,CAAC,MAAM,SAAS,QAAQ;CAC9B,OAAO;EAAE;EAAM;CAAM;AACvB;AAEA,SAAS,mBAAmB,OAAqE;CAC/F,IAAI,CAAC,SAAS,MAAM,QAAQ,KAAK,GAAG,OAAO;CAC3C,OAAO,OAAO,KAAK,KAAK,EAAE,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,SAAS;AAC5E;AAEA,SAAS,gBAAgB,QAAwB;CAC/C,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,MAAM,UAAU,OAAO,QAAQ,MAAM,EAAE,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,OAAO,KAAK,CAAC,CAAU;CAC5F,OAAO,QAAQ,SAAS,IAAI,OAAO,YAAY,OAAO,IAAI,KAAA;AAC5D"}
1
+ {"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import { Children, createContext, isValidElement, use, useMemo, type ReactNode } from \"react\"\n\nimport type { TranslateOptions } from \"./types.js\"\n\nimport { getCallMessageId, getMessageId } from \"./message-id.js\"\n\ninterface TranslateContextValue {\n messages: Record<string, string>\n}\n\nconst TranslateContext = createContext<TranslateContextValue>({ messages: {} })\n\n/** Props for `TranslateProvider`. */\nexport interface TranslateProviderProps {\n /** Flattened locale message map keyed by stable lookup id. */\n messages: Record<string, string>\n /** React subtree that should have access to translations. */\n children: ReactNode\n}\n\n/** Provides translated messages to React components below it. */\nexport function TranslateProvider({ messages, children }: TranslateProviderProps) {\n const value = useMemo(() => ({ messages }), [messages])\n return <TranslateContext.Provider value={value}>{children}</TranslateContext.Provider>\n}\n\n/** Returns the raw locale message map from the current provider. */\nexport function useMessages() {\n return use(TranslateContext).messages\n}\n\ntype MessageValues = Record<string, unknown>\ntype TranslateFn = (message: string, valuesOrOptions?: MessageValues | TranslateOptions, options?: TranslateOptions) => string\n\n/** Returns a translator function for text used in props, labels, and other non-JSX positions. */\nexport function useT(): TranslateFn {\n const { messages } = use(TranslateContext)\n return useMemo<TranslateFn>(\n () => (message, valuesOrOptions, options) => {\n const values = isTranslateOptions(valuesOrOptions) ? undefined : normalizeValues(valuesOrOptions)\n const resolvedOptions = isTranslateOptions(valuesOrOptions) ? valuesOrOptions : options\n const template = messages[getCallMessageId(message, resolvedOptions)] ?? message\n if (!values) return template\n return template.replace(/\\{(\\w+)\\}/g, (_, name: string) => values[name] ?? `{${name}}`)\n },\n [messages],\n )\n}\n\n/** Props for `Var`. */\nexport type VarProps = {\n /** Optional shorthand child form, normalized at build time for simple identifiers. */\n children?: ReactNode\n} & Record<string, ReactNode | undefined>\n\n/** Marks a runtime value for placeholder interpolation inside `<T>` content. */\nexport function Var(props: VarProps) {\n return <>{getRuntimeVarEntry(props)?.value ?? props.children}</>\n}\n\n/** Props for `T`. */\nexport interface TProps {\n /** Explicit stable lookup id to use instead of hashing the rendered source text, whether provided manually or by a transform. */\n id?: string\n /** Extra disambiguating context for translators and custom grouping. */\n context?: string\n /** Source-language JSX content to translate. */\n children?: ReactNode\n}\n\n/** Renders translated JSX content and supports placeholders through `<Var>`. */\nexport function T({ id, context, children }: TProps) {\n const { messages } = use(TranslateContext)\n const resolvedMeta = context ? { context } : undefined\n const runtimeContent = useMemo(() => extractRuntimeContent(children), [children])\n const template = messages[id ?? (runtimeContent.message ? getMessageId(runtimeContent.message, resolvedMeta) : \"\")]\n const vars = template?.includes(\"{\") ? runtimeContent.vars : undefined\n const interpolated = useMemo(() => interpolate(template, vars), [template, vars])\n\n if (!template) return <>{children}</>\n if (!vars) return <>{template}</>\n if (!interpolated.length) return <>{children}</>\n return <>{interpolated}</>\n}\n\nfunction interpolate(template?: string, vars?: Record<string, ReactNode>): ReactNode[] {\n if (!template || !vars) return []\n const result: ReactNode[] = []\n const re = /\\{(\\w+)\\}/g\n let lastIndex = 0\n let match: RegExpExecArray | null\n\n while ((match = re.exec(template)) !== null) {\n if (match.index > lastIndex) result.push(template.slice(lastIndex, match.index))\n result.push(vars[match[1]!] ?? `{${match[1]}}`)\n lastIndex = re.lastIndex\n }\n\n if (lastIndex < template.length) result.push(template.slice(lastIndex))\n return result\n}\n\nfunction extractRuntimeContent(children: ReactNode) {\n const parts: string[] = []\n const vars: Record<string, ReactNode> = {}\n\n Children.forEach(children, (child) => {\n if (typeof child === \"string\" || typeof child === \"number\") {\n parts.push(String(child))\n return\n }\n\n if (isValidElement<VarProps>(child) && child.type === Var) {\n const entry = getRuntimeVarEntry(child.props)\n if (entry) {\n parts.push(`{${entry.name}}`)\n vars[entry.name] = entry.value\n }\n }\n })\n\n return {\n message: parts.join(\"\").replace(/\\s+/g, \" \").trim(),\n vars: Object.keys(vars).length > 0 ? vars : undefined,\n }\n}\n\nfunction getRuntimeVarEntry(props: VarProps) {\n if (typeof props.name === \"string\" && props.children !== undefined) {\n return { name: props.name, value: props.children }\n }\n\n const entries = Object.entries(props).filter(([key]) => key !== \"children\")\n if (entries.length !== 1) return undefined\n\n const [name, value] = entries[0]!\n return { name, value }\n}\n\nfunction isTranslateOptions(value?: MessageValues | TranslateOptions): value is TranslateOptions {\n if (!value || Array.isArray(value)) return false\n return Object.keys(value).every((key) => key === \"id\" || key === \"context\")\n}\n\nfunction normalizeValues(values?: MessageValues) {\n if (!values) return undefined\n const entries = Object.entries(values).map(([name, value]) => [name, String(value)] as const)\n return entries.length > 0 ? Object.fromEntries(entries) : undefined\n}\n"],"mappings":";;;;AAUA,MAAM,mBAAmB,cAAqC,EAAE,UAAU,CAAC,EAAE,CAAC;;AAW9E,SAAgB,kBAAkB,EAAE,UAAU,YAAoC;CAChF,MAAM,QAAQ,eAAe,EAAE,SAAS,IAAI,CAAC,QAAQ,CAAC;CACtD,OAAO,oBAAC,iBAAiB,UAAlB;EAAkC;EAAQ;CAAoC,CAAA;AACvF;;AAGA,SAAgB,cAAc;CAC5B,OAAO,IAAI,gBAAgB,EAAE;AAC/B;;AAMA,SAAgB,OAA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AC9B,OAAO;EAAE;EAAM;CAAM;AACvB;AAEA,SAAS,mBAAmB,OAAqE;CAC/F,IAAI,CAAC,SAAS,MAAM,QAAQ,KAAK,GAAG,OAAO;CAC3C,OAAO,OAAO,KAAK,KAAK,EAAE,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,SAAS;AAC5E;AAEA,SAAS,gBAAgB,QAAwB;CAC/C,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,MAAM,UAAU,OAAO,QAAQ,MAAM,EAAE,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,OAAO,KAAK,CAAC,CAAU;CAC5F,OAAO,QAAQ,SAAS,IAAI,OAAO,YAAY,OAAO,IAAI,KAAA;AAC5D"}
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { p as TranslateOptions } from "./types-DxcBf0RB.mjs";
1
+ import { l as TranslateOptions } from "./types-Ca8X5uZF.mjs";
2
2
 
3
3
  //#region src/server.d.ts
4
4
  type MessageValues = Record<string, unknown>;
package/dist/server.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as getCallMessageId } from "./message-id-B8zJjADZ.mjs";
1
+ import { t as getCallMessageId } from "./message-id-DGUI8H5w.mjs";
2
2
  //#region src/server.ts
3
3
  /** Creates a lightweight server-side translator from a loaded message map. */
4
4
  function createTranslator(messages) {
@@ -31,22 +31,22 @@ interface ManifestEntry {
31
31
  /** Source locations that contributed to this manifest entry. */
32
32
  sources: MessageSource[];
33
33
  }
34
- /** In-memory manifest keyed by stable message id. */
34
+ /** In-memory manifest keyed by stable lookup id. */
35
35
  type MessageManifest = Record<string, ManifestEntry>;
36
- /** Private on-disk manifest keyed by stable message id. */
36
+ /** Private on-disk manifest keyed by stable lookup id. */
37
37
  type MessageManifestFile = MessageManifest;
38
- /** Flat runtime message map keyed by stable message id. */
38
+ /** Flat runtime message map keyed by stable lookup id. */
39
39
  type RuntimeMessages = Record<string, string>;
40
40
  /** Extra metadata that can influence translation and message grouping. */
41
41
  interface TranslateOptions {
42
- /** Explicit stable message id for direct runtime lookups, whether provided manually or by a transform. */
42
+ /** Explicit stable lookup id for direct runtime lookups, whether provided manually or by a transform. */
43
43
  id?: string;
44
44
  /** Extra disambiguating context for translators and custom ids. */
45
45
  context?: string;
46
46
  }
47
47
  /** A full message payload passed to the translate callback. */
48
48
  interface TranslateMessage {
49
- /** Stable message id used for locale file keys and translation results. */
49
+ /** Stable lookup id used for locale file keys and translation results. */
50
50
  id: string;
51
51
  /** Source-language text that should be translated. */
52
52
  text: string;
@@ -59,22 +59,6 @@ interface TranslateMessage {
59
59
  }
60
60
  /** User-provided translation function used to fill missing locale entries. */
61
61
  type TranslateFn = (messages: TranslateMessage[], locale: string) => Promise<Record<string, string>>;
62
- /** Stores messages in a remote backend. Deprecated: use `runtime.type = "remote"` instead. */
63
- interface BetterTranslateRemoteStorageOptions {
64
- /** Selects remote storage. */
65
- type: "remote";
66
- /** Optional remote backend URL. */
67
- url?: string;
68
- }
69
- /** Writes locale JSON files into the app repository or deployed artifact. Deprecated: use `runtime.type = "local"` instead. */
70
- interface BetterTranslateLocalStorageOptions {
71
- /** Selects local file storage. */
72
- type: "local";
73
- /** Output directory where locale JSON files are written. */
74
- output?: string;
75
- }
76
- /** Controls where translated locale artifacts are written or synced. */
77
- type BetterTranslateStorageOptions = BetterTranslateRemoteStorageOptions | BetterTranslateLocalStorageOptions;
78
62
  /** Writes locale files into the app and loads them through Vite. */
79
63
  interface BetterTranslateLocalRuntimeOptions {
80
64
  /** Selects local runtime artifacts. */
@@ -85,6 +69,8 @@ interface BetterTranslateLocalRuntimeOptions {
85
69
  output?: string;
86
70
  /** Public URL prefix used by the generated loader for `target: "public"`. */
87
71
  basePath?: string;
72
+ /** Custom translation function used for messages missing from non-default locales. */
73
+ translate?: TranslateFn;
88
74
  }
89
75
  /** Loads locale files from an external translation service. */
90
76
  interface BetterTranslateRemoteRuntimeOptions {
@@ -93,19 +79,18 @@ interface BetterTranslateRemoteRuntimeOptions {
93
79
  /** Remote translation service URL. */
94
80
  endpoint?: string;
95
81
  /** Remote project identifier. */
96
- projectId?: string;
82
+ projectId: string;
83
+ /** Project API key used by the Vite plugin to sync Manifests. Falls back to `BETTER_TRANSLATION_API_KEY`. */
84
+ apiKey?: string;
85
+ /** Branch to read from, or `"auto"` to infer it from the environment. */
86
+ branch?: "auto" | (string & {});
87
+ /** Local development behavior for remote runtime mode. */
88
+ dev?: {
89
+ /** Avoid platform reads and writes during local development. */offline?: boolean;
90
+ };
97
91
  }
98
92
  /** Controls where locale artifacts live and how the virtual runtime loader reads them. */
99
93
  type BetterTranslateRuntimeOptions = BetterTranslateLocalRuntimeOptions | BetterTranslateRemoteRuntimeOptions;
100
- /** Runtime metadata emitted by the plugin for server-side loaders. */
101
- interface BetterTranslateRuntimeConfig {
102
- /** Runtime backend configured for locale artifacts. */
103
- runtime: BetterTranslateRuntimeOptions;
104
- /** Locale code treated as the source language. */
105
- defaultLocale: string;
106
- /** All locale codes emitted by the plugin. */
107
- locales: string[];
108
- }
109
94
  /** Public configuration for the Better Translation Vite plugin. */
110
95
  interface BetterTranslatePluginOptions {
111
96
  /** All locale codes that should be emitted. */
@@ -120,11 +105,7 @@ interface BetterTranslatePluginOptions {
120
105
  logging?: boolean;
121
106
  /** Runtime backend configuration. */
122
107
  runtime?: BetterTranslateRuntimeOptions;
123
- /** Storage backend configuration. Deprecated: use `runtime` instead. */
124
- storage?: BetterTranslateStorageOptions;
125
- /** Custom translation function used for messages missing from non-default locales. */
126
- translate?: TranslateFn;
127
108
  }
128
109
  //#endregion
129
- export { BetterTranslateRemoteStorageOptions as a, BetterTranslateStorageOptions as c, TranslateFn as d, TranslateMessage as f, BetterTranslateRemoteRuntimeOptions as i, MessageManifestFile as l, BetterTranslateLocalStorageOptions as n, BetterTranslateRuntimeConfig as o, TranslateOptions as p, BetterTranslatePluginOptions as r, BetterTranslateRuntimeOptions as s, BetterTranslateLocalRuntimeOptions as t, RuntimeMessages as u };
130
- //# sourceMappingURL=types-DxcBf0RB.d.mts.map
110
+ export { MessageManifestFile as a, TranslateMessage as c, BetterTranslateRuntimeOptions as i, TranslateOptions as l, BetterTranslatePluginOptions as n, RuntimeMessages as o, BetterTranslateRemoteRuntimeOptions as r, TranslateFn as s, BetterTranslateLocalRuntimeOptions as t };
111
+ //# sourceMappingURL=types-Ca8X5uZF.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-Ca8X5uZF.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;UAeiB,aAAA;EAkBZ;EAhBH,IAAA;EAoB4B;EAlB5B,IAAA;EA0BsB;EAxBtB,MAAA;EAoBA;EAlBA,IAAA;EAoBA;EAlBA,MAAA;EAoBS;EAlBT,OAAA;EAkBsB;EAhBtB,SAAA;EAoByB;EAlBzB,KAAA;EAkB4B;EAhB5B,GAAA;AAAA;;UAIe,aAAA;EAegC;EAb/C,cAAA;EAgBU;EAdV,IAAA,EAAM,gBAAA;;EAEN,YAAA;EAYkC;EAVlC,OAAA,EAAS,aAAa;AAAA;;KAIZ,eAAA,GAAkB,MAAM,SAAS,aAAA;AA2DpC;AAAA,KAxDG,mBAAA,GAAsB,eAAe;;KAGrC,eAAA,GAAkB,MAAM;;UAiDnB,gBAAA;EA2Cf;EAzCA,EAAA;EA6CA;EA3CA,OAAO;AAAA;;UAIQ,gBAAA;EA6CN;EA3CT,EAAA;EAgDuC;EA9CvC,IAAA;EA8C0C;EA5C1C,IAAA,EAAM,gBAAA;EA+CS;EA7Cf,YAAA;;EAEA,OAAA,EAAS,aAAa;AAAA;;KAIZ,WAAA,IAAe,QAAA,EAAU,gBAAA,IAAoB,MAAA,aAAmB,OAAA,CAAQ,MAAA;;UAGnE,kCAAA;EAgDf;EA9CA,IAAA;EA8CuC;EA5CvC,MAAA;;EAEA,MAAA;;EAEA,QAAA;;EAEA,SAAA,GAAY,WAAW;AAAA;;UAIR,mCAAA;;EAEf,IAAA;;EAEA,QAAA;;EAEA,SAAA;;EAEA,MAAA;;EAEA,MAAA;;EAEA,GAAA;oEAEE,OAAA;EAAA;AAAA;;KAKQ,6BAAA,GAAgC,kCAAA,GAAqC,mCAAmC;;UAGnG,4BAAA;;EAEf,OAAA;;EAEA,aAAA;;EAEA,OAAA;;EAEA,SAAA;;EAEA,OAAA;;EAEA,OAAA,GAAU,6BAA6B;AAAA"}
package/dist/vite.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as BetterTranslateRemoteStorageOptions, c as BetterTranslateStorageOptions, d as TranslateFn, f as TranslateMessage, i as BetterTranslateRemoteRuntimeOptions, l as MessageManifestFile, n as BetterTranslateLocalStorageOptions, o as BetterTranslateRuntimeConfig, p as TranslateOptions, r as BetterTranslatePluginOptions, s as BetterTranslateRuntimeOptions, t as BetterTranslateLocalRuntimeOptions, u as RuntimeMessages } from "./types-DxcBf0RB.mjs";
1
+ import { a as MessageManifestFile, c as TranslateMessage, i as BetterTranslateRuntimeOptions, l as TranslateOptions, n as BetterTranslatePluginOptions, o as RuntimeMessages, r as BetterTranslateRemoteRuntimeOptions, s as TranslateFn, t as BetterTranslateLocalRuntimeOptions } from "./types-Ca8X5uZF.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/plugin.d.ts
5
5
  /** Scans source files for translatable messages and keeps locale JSON files in sync. */
6
6
  declare function betterTranslation(options: BetterTranslatePluginOptions): Plugin;
7
7
  //#endregion
8
- export { type BetterTranslateLocalRuntimeOptions, type BetterTranslateLocalStorageOptions, type BetterTranslatePluginOptions, type BetterTranslateRemoteRuntimeOptions, type BetterTranslateRemoteStorageOptions, type BetterTranslateRuntimeConfig, type BetterTranslateRuntimeOptions, type BetterTranslateStorageOptions, type MessageManifestFile, type RuntimeMessages, type TranslateFn, type TranslateMessage, type TranslateOptions, betterTranslation };
8
+ export { type BetterTranslateLocalRuntimeOptions, type BetterTranslatePluginOptions, type BetterTranslateRemoteRuntimeOptions, type BetterTranslateRuntimeOptions, type MessageManifestFile, type RuntimeMessages, type TranslateFn, type TranslateMessage, type TranslateOptions, betterTranslation };
9
9
  //# sourceMappingURL=vite.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;iBA8DgB,iBAAA,CAAkB,OAAA,EAAS,4BAAA,GAA+B,MAAM"}
1
+ {"version":3,"file":"vite.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;iBA4DgB,iBAAA,CAAkB,OAAA,EAAS,4BAAA,GAA+B,MAAM"}