@weglot/translate-react 0.1.0 → 0.2.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.
Files changed (50) hide show
  1. package/README.md +71 -18
  2. package/build/plugin/build-translator.cjs +6 -2
  3. package/build/plugin/build-translator.mjs +6 -2
  4. package/build/plugin/build-translator.mjs.map +1 -1
  5. package/build/plugin/next.cjs +1 -0
  6. package/build/plugin/next.d.cts.map +1 -1
  7. package/build/plugin/next.d.mts.map +1 -1
  8. package/build/plugin/next.mjs +1 -0
  9. package/build/plugin/next.mjs.map +1 -1
  10. package/build/plugin/vite.cjs +1 -1
  11. package/build/plugin/vite.mjs +1 -1
  12. package/build/plugin/vite.mjs.map +1 -1
  13. package/build/plugin/webpack.cjs +1 -1
  14. package/build/plugin/webpack.mjs +1 -1
  15. package/build/plugin/webpack.mjs.map +1 -1
  16. package/build/runtime/translate-dynamic.cjs +6 -4
  17. package/build/runtime/translate-dynamic.d.cts.map +1 -1
  18. package/build/runtime/translate-dynamic.d.mts.map +1 -1
  19. package/build/runtime/translate-dynamic.mjs +7 -5
  20. package/build/runtime/translate-dynamic.mjs.map +1 -1
  21. package/build/translators/translation-service.cjs +7 -4
  22. package/build/translators/translation-service.mjs +7 -4
  23. package/build/translators/translation-service.mjs.map +1 -1
  24. package/build/translators/weglot/api-client.cjs +103 -23
  25. package/build/translators/weglot/api-client.mjs +103 -24
  26. package/build/translators/weglot/api-client.mjs.map +1 -1
  27. package/build/translators/weglot/engine.cjs +2 -5
  28. package/build/translators/weglot/engine.mjs +2 -5
  29. package/build/translators/weglot/engine.mjs.map +1 -1
  30. package/build/translators/weglot/translator.cjs +48 -24
  31. package/build/translators/weglot/translator.mjs +48 -24
  32. package/build/translators/weglot/translator.mjs.map +1 -1
  33. package/build/types.d.cts +13 -3
  34. package/build/types.d.cts.map +1 -1
  35. package/build/types.d.mts +13 -3
  36. package/build/types.d.mts.map +1 -1
  37. package/build/utils/config-factory.cjs +18 -4
  38. package/build/utils/config-factory.mjs +19 -5
  39. package/build/utils/config-factory.mjs.map +1 -1
  40. package/build/virtual/code-generator.cjs +2 -0
  41. package/build/virtual/code-generator.mjs +2 -0
  42. package/build/virtual/code-generator.mjs.map +1 -1
  43. package/build/virtual/config.cjs +3 -0
  44. package/build/virtual/config.d.cts +3 -1
  45. package/build/virtual/config.d.cts.map +1 -1
  46. package/build/virtual/config.d.mts +3 -1
  47. package/build/virtual/config.d.mts.map +1 -1
  48. package/build/virtual/config.mjs +3 -1
  49. package/build/virtual/config.mjs.map +1 -1
  50. package/package.json +1 -1
@@ -1,26 +1,33 @@
1
- const require_timeout = require('../../utils/timeout.cjs');
2
1
  const require_api_client = require('./api-client.cjs');
3
2
  const require_engine = require('./engine.cjs');
4
3
  const require_wire_format = require('./wire-format.cjs');
5
4
 
6
5
  //#region src/translators/weglot/translator.ts
7
- const MAX_WORDS_PER_REQUEST = 100;
8
6
  var WeglotTranslator = class {
9
7
  client;
10
8
  engine;
11
- constructor(config, logger, client) {
9
+ /** Texts settled as their source this process, per locale, so they are not polled again. */
10
+ settledAsSource = /* @__PURE__ */ new Map();
11
+ constructor(config, logger, client, pollOptions = {}) {
12
12
  this.config = config;
13
13
  this.logger = logger;
14
- this.client = client ?? new require_api_client.WeglotApiClient(config.apiKey);
15
- this.engine = require_engine.resolveTranslationEngine(config.apiKey, config.translationEngine);
14
+ this.pollOptions = pollOptions;
15
+ this.client = client ?? new require_api_client.WeglotApiClient(config.apiKey, config.apiBaseUrl);
16
+ this.engine = require_engine.resolveTranslationEngine(config.translationEngine);
16
17
  }
17
18
  async translate(locale, entriesMap) {
18
19
  const hashes = Object.keys(entriesMap);
19
20
  this.logger.debug(`Weglot translate() called for ${locale} with ${hashes.length} entries`);
20
21
  const translations = {};
21
22
  const protectedEntries = [];
23
+ const settled = this.settledAsSource.get(locale) ?? /* @__PURE__ */ new Set();
24
+ this.settledAsSource.set(locale, settled);
22
25
  for (const hash of hashes) {
23
26
  const sourceText = entriesMap[hash].text;
27
+ if (settled.has(sourceText)) {
28
+ translations[hash] = sourceText;
29
+ continue;
30
+ }
24
31
  const { wire, restore, encodable } = require_wire_format.encodeForApi(sourceText, this.engine);
25
32
  if (!encodable) {
26
33
  this.logger.warn(`Weglot translation engine ${this.engine} cannot carry the markup in hash "${hash}"; falling back to source text.`);
@@ -33,26 +40,43 @@ var WeglotTranslator = class {
33
40
  restore
34
41
  });
35
42
  }
36
- for (let i = 0; i < protectedEntries.length; i += MAX_WORDS_PER_REQUEST) {
37
- const chunk = protectedEntries.slice(i, i + MAX_WORDS_PER_REQUEST);
38
- this.logger.debug(`Translating chunk ${i / MAX_WORDS_PER_REQUEST + 1} (${chunk.length} words) to ${locale}`);
39
- const translated = await require_timeout.withTimeout(this.client.translate({
40
- from: this.config.sourceLocale,
41
- to: this.config.apiLocales?.[locale] ?? locale,
42
- words: chunk.map((entry) => entry.text)
43
- }), require_timeout.DEFAULT_TIMEOUTS.AI_API, `Weglot API translation to ${locale}`);
44
- chunk.forEach((entry, index) => {
45
- const sourceText = entriesMap[entry.hash].text;
46
- const { text: restored, damaged } = entry.restore(translated[index]);
47
- if (damaged) {
48
- this.logger.warn(`Weglot translation for hash "${entry.hash}" (locale "${locale}") lost an interpolation or element during restore; falling back to source text.`);
49
- translations[entry.hash] = sourceText;
50
- } else if (translated[index] === entry.text && entry.text !== sourceText) {
51
- this.logger.warn(`Weglot API returned hash "${entry.hash}" (locale "${locale}") untranslated; falling back to source text.`);
52
- translations[entry.hash] = sourceText;
53
- } else translations[entry.hash] = restored;
54
- });
43
+ if (protectedEntries.length === 0) return translations;
44
+ const { words: translated, refused } = await this.client.translateUntilReady({
45
+ from: this.config.sourceLocale,
46
+ to: this.config.apiLocales?.[locale] ?? locale,
47
+ words: protectedEntries.map((entry) => entry.text)
48
+ }, {
49
+ ...this.pollOptions,
50
+ deadline: Date.now() + this.config.translationTimeoutMs
51
+ });
52
+ const refusedIndexes = new Set(refused);
53
+ let queued = 0;
54
+ protectedEntries.forEach((entry, index) => {
55
+ const result = translated[index];
56
+ const sourceText = entriesMap[entry.hash].text;
57
+ if (refusedIndexes.has(index)) {
58
+ translations[entry.hash] = sourceText;
59
+ return;
60
+ }
61
+ if (result === null) {
62
+ queued++;
63
+ return;
64
+ }
65
+ const { text: restored, damaged } = entry.restore(result);
66
+ if (damaged) {
67
+ this.logger.warn(`Weglot translation for hash "${entry.hash}" (locale "${locale}") lost an interpolation or element during restore; falling back to source text.`);
68
+ translations[entry.hash] = sourceText;
69
+ } else if (result === entry.text && entry.text !== sourceText) {
70
+ this.logger.warn(`Weglot API returned hash "${entry.hash}" (locale "${locale}") untranslated; falling back to source text.`);
71
+ translations[entry.hash] = sourceText;
72
+ } else translations[entry.hash] = restored;
73
+ });
74
+ for (const [hash, text] of Object.entries(translations)) if (text === entriesMap[hash].text) settled.add(text);
75
+ if (refused.length > 0) {
76
+ const examples = refused.slice(0, 5).map((index) => `"${entriesMap[protectedEntries[index].hash].text.slice(0, 80)}"`).join(", ");
77
+ this.logger.warn(`Weglot will not translate ${refused.length} ${locale} string(s), served untranslated: ${examples}${refused.length > 5 ? ", ..." : ""}`);
55
78
  }
79
+ if (queued > 0) this.logger.warn(`${queued} ${locale} translation(s) are still being generated by Weglot after ${Math.round(this.config.translationTimeoutMs / 1e3)}s. Translations already received are cached, so running again picks up the rest.`);
56
80
  return translations;
57
81
  }
58
82
  };
@@ -1,26 +1,33 @@
1
- import { DEFAULT_TIMEOUTS, withTimeout } from "../../utils/timeout.mjs";
2
1
  import { WeglotApiClient } from "./api-client.mjs";
3
2
  import { resolveTranslationEngine } from "./engine.mjs";
4
3
  import { encodeForApi } from "./wire-format.mjs";
5
4
 
6
5
  //#region src/translators/weglot/translator.ts
7
- const MAX_WORDS_PER_REQUEST = 100;
8
6
  var WeglotTranslator = class {
9
7
  client;
10
8
  engine;
11
- constructor(config, logger, client) {
9
+ /** Texts settled as their source this process, per locale, so they are not polled again. */
10
+ settledAsSource = /* @__PURE__ */ new Map();
11
+ constructor(config, logger, client, pollOptions = {}) {
12
12
  this.config = config;
13
13
  this.logger = logger;
14
- this.client = client ?? new WeglotApiClient(config.apiKey);
15
- this.engine = resolveTranslationEngine(config.apiKey, config.translationEngine);
14
+ this.pollOptions = pollOptions;
15
+ this.client = client ?? new WeglotApiClient(config.apiKey, config.apiBaseUrl);
16
+ this.engine = resolveTranslationEngine(config.translationEngine);
16
17
  }
17
18
  async translate(locale, entriesMap) {
18
19
  const hashes = Object.keys(entriesMap);
19
20
  this.logger.debug(`Weglot translate() called for ${locale} with ${hashes.length} entries`);
20
21
  const translations = {};
21
22
  const protectedEntries = [];
23
+ const settled = this.settledAsSource.get(locale) ?? /* @__PURE__ */ new Set();
24
+ this.settledAsSource.set(locale, settled);
22
25
  for (const hash of hashes) {
23
26
  const sourceText = entriesMap[hash].text;
27
+ if (settled.has(sourceText)) {
28
+ translations[hash] = sourceText;
29
+ continue;
30
+ }
24
31
  const { wire, restore, encodable } = encodeForApi(sourceText, this.engine);
25
32
  if (!encodable) {
26
33
  this.logger.warn(`Weglot translation engine ${this.engine} cannot carry the markup in hash "${hash}"; falling back to source text.`);
@@ -33,26 +40,43 @@ var WeglotTranslator = class {
33
40
  restore
34
41
  });
35
42
  }
36
- for (let i = 0; i < protectedEntries.length; i += MAX_WORDS_PER_REQUEST) {
37
- const chunk = protectedEntries.slice(i, i + MAX_WORDS_PER_REQUEST);
38
- this.logger.debug(`Translating chunk ${i / MAX_WORDS_PER_REQUEST + 1} (${chunk.length} words) to ${locale}`);
39
- const translated = await withTimeout(this.client.translate({
40
- from: this.config.sourceLocale,
41
- to: this.config.apiLocales?.[locale] ?? locale,
42
- words: chunk.map((entry) => entry.text)
43
- }), DEFAULT_TIMEOUTS.AI_API, `Weglot API translation to ${locale}`);
44
- chunk.forEach((entry, index) => {
45
- const sourceText = entriesMap[entry.hash].text;
46
- const { text: restored, damaged } = entry.restore(translated[index]);
47
- if (damaged) {
48
- this.logger.warn(`Weglot translation for hash "${entry.hash}" (locale "${locale}") lost an interpolation or element during restore; falling back to source text.`);
49
- translations[entry.hash] = sourceText;
50
- } else if (translated[index] === entry.text && entry.text !== sourceText) {
51
- this.logger.warn(`Weglot API returned hash "${entry.hash}" (locale "${locale}") untranslated; falling back to source text.`);
52
- translations[entry.hash] = sourceText;
53
- } else translations[entry.hash] = restored;
54
- });
43
+ if (protectedEntries.length === 0) return translations;
44
+ const { words: translated, refused } = await this.client.translateUntilReady({
45
+ from: this.config.sourceLocale,
46
+ to: this.config.apiLocales?.[locale] ?? locale,
47
+ words: protectedEntries.map((entry) => entry.text)
48
+ }, {
49
+ ...this.pollOptions,
50
+ deadline: Date.now() + this.config.translationTimeoutMs
51
+ });
52
+ const refusedIndexes = new Set(refused);
53
+ let queued = 0;
54
+ protectedEntries.forEach((entry, index) => {
55
+ const result = translated[index];
56
+ const sourceText = entriesMap[entry.hash].text;
57
+ if (refusedIndexes.has(index)) {
58
+ translations[entry.hash] = sourceText;
59
+ return;
60
+ }
61
+ if (result === null) {
62
+ queued++;
63
+ return;
64
+ }
65
+ const { text: restored, damaged } = entry.restore(result);
66
+ if (damaged) {
67
+ this.logger.warn(`Weglot translation for hash "${entry.hash}" (locale "${locale}") lost an interpolation or element during restore; falling back to source text.`);
68
+ translations[entry.hash] = sourceText;
69
+ } else if (result === entry.text && entry.text !== sourceText) {
70
+ this.logger.warn(`Weglot API returned hash "${entry.hash}" (locale "${locale}") untranslated; falling back to source text.`);
71
+ translations[entry.hash] = sourceText;
72
+ } else translations[entry.hash] = restored;
73
+ });
74
+ for (const [hash, text] of Object.entries(translations)) if (text === entriesMap[hash].text) settled.add(text);
75
+ if (refused.length > 0) {
76
+ const examples = refused.slice(0, 5).map((index) => `"${entriesMap[protectedEntries[index].hash].text.slice(0, 80)}"`).join(", ");
77
+ this.logger.warn(`Weglot will not translate ${refused.length} ${locale} string(s), served untranslated: ${examples}${refused.length > 5 ? ", ..." : ""}`);
55
78
  }
79
+ if (queued > 0) this.logger.warn(`${queued} ${locale} translation(s) are still being generated by Weglot after ${Math.round(this.config.translationTimeoutMs / 1e3)}s. Translations already received are cached, so running again picks up the rest.`);
56
80
  return translations;
57
81
  }
58
82
  };
@@ -1 +1 @@
1
- {"version":3,"file":"translator.mjs","names":["config: WeglotTranslatorConfig","logger: Logger","translations: Record<string, string>","protectedEntries: {\n hash: string;\n text: string;\n restore: (translated: string) => RestoredTranslation;\n }[]"],"sources":["../../../src/translators/weglot/translator.ts"],"sourcesContent":["import type { LocaleCode } from \"../../locale\";\nimport type { TranslatableEntry, Translator } from \"../api\";\nimport type { Logger } from \"../../utils/logger\";\nimport { DEFAULT_TIMEOUTS, withTimeout } from \"../../utils/timeout\";\nimport { WeglotApiClient } from \"./api-client\";\nimport { encodeForApi, type RestoredTranslation } from \"./wire-format\";\nimport { resolveTranslationEngine } from \"./engine\";\n\nconst MAX_WORDS_PER_REQUEST = 100;\n\nexport interface WeglotTranslatorConfig {\n apiKey: string;\n sourceLocale: LocaleCode;\n /** Public locale to the language code the translate API expects. */\n apiLocales?: Record<string, LocaleCode>;\n /** From the project settings; derived from the key length when absent. */\n translationEngine?: number;\n}\n\nexport class WeglotTranslator implements Translator<WeglotTranslatorConfig> {\n private readonly client: WeglotApiClient;\n private readonly engine: number;\n\n constructor(\n readonly config: WeglotTranslatorConfig,\n private readonly logger: Logger,\n client?: WeglotApiClient,\n ) {\n this.client = client ?? new WeglotApiClient(config.apiKey);\n this.engine = resolveTranslationEngine(\n config.apiKey,\n config.translationEngine,\n );\n }\n\n async translate(\n locale: LocaleCode,\n entriesMap: Record<string, TranslatableEntry>,\n ): Promise<Record<string, string>> {\n const hashes = Object.keys(entriesMap);\n this.logger.debug(\n `Weglot translate() called for ${locale} with ${hashes.length} entries`,\n );\n\n const translations: Record<string, string> = {};\n const protectedEntries: {\n hash: string;\n text: string;\n restore: (translated: string) => RestoredTranslation;\n }[] = [];\n\n for (const hash of hashes) {\n const sourceText = entriesMap[hash].text;\n const { wire, restore, encodable } = encodeForApi(sourceText, this.engine);\n if (!encodable) {\n // Engine 1 merges nothing, so markup cannot survive the wire form.\n this.logger.warn(\n `Weglot translation engine ${this.engine} cannot carry the markup in hash \"${hash}\"; falling back to source text.`,\n );\n translations[hash] = sourceText;\n continue;\n }\n protectedEntries.push({ hash, text: wire, restore });\n }\n\n for (let i = 0; i < protectedEntries.length; i += MAX_WORDS_PER_REQUEST) {\n const chunk = protectedEntries.slice(i, i + MAX_WORDS_PER_REQUEST);\n this.logger.debug(\n `Translating chunk ${i / MAX_WORDS_PER_REQUEST + 1} (${chunk.length} words) to ${locale}`,\n );\n\n const translated = await withTimeout(\n this.client.translate({\n from: this.config.sourceLocale,\n to: this.config.apiLocales?.[locale] ?? locale,\n words: chunk.map((entry) => entry.text),\n }),\n DEFAULT_TIMEOUTS.AI_API,\n `Weglot API translation to ${locale}`,\n );\n\n chunk.forEach((entry, index) => {\n const sourceText = entriesMap[entry.hash].text;\n const { text: restored, damaged } = entry.restore(translated[index]);\n\n if (damaged) {\n this.logger.warn(\n `Weglot translation for hash \"${entry.hash}\" (locale \"${locale}\") lost an interpolation or element during restore; falling back to source text.`,\n );\n translations[entry.hash] = sourceText;\n } else if (translated[index] === entry.text && entry.text !== sourceText) {\n // The API echoes a segment back verbatim when it rejects its markup.\n this.logger.warn(\n `Weglot API returned hash \"${entry.hash}\" (locale \"${locale}\") untranslated; falling back to source text.`,\n );\n translations[entry.hash] = sourceText;\n } else {\n translations[entry.hash] = restored;\n }\n });\n }\n\n return translations;\n }\n}\n"],"mappings":";;;;;;AAQA,MAAM,wBAAwB;AAW9B,IAAa,mBAAb,MAA4E;CAC1E,AAAiB;CACjB,AAAiB;CAEjB,YACE,AAASA,QACT,AAAiBC,QACjB,QACA;EAHS;EACQ;AAGjB,OAAK,SAAS,UAAU,IAAI,gBAAgB,OAAO,OAAO;AAC1D,OAAK,SAAS,yBACZ,OAAO,QACP,OAAO,kBACR;;CAGH,MAAM,UACJ,QACA,YACiC;EACjC,MAAM,SAAS,OAAO,KAAK,WAAW;AACtC,OAAK,OAAO,MACV,iCAAiC,OAAO,QAAQ,OAAO,OAAO,UAC/D;EAED,MAAMC,eAAuC,EAAE;EAC/C,MAAMC,mBAIA,EAAE;AAER,OAAK,MAAM,QAAQ,QAAQ;GACzB,MAAM,aAAa,WAAW,MAAM;GACpC,MAAM,EAAE,MAAM,SAAS,cAAc,aAAa,YAAY,KAAK,OAAO;AAC1E,OAAI,CAAC,WAAW;AAEd,SAAK,OAAO,KACV,6BAA6B,KAAK,OAAO,oCAAoC,KAAK,iCACnF;AACD,iBAAa,QAAQ;AACrB;;AAEF,oBAAiB,KAAK;IAAE;IAAM,MAAM;IAAM;IAAS,CAAC;;AAGtD,OAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,QAAQ,KAAK,uBAAuB;GACvE,MAAM,QAAQ,iBAAiB,MAAM,GAAG,IAAI,sBAAsB;AAClE,QAAK,OAAO,MACV,qBAAqB,IAAI,wBAAwB,EAAE,IAAI,MAAM,OAAO,aAAa,SAClF;GAED,MAAM,aAAa,MAAM,YACvB,KAAK,OAAO,UAAU;IACpB,MAAM,KAAK,OAAO;IAClB,IAAI,KAAK,OAAO,aAAa,WAAW;IACxC,OAAO,MAAM,KAAK,UAAU,MAAM,KAAK;IACxC,CAAC,EACF,iBAAiB,QACjB,6BAA6B,SAC9B;AAED,SAAM,SAAS,OAAO,UAAU;IAC9B,MAAM,aAAa,WAAW,MAAM,MAAM;IAC1C,MAAM,EAAE,MAAM,UAAU,YAAY,MAAM,QAAQ,WAAW,OAAO;AAEpE,QAAI,SAAS;AACX,UAAK,OAAO,KACV,gCAAgC,MAAM,KAAK,aAAa,OAAO,kFAChE;AACD,kBAAa,MAAM,QAAQ;eAClB,WAAW,WAAW,MAAM,QAAQ,MAAM,SAAS,YAAY;AAExE,UAAK,OAAO,KACV,6BAA6B,MAAM,KAAK,aAAa,OAAO,+CAC7D;AACD,kBAAa,MAAM,QAAQ;UAE3B,cAAa,MAAM,QAAQ;KAE7B;;AAGJ,SAAO"}
1
+ {"version":3,"file":"translator.mjs","names":["config: WeglotTranslatorConfig","logger: Logger","pollOptions: Omit<PollOptions, \"deadline\">","translations: Record<string, string>","protectedEntries: {\n hash: string;\n text: string;\n restore: (translated: string) => RestoredTranslation;\n }[]"],"sources":["../../../src/translators/weglot/translator.ts"],"sourcesContent":["import type { LocaleCode } from \"../../locale\";\nimport type { TranslatableEntry, Translator } from \"../api\";\nimport type { Logger } from \"../../utils/logger\";\nimport { type PollOptions, WeglotApiClient } from \"./api-client\";\nimport { encodeForApi, type RestoredTranslation } from \"./wire-format\";\nimport { resolveTranslationEngine } from \"./engine\";\n\nexport interface WeglotTranslatorConfig {\n apiKey: string;\n sourceLocale: LocaleCode;\n /** Public locale to the language code the translate API expects. */\n apiLocales?: Record<string, LocaleCode>;\n /** From the project settings; the modern engine when absent. */\n translationEngine?: number;\n /** The project's regional API host, from the project settings. */\n apiBaseUrl?: string;\n /** How long to wait for queued translations before leaving them out. */\n translationTimeoutMs: number;\n}\n\nexport class WeglotTranslator implements Translator<WeglotTranslatorConfig> {\n private readonly client: WeglotApiClient;\n private readonly engine: number;\n /** Texts settled as their source this process, per locale, so they are not polled again. */\n private readonly settledAsSource = new Map<LocaleCode, Set<string>>();\n\n constructor(\n readonly config: WeglotTranslatorConfig,\n private readonly logger: Logger,\n client?: WeglotApiClient,\n private readonly pollOptions: Omit<PollOptions, \"deadline\"> = {},\n ) {\n this.client = client ?? new WeglotApiClient(config.apiKey, config.apiBaseUrl);\n this.engine = resolveTranslationEngine(config.translationEngine);\n }\n\n async translate(\n locale: LocaleCode,\n entriesMap: Record<string, TranslatableEntry>,\n ): Promise<Record<string, string>> {\n const hashes = Object.keys(entriesMap);\n this.logger.debug(\n `Weglot translate() called for ${locale} with ${hashes.length} entries`,\n );\n\n const translations: Record<string, string> = {};\n const protectedEntries: {\n hash: string;\n text: string;\n restore: (translated: string) => RestoredTranslation;\n }[] = [];\n\n const settled = this.settledAsSource.get(locale) ?? new Set<string>();\n this.settledAsSource.set(locale, settled);\n\n for (const hash of hashes) {\n const sourceText = entriesMap[hash].text;\n if (settled.has(sourceText)) {\n translations[hash] = sourceText;\n continue;\n }\n const { wire, restore, encodable } = encodeForApi(sourceText, this.engine);\n if (!encodable) {\n // Engine 1 merges nothing, so markup cannot survive the wire form.\n this.logger.warn(\n `Weglot translation engine ${this.engine} cannot carry the markup in hash \"${hash}\"; falling back to source text.`,\n );\n translations[hash] = sourceText;\n continue;\n }\n protectedEntries.push({ hash, text: wire, restore });\n }\n\n if (protectedEntries.length === 0) return translations;\n\n const { words: translated, refused } = await this.client.translateUntilReady(\n {\n from: this.config.sourceLocale,\n to: this.config.apiLocales?.[locale] ?? locale,\n words: protectedEntries.map((entry) => entry.text),\n },\n {\n ...this.pollOptions,\n deadline: Date.now() + this.config.translationTimeoutMs,\n },\n );\n\n const refusedIndexes = new Set(refused);\n let queued = 0;\n protectedEntries.forEach((entry, index) => {\n const result = translated[index];\n const sourceText = entriesMap[entry.hash].text;\n\n if (refusedIndexes.has(index)) {\n translations[entry.hash] = sourceText;\n return;\n }\n if (result === null) {\n // Left out rather than filled with source, which would be cached.\n queued++;\n return;\n }\n\n const { text: restored, damaged } = entry.restore(result);\n if (damaged) {\n this.logger.warn(\n `Weglot translation for hash \"${entry.hash}\" (locale \"${locale}\") lost an interpolation or element during restore; falling back to source text.`,\n );\n translations[entry.hash] = sourceText;\n } else if (result === entry.text && entry.text !== sourceText) {\n // The API echoes a segment back verbatim when it rejects its markup.\n this.logger.warn(\n `Weglot API returned hash \"${entry.hash}\" (locale \"${locale}\") untranslated; falling back to source text.`,\n );\n translations[entry.hash] = sourceText;\n } else {\n translations[entry.hash] = restored;\n }\n });\n\n for (const [hash, text] of Object.entries(translations)) {\n if (text === entriesMap[hash].text) settled.add(text);\n }\n\n if (refused.length > 0) {\n const examples = refused\n .slice(0, 5)\n .map((index) => `\"${entriesMap[protectedEntries[index].hash].text.slice(0, 80)}\"`)\n .join(\", \");\n this.logger.warn(\n `Weglot will not translate ${refused.length} ${locale} string(s), served untranslated: ${examples}${refused.length > 5 ? \", ...\" : \"\"}`,\n );\n }\n\n if (queued > 0) {\n this.logger.warn(\n `${queued} ${locale} translation(s) are still being generated by Weglot after ${Math.round(this.config.translationTimeoutMs / 1000)}s. Translations already received are cached, so running again picks up the rest.`,\n );\n }\n\n return translations;\n }\n}\n"],"mappings":";;;;;AAoBA,IAAa,mBAAb,MAA4E;CAC1E,AAAiB;CACjB,AAAiB;;CAEjB,AAAiB,kCAAkB,IAAI,KAA8B;CAErE,YACE,AAASA,QACT,AAAiBC,QACjB,QACA,AAAiBC,cAA6C,EAAE,EAChE;EAJS;EACQ;EAEA;AAEjB,OAAK,SAAS,UAAU,IAAI,gBAAgB,OAAO,QAAQ,OAAO,WAAW;AAC7E,OAAK,SAAS,yBAAyB,OAAO,kBAAkB;;CAGlE,MAAM,UACJ,QACA,YACiC;EACjC,MAAM,SAAS,OAAO,KAAK,WAAW;AACtC,OAAK,OAAO,MACV,iCAAiC,OAAO,QAAQ,OAAO,OAAO,UAC/D;EAED,MAAMC,eAAuC,EAAE;EAC/C,MAAMC,mBAIA,EAAE;EAER,MAAM,UAAU,KAAK,gBAAgB,IAAI,OAAO,oBAAI,IAAI,KAAa;AACrE,OAAK,gBAAgB,IAAI,QAAQ,QAAQ;AAEzC,OAAK,MAAM,QAAQ,QAAQ;GACzB,MAAM,aAAa,WAAW,MAAM;AACpC,OAAI,QAAQ,IAAI,WAAW,EAAE;AAC3B,iBAAa,QAAQ;AACrB;;GAEF,MAAM,EAAE,MAAM,SAAS,cAAc,aAAa,YAAY,KAAK,OAAO;AAC1E,OAAI,CAAC,WAAW;AAEd,SAAK,OAAO,KACV,6BAA6B,KAAK,OAAO,oCAAoC,KAAK,iCACnF;AACD,iBAAa,QAAQ;AACrB;;AAEF,oBAAiB,KAAK;IAAE;IAAM,MAAM;IAAM;IAAS,CAAC;;AAGtD,MAAI,iBAAiB,WAAW,EAAG,QAAO;EAE1C,MAAM,EAAE,OAAO,YAAY,YAAY,MAAM,KAAK,OAAO,oBACvD;GACE,MAAM,KAAK,OAAO;GAClB,IAAI,KAAK,OAAO,aAAa,WAAW;GACxC,OAAO,iBAAiB,KAAK,UAAU,MAAM,KAAK;GACnD,EACD;GACE,GAAG,KAAK;GACR,UAAU,KAAK,KAAK,GAAG,KAAK,OAAO;GACpC,CACF;EAED,MAAM,iBAAiB,IAAI,IAAI,QAAQ;EACvC,IAAI,SAAS;AACb,mBAAiB,SAAS,OAAO,UAAU;GACzC,MAAM,SAAS,WAAW;GAC1B,MAAM,aAAa,WAAW,MAAM,MAAM;AAE1C,OAAI,eAAe,IAAI,MAAM,EAAE;AAC7B,iBAAa,MAAM,QAAQ;AAC3B;;AAEF,OAAI,WAAW,MAAM;AAEnB;AACA;;GAGF,MAAM,EAAE,MAAM,UAAU,YAAY,MAAM,QAAQ,OAAO;AACzD,OAAI,SAAS;AACX,SAAK,OAAO,KACV,gCAAgC,MAAM,KAAK,aAAa,OAAO,kFAChE;AACD,iBAAa,MAAM,QAAQ;cAClB,WAAW,MAAM,QAAQ,MAAM,SAAS,YAAY;AAE7D,SAAK,OAAO,KACV,6BAA6B,MAAM,KAAK,aAAa,OAAO,+CAC7D;AACD,iBAAa,MAAM,QAAQ;SAE3B,cAAa,MAAM,QAAQ;IAE7B;AAEF,OAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,aAAa,CACrD,KAAI,SAAS,WAAW,MAAM,KAAM,SAAQ,IAAI,KAAK;AAGvD,MAAI,QAAQ,SAAS,GAAG;GACtB,MAAM,WAAW,QACd,MAAM,GAAG,EAAE,CACX,KAAK,UAAU,IAAI,WAAW,iBAAiB,OAAO,MAAM,KAAK,MAAM,GAAG,GAAG,CAAC,GAAG,CACjF,KAAK,KAAK;AACb,QAAK,OAAO,KACV,6BAA6B,QAAQ,OAAO,GAAG,OAAO,mCAAmC,WAAW,QAAQ,SAAS,IAAI,UAAU,KACpI;;AAGH,MAAI,SAAS,EACX,MAAK,OAAO,KACV,GAAG,OAAO,GAAG,OAAO,4DAA4D,KAAK,MAAM,KAAK,OAAO,uBAAuB,IAAK,CAAC,kFACrI;AAGH,SAAO"}
package/build/types.d.cts CHANGED
@@ -29,7 +29,7 @@ type LocalePersistenceConfig = {
29
29
  * Fields that are resolved internally (from the Weglot project settings or the
30
30
  * environment) rather than provided by users.
31
31
  */
32
- type WeglotInternalFields = "environment" | "cacheType" | "sourceLocale" | "targetLocales" | "apiLocales" | "translationEngine" | "weglotDir";
32
+ type WeglotInternalFields = "environment" | "cacheType" | "sourceLocale" | "targetLocales" | "apiLocales" | "translationEngine" | "apiBaseUrl" | "weglotDir";
33
33
  /**
34
34
  * Configuration for @weglot/translate-react
35
35
  */
@@ -92,9 +92,19 @@ type WeglotConfig = {
92
92
  /** Public locale to the code the translate API expects, for languages with a
93
93
  * custom code. Resolved from the project settings. @internal */
94
94
  apiLocales: Record<string, LocaleCode>;
95
- /** Inline elements allowed inside a segment, from the project settings or the
96
- * key length. @internal */
95
+ /** Inline elements allowed inside a segment, from the project settings.
96
+ * @internal */
97
97
  translationEngine: number;
98
+ /** The project's regional API host, from the project settings. @internal */
99
+ apiBaseUrl: string;
100
+ /**
101
+ * Seconds to wait for translations Weglot is still generating. What is still
102
+ * missing then fails a `translate` build; in dev it shows up on a reload.
103
+ * Can be overridden by WEGLOT_TRANSLATION_TIMEOUT environment variable.
104
+ *
105
+ * @default 300 in a build, 10 in dev
106
+ */
107
+ translationTimeout: number;
98
108
  /**
99
109
  * Whether to require 'use i18n' directive
100
110
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;AA2BA;AAMA;AAYA;AACO,UArCU,YAAA,CAqCV;EAAc;;;;EADa,IAAA,EAAA,MAAA;EAAO;AAMzC;AAKA;;EA6CgB,MAAA,EAAA,MAAA;;;;;;AAsD4B,KAhIhC,uBAAA,GAgIgC;;UAhIoB;;;;;;KAMpD,oBAAA;;;;KAYA,mBAAA,GAAsB,QAChC,KAAK,cAAc;OACZ,QAAQ;;KAIL,iBAAA;;;;KAKA,YAAA;;;;;;;;;;;;;;;;;;;;;;;eA0BG;;;;;;;;;;;;;;;;;gBAmBC;;;;;;;;iBASC;;;cAIH,eAAe;;;;;;;;;;;;0BAeH;;;;;;;;;;;;;;;;;;;;;;;qBA0BL"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;AA2BA;AAMA;AAaA;AACO,UAtCU,YAAA,CAsCV;EAAc;;;;EADa,IAAA,EAAA,MAAA;EAAO;AAMzC;AAKA;;EA6CgB,MAAA,EAAA,MAAA;;;;;;AAkE4B,KA7IhC,uBAAA,GA6IgC;;UA7IoB;;;;;;KAMpD,oBAAA;;;;KAaA,mBAAA,GAAsB,QAChC,KAAK,cAAc;OACZ,QAAQ;;KAIL,iBAAA;;;;KAKA,YAAA;;;;;;;;;;;;;;;;;;;;;;;eA0BG;;;;;;;;;;;;;;;;;gBAmBC;;;;;;;;iBASC;;;cAIH,eAAe;;;;;;;;;;;;;;;;;;;;;;0BA2BH;;;;;;;;;;;;;;;;;;;;;;;qBA0BL"}
package/build/types.d.mts CHANGED
@@ -29,7 +29,7 @@ type LocalePersistenceConfig = {
29
29
  * Fields that are resolved internally (from the Weglot project settings or the
30
30
  * environment) rather than provided by users.
31
31
  */
32
- type WeglotInternalFields = "environment" | "cacheType" | "sourceLocale" | "targetLocales" | "apiLocales" | "translationEngine" | "weglotDir";
32
+ type WeglotInternalFields = "environment" | "cacheType" | "sourceLocale" | "targetLocales" | "apiLocales" | "translationEngine" | "apiBaseUrl" | "weglotDir";
33
33
  /**
34
34
  * Configuration for @weglot/translate-react
35
35
  */
@@ -92,9 +92,19 @@ type WeglotConfig = {
92
92
  /** Public locale to the code the translate API expects, for languages with a
93
93
  * custom code. Resolved from the project settings. @internal */
94
94
  apiLocales: Record<string, LocaleCode>;
95
- /** Inline elements allowed inside a segment, from the project settings or the
96
- * key length. @internal */
95
+ /** Inline elements allowed inside a segment, from the project settings.
96
+ * @internal */
97
97
  translationEngine: number;
98
+ /** The project's regional API host, from the project settings. @internal */
99
+ apiBaseUrl: string;
100
+ /**
101
+ * Seconds to wait for translations Weglot is still generating. What is still
102
+ * missing then fails a `translate` build; in dev it shows up on a reload.
103
+ * Can be overridden by WEGLOT_TRANSLATION_TIMEOUT environment variable.
104
+ *
105
+ * @default 300 in a build, 10 in dev
106
+ */
107
+ translationTimeout: number;
98
108
  /**
99
109
  * Whether to require 'use i18n' directive
100
110
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;AA2BA;AAMA;AAYA;AACO,UArCU,YAAA,CAqCV;EAAc;;;;EADa,IAAA,EAAA,MAAA;EAAO;AAMzC;AAKA;;EA6CgB,MAAA,EAAA,MAAA;;;;;;AAsD4B,KAhIhC,uBAAA,GAgIgC;;UAhIoB;;;;;;KAMpD,oBAAA;;;;KAYA,mBAAA,GAAsB,QAChC,KAAK,cAAc;OACZ,QAAQ;;KAIL,iBAAA;;;;KAKA,YAAA;;;;;;;;;;;;;;;;;;;;;;;eA0BG;;;;;;;;;;;;;;;;;gBAmBC;;;;;;;;iBASC;;;cAIH,eAAe;;;;;;;;;;;;0BAeH;;;;;;;;;;;;;;;;;;;;;;;qBA0BL"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;AA2BA;AAMA;AAaA;AACO,UAtCU,YAAA,CAsCV;EAAc;;;;EADa,IAAA,EAAA,MAAA;EAAO;AAMzC;AAKA;;EA6CgB,MAAA,EAAA,MAAA;;;;;;AAkE4B,KA7IhC,uBAAA,GA6IgC;;UA7IoB;;;;;;KAMpD,oBAAA;;;;KAaA,mBAAA,GAAsB,QAChC,KAAK,cAAc;OACZ,QAAQ;;KAIL,iBAAA;;;;KAKA,YAAA;;;;;;;;;;;;;;;;;;;;;;;eA0BG;;;;;;;;;;;;;;;;;gBAmBC;;;;;;;;iBASC;;;cAIH,eAAe;;;;;;;;;;;;;;;;;;;;;;0BA2BH;;;;;;;;;;;;;;;;;;;;;;;qBA0BL"}
@@ -24,6 +24,16 @@ const DEFAULT_CONFIG = {
24
24
  },
25
25
  buildMode: "translate"
26
26
  };
27
+ const DEFAULT_TRANSLATION_TIMEOUT = {
28
+ production: 300,
29
+ development: 10
30
+ };
31
+ function timeoutFromEnv() {
32
+ const raw = process.env.WEGLOT_TRANSLATION_TIMEOUT;
33
+ if (!raw) return void 0;
34
+ const value = Number(raw);
35
+ return Number.isFinite(value) && value >= 0 ? value : void 0;
36
+ }
27
37
  /**
28
38
  * Create a LoaderConfig with defaults applied
29
39
  *
@@ -43,6 +53,7 @@ function createWeglotConfig(options) {
43
53
  cleanObject(cleanOptions);
44
54
  const apiKey = cleanOptions.apiKey ?? process.env.WEGLOT_API_KEY;
45
55
  if (!apiKey) throw new Error("Weglot project key is missing. Pass `apiKey` in the plugin options or set the WEGLOT_API_KEY environment variable.");
56
+ const environment = cleanOptions.environment ?? (process.env.NODE_ENV === "development" ? "development" : "production");
46
57
  return {
47
58
  ...DEFAULT_CONFIG,
48
59
  ...cleanOptions,
@@ -50,8 +61,10 @@ function createWeglotConfig(options) {
50
61
  sourceLocale: cleanOptions.sourceLocale ?? "",
51
62
  targetLocales: cleanOptions.targetLocales ?? [],
52
63
  apiLocales: cleanOptions.apiLocales ?? {},
53
- translationEngine: cleanOptions.translationEngine ?? require_engine.resolveTranslationEngine(apiKey),
54
- environment: cleanOptions.environment ?? (process.env.NODE_ENV === "development" ? "development" : "production"),
64
+ translationEngine: require_engine.resolveTranslationEngine(cleanOptions.translationEngine),
65
+ apiBaseUrl: cleanOptions.apiBaseUrl ?? "",
66
+ translationTimeout: cleanOptions.translationTimeout ?? timeoutFromEnv() ?? DEFAULT_TRANSLATION_TIMEOUT[environment],
67
+ environment,
55
68
  cacheType: cleanOptions.cacheType ?? "local",
56
69
  dev: {
57
70
  ...DEFAULT_CONFIG.dev,
@@ -73,12 +86,13 @@ function createWeglotConfig(options) {
73
86
  * through Next.js loader options).
74
87
  */
75
88
  async function resolveProjectLanguages(config, client = new require_api_client.WeglotApiClient(config.apiKey)) {
76
- if (config.sourceLocale && config.targetLocales.length > 0) return;
89
+ if (config.sourceLocale && config.targetLocales.length > 0 && config.apiBaseUrl) return;
77
90
  const settings = await client.fetchSettings();
78
91
  config.sourceLocale = settings.sourceLocale;
79
92
  config.targetLocales = settings.targetLocales;
80
93
  config.apiLocales = settings.apiLocales;
81
- config.translationEngine = require_engine.resolveTranslationEngine(config.apiKey, settings.translationEngine);
94
+ config.apiBaseUrl = settings.apiBaseUrl || require_api_client.DEFAULT_API_BASE_URL;
95
+ config.translationEngine = require_engine.resolveTranslationEngine(settings.translationEngine);
82
96
  }
83
97
 
84
98
  //#endregion
@@ -1,4 +1,4 @@
1
- import { WeglotApiClient } from "../translators/weglot/api-client.mjs";
1
+ import { DEFAULT_API_BASE_URL, WeglotApiClient } from "../translators/weglot/api-client.mjs";
2
2
  import { resolveTranslationEngine } from "../translators/weglot/engine.mjs";
3
3
  import "dotenv/config";
4
4
 
@@ -21,6 +21,16 @@ const DEFAULT_CONFIG = {
21
21
  },
22
22
  buildMode: "translate"
23
23
  };
24
+ const DEFAULT_TRANSLATION_TIMEOUT = {
25
+ production: 300,
26
+ development: 10
27
+ };
28
+ function timeoutFromEnv() {
29
+ const raw = process.env.WEGLOT_TRANSLATION_TIMEOUT;
30
+ if (!raw) return void 0;
31
+ const value = Number(raw);
32
+ return Number.isFinite(value) && value >= 0 ? value : void 0;
33
+ }
24
34
  /**
25
35
  * Create a LoaderConfig with defaults applied
26
36
  *
@@ -40,6 +50,7 @@ function createWeglotConfig(options) {
40
50
  cleanObject(cleanOptions);
41
51
  const apiKey = cleanOptions.apiKey ?? process.env.WEGLOT_API_KEY;
42
52
  if (!apiKey) throw new Error("Weglot project key is missing. Pass `apiKey` in the plugin options or set the WEGLOT_API_KEY environment variable.");
53
+ const environment = cleanOptions.environment ?? (process.env.NODE_ENV === "development" ? "development" : "production");
43
54
  return {
44
55
  ...DEFAULT_CONFIG,
45
56
  ...cleanOptions,
@@ -47,8 +58,10 @@ function createWeglotConfig(options) {
47
58
  sourceLocale: cleanOptions.sourceLocale ?? "",
48
59
  targetLocales: cleanOptions.targetLocales ?? [],
49
60
  apiLocales: cleanOptions.apiLocales ?? {},
50
- translationEngine: cleanOptions.translationEngine ?? resolveTranslationEngine(apiKey),
51
- environment: cleanOptions.environment ?? (process.env.NODE_ENV === "development" ? "development" : "production"),
61
+ translationEngine: resolveTranslationEngine(cleanOptions.translationEngine),
62
+ apiBaseUrl: cleanOptions.apiBaseUrl ?? "",
63
+ translationTimeout: cleanOptions.translationTimeout ?? timeoutFromEnv() ?? DEFAULT_TRANSLATION_TIMEOUT[environment],
64
+ environment,
52
65
  cacheType: cleanOptions.cacheType ?? "local",
53
66
  dev: {
54
67
  ...DEFAULT_CONFIG.dev,
@@ -70,12 +83,13 @@ function createWeglotConfig(options) {
70
83
  * through Next.js loader options).
71
84
  */
72
85
  async function resolveProjectLanguages(config, client = new WeglotApiClient(config.apiKey)) {
73
- if (config.sourceLocale && config.targetLocales.length > 0) return;
86
+ if (config.sourceLocale && config.targetLocales.length > 0 && config.apiBaseUrl) return;
74
87
  const settings = await client.fetchSettings();
75
88
  config.sourceLocale = settings.sourceLocale;
76
89
  config.targetLocales = settings.targetLocales;
77
90
  config.apiLocales = settings.apiLocales;
78
- config.translationEngine = resolveTranslationEngine(config.apiKey, settings.translationEngine);
91
+ config.apiBaseUrl = settings.apiBaseUrl || DEFAULT_API_BASE_URL;
92
+ config.translationEngine = resolveTranslationEngine(settings.translationEngine);
79
93
  }
80
94
 
81
95
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"config-factory.mjs","names":[],"sources":["../../src/utils/config-factory.ts"],"sourcesContent":["/**\n * Config factory for creating LoaderConfig instances\n */\nimport \"dotenv/config\";\nimport type {\n WeglotConfig,\n WeglotInternalFields,\n PartialWeglotConfig,\n} from \"../types\";\nimport { WeglotApiClient } from \"../translators/weglot/api-client\";\nimport { resolveTranslationEngine } from \"../translators/weglot/engine\";\n\n/**\n * Default configuration values\n */\nexport const DEFAULT_CONFIG = {\n sourceRoot: \"src\",\n weglotDir: \"weglot\",\n useDirective: false,\n translatableAttributes: {},\n dev: {\n translationServerStartPort: 60000,\n },\n localePersistence: {\n type: \"cookie\" as const,\n config: {\n name: \"locale\",\n maxAge: 31536000,\n },\n },\n buildMode: \"translate\",\n} satisfies Omit<\n WeglotConfig,\n // weglotDir is an internal field for public-config purposes, but (unlike\n // the other internal fields) it still has a static default here rather\n // than being resolved at runtime, so it stays out of this Omit.\n \"apiKey\" | Exclude<WeglotInternalFields, \"weglotDir\">\n>;\n\n/**\n * Create a LoaderConfig with defaults applied\n *\n * @param options - Partial config to override defaults\n * @returns Complete LoaderConfig with all defaults applied\n *\n */\nexport function createWeglotConfig(\n options: PartialWeglotConfig & Partial<Pick<WeglotConfig, WeglotInternalFields>>,\n): WeglotConfig {\n const cleanOptions = { ...options };\n\n const cleanObject = (obj: any) => {\n if (!obj || typeof obj !== \"object\") return;\n Object.keys(obj).forEach((key) => {\n if (obj[key] === undefined) {\n delete obj[key];\n } else if (\n obj[key] &&\n typeof obj[key] === \"object\" &&\n !Array.isArray(obj[key])\n ) {\n cleanObject(obj[key]);\n }\n });\n };\n\n cleanObject(cleanOptions);\n\n const apiKey = cleanOptions.apiKey ?? process.env.WEGLOT_API_KEY;\n if (!apiKey) {\n throw new Error(\n \"Weglot project key is missing. Pass `apiKey` in the plugin options or set the WEGLOT_API_KEY environment variable.\",\n );\n }\n\n return {\n ...DEFAULT_CONFIG,\n ...cleanOptions,\n apiKey,\n sourceLocale: cleanOptions.sourceLocale ?? \"\",\n targetLocales: cleanOptions.targetLocales ?? [],\n apiLocales: cleanOptions.apiLocales ?? {},\n translationEngine:\n cleanOptions.translationEngine ?? resolveTranslationEngine(apiKey),\n environment:\n cleanOptions.environment ??\n (process.env.NODE_ENV === \"development\" ? \"development\" : \"production\"),\n cacheType: cleanOptions.cacheType ?? \"local\",\n dev: {\n ...DEFAULT_CONFIG.dev,\n ...cleanOptions.dev,\n },\n localePersistence: {\n ...DEFAULT_CONFIG.localePersistence,\n ...cleanOptions.localePersistence,\n config: {\n ...DEFAULT_CONFIG.localePersistence.config,\n ...cleanOptions.localePersistence?.config,\n },\n },\n };\n}\n\n/**\n * Fetches source/target locales from the Weglot project settings.\n * Idempotent: no-ops when locales are already resolved (e.g. passed\n * through Next.js loader options).\n */\nexport async function resolveProjectLanguages(\n config: WeglotConfig,\n client: WeglotApiClient = new WeglotApiClient(config.apiKey),\n): Promise<void> {\n if (config.sourceLocale && config.targetLocales.length > 0) {\n return;\n }\n const settings = await client.fetchSettings();\n config.sourceLocale = settings.sourceLocale;\n config.targetLocales = settings.targetLocales;\n config.apiLocales = settings.apiLocales;\n config.translationEngine = resolveTranslationEngine(\n config.apiKey,\n settings.translationEngine,\n );\n}\n"],"mappings":";;;;;;;;AAeA,MAAa,iBAAiB;CAC5B,YAAY;CACZ,WAAW;CACX,cAAc;CACd,wBAAwB,EAAE;CAC1B,KAAK,EACH,4BAA4B,KAC7B;CACD,mBAAmB;EACjB,MAAM;EACN,QAAQ;GACN,MAAM;GACN,QAAQ;GACT;EACF;CACD,WAAW;CACZ;;;;;;;;AAeD,SAAgB,mBACd,SACc;CACd,MAAM,eAAe,EAAE,GAAG,SAAS;CAEnC,MAAM,eAAe,QAAa;AAChC,MAAI,CAAC,OAAO,OAAO,QAAQ,SAAU;AACrC,SAAO,KAAK,IAAI,CAAC,SAAS,QAAQ;AAChC,OAAI,IAAI,SAAS,OACf,QAAO,IAAI;YAEX,IAAI,QACJ,OAAO,IAAI,SAAS,YACpB,CAAC,MAAM,QAAQ,IAAI,KAAK,CAExB,aAAY,IAAI,KAAK;IAEvB;;AAGJ,aAAY,aAAa;CAEzB,MAAM,SAAS,aAAa,UAAU,QAAQ,IAAI;AAClD,KAAI,CAAC,OACH,OAAM,IAAI,MACR,qHACD;AAGH,QAAO;EACL,GAAG;EACH,GAAG;EACH;EACA,cAAc,aAAa,gBAAgB;EAC3C,eAAe,aAAa,iBAAiB,EAAE;EAC/C,YAAY,aAAa,cAAc,EAAE;EACzC,mBACE,aAAa,qBAAqB,yBAAyB,OAAO;EACpE,aACE,aAAa,gBACZ,QAAQ,IAAI,aAAa,gBAAgB,gBAAgB;EAC5D,WAAW,aAAa,aAAa;EACrC,KAAK;GACH,GAAG,eAAe;GAClB,GAAG,aAAa;GACjB;EACD,mBAAmB;GACjB,GAAG,eAAe;GAClB,GAAG,aAAa;GAChB,QAAQ;IACN,GAAG,eAAe,kBAAkB;IACpC,GAAG,aAAa,mBAAmB;IACpC;GACF;EACF;;;;;;;AAQH,eAAsB,wBACpB,QACA,SAA0B,IAAI,gBAAgB,OAAO,OAAO,EAC7C;AACf,KAAI,OAAO,gBAAgB,OAAO,cAAc,SAAS,EACvD;CAEF,MAAM,WAAW,MAAM,OAAO,eAAe;AAC7C,QAAO,eAAe,SAAS;AAC/B,QAAO,gBAAgB,SAAS;AAChC,QAAO,aAAa,SAAS;AAC7B,QAAO,oBAAoB,yBACzB,OAAO,QACP,SAAS,kBACV"}
1
+ {"version":3,"file":"config-factory.mjs","names":[],"sources":["../../src/utils/config-factory.ts"],"sourcesContent":["/**\n * Config factory for creating LoaderConfig instances\n */\nimport \"dotenv/config\";\nimport type {\n WeglotConfig,\n WeglotInternalFields,\n PartialWeglotConfig,\n} from \"../types\";\nimport {\n DEFAULT_API_BASE_URL,\n WeglotApiClient,\n} from \"../translators/weglot/api-client\";\nimport { resolveTranslationEngine } from \"../translators/weglot/engine\";\n\n/**\n * Default configuration values\n */\nexport const DEFAULT_CONFIG = {\n sourceRoot: \"src\",\n weglotDir: \"weglot\",\n useDirective: false,\n translatableAttributes: {},\n dev: {\n translationServerStartPort: 60000,\n },\n localePersistence: {\n type: \"cookie\" as const,\n config: {\n name: \"locale\",\n maxAge: 31536000,\n },\n },\n buildMode: \"translate\",\n} satisfies Omit<\n WeglotConfig,\n // weglotDir is an internal field for public-config purposes, but (unlike\n // the other internal fields) it still has a static default here rather\n // than being resolved at runtime, so it stays out of this Omit.\n \"apiKey\" | \"translationTimeout\" | Exclude<WeglotInternalFields, \"weglotDir\">\n>;\n\n// Dev stays short: a server component waits on it, and the client gives up at 30s.\nconst DEFAULT_TRANSLATION_TIMEOUT = { production: 300, development: 10 };\n\nfunction timeoutFromEnv(): number | undefined {\n const raw = process.env.WEGLOT_TRANSLATION_TIMEOUT;\n if (!raw) return undefined;\n const value = Number(raw);\n return Number.isFinite(value) && value >= 0 ? value : undefined;\n}\n\n/**\n * Create a LoaderConfig with defaults applied\n *\n * @param options - Partial config to override defaults\n * @returns Complete LoaderConfig with all defaults applied\n *\n */\nexport function createWeglotConfig(\n options: PartialWeglotConfig & Partial<Pick<WeglotConfig, WeglotInternalFields>>,\n): WeglotConfig {\n const cleanOptions = { ...options };\n\n const cleanObject = (obj: any) => {\n if (!obj || typeof obj !== \"object\") return;\n Object.keys(obj).forEach((key) => {\n if (obj[key] === undefined) {\n delete obj[key];\n } else if (\n obj[key] &&\n typeof obj[key] === \"object\" &&\n !Array.isArray(obj[key])\n ) {\n cleanObject(obj[key]);\n }\n });\n };\n\n cleanObject(cleanOptions);\n\n const apiKey = cleanOptions.apiKey ?? process.env.WEGLOT_API_KEY;\n if (!apiKey) {\n throw new Error(\n \"Weglot project key is missing. Pass `apiKey` in the plugin options or set the WEGLOT_API_KEY environment variable.\",\n );\n }\n\n const environment =\n cleanOptions.environment ??\n (process.env.NODE_ENV === \"development\" ? \"development\" : \"production\");\n\n return {\n ...DEFAULT_CONFIG,\n ...cleanOptions,\n apiKey,\n sourceLocale: cleanOptions.sourceLocale ?? \"\",\n targetLocales: cleanOptions.targetLocales ?? [],\n apiLocales: cleanOptions.apiLocales ?? {},\n translationEngine: resolveTranslationEngine(cleanOptions.translationEngine),\n apiBaseUrl: cleanOptions.apiBaseUrl ?? \"\",\n translationTimeout:\n cleanOptions.translationTimeout ??\n timeoutFromEnv() ??\n DEFAULT_TRANSLATION_TIMEOUT[environment],\n environment,\n cacheType: cleanOptions.cacheType ?? \"local\",\n dev: {\n ...DEFAULT_CONFIG.dev,\n ...cleanOptions.dev,\n },\n localePersistence: {\n ...DEFAULT_CONFIG.localePersistence,\n ...cleanOptions.localePersistence,\n config: {\n ...DEFAULT_CONFIG.localePersistence.config,\n ...cleanOptions.localePersistence?.config,\n },\n },\n };\n}\n\n/**\n * Fetches source/target locales from the Weglot project settings.\n * Idempotent: no-ops when locales are already resolved (e.g. passed\n * through Next.js loader options).\n */\nexport async function resolveProjectLanguages(\n config: WeglotConfig,\n client: WeglotApiClient = new WeglotApiClient(config.apiKey),\n): Promise<void> {\n if (\n config.sourceLocale &&\n config.targetLocales.length > 0 &&\n config.apiBaseUrl\n ) {\n return;\n }\n const settings = await client.fetchSettings();\n config.sourceLocale = settings.sourceLocale;\n config.targetLocales = settings.targetLocales;\n config.apiLocales = settings.apiLocales;\n config.apiBaseUrl = settings.apiBaseUrl || DEFAULT_API_BASE_URL;\n config.translationEngine = resolveTranslationEngine(\n settings.translationEngine,\n );\n}\n"],"mappings":";;;;;;;;AAkBA,MAAa,iBAAiB;CAC5B,YAAY;CACZ,WAAW;CACX,cAAc;CACd,wBAAwB,EAAE;CAC1B,KAAK,EACH,4BAA4B,KAC7B;CACD,mBAAmB;EACjB,MAAM;EACN,QAAQ;GACN,MAAM;GACN,QAAQ;GACT;EACF;CACD,WAAW;CACZ;AASD,MAAM,8BAA8B;CAAE,YAAY;CAAK,aAAa;CAAI;AAExE,SAAS,iBAAqC;CAC5C,MAAM,MAAM,QAAQ,IAAI;AACxB,KAAI,CAAC,IAAK,QAAO;CACjB,MAAM,QAAQ,OAAO,IAAI;AACzB,QAAO,OAAO,SAAS,MAAM,IAAI,SAAS,IAAI,QAAQ;;;;;;;;;AAUxD,SAAgB,mBACd,SACc;CACd,MAAM,eAAe,EAAE,GAAG,SAAS;CAEnC,MAAM,eAAe,QAAa;AAChC,MAAI,CAAC,OAAO,OAAO,QAAQ,SAAU;AACrC,SAAO,KAAK,IAAI,CAAC,SAAS,QAAQ;AAChC,OAAI,IAAI,SAAS,OACf,QAAO,IAAI;YAEX,IAAI,QACJ,OAAO,IAAI,SAAS,YACpB,CAAC,MAAM,QAAQ,IAAI,KAAK,CAExB,aAAY,IAAI,KAAK;IAEvB;;AAGJ,aAAY,aAAa;CAEzB,MAAM,SAAS,aAAa,UAAU,QAAQ,IAAI;AAClD,KAAI,CAAC,OACH,OAAM,IAAI,MACR,qHACD;CAGH,MAAM,cACJ,aAAa,gBACZ,QAAQ,IAAI,aAAa,gBAAgB,gBAAgB;AAE5D,QAAO;EACL,GAAG;EACH,GAAG;EACH;EACA,cAAc,aAAa,gBAAgB;EAC3C,eAAe,aAAa,iBAAiB,EAAE;EAC/C,YAAY,aAAa,cAAc,EAAE;EACzC,mBAAmB,yBAAyB,aAAa,kBAAkB;EAC3E,YAAY,aAAa,cAAc;EACvC,oBACE,aAAa,sBACb,gBAAgB,IAChB,4BAA4B;EAC9B;EACA,WAAW,aAAa,aAAa;EACrC,KAAK;GACH,GAAG,eAAe;GAClB,GAAG,aAAa;GACjB;EACD,mBAAmB;GACjB,GAAG,eAAe;GAClB,GAAG,aAAa;GAChB,QAAQ;IACN,GAAG,eAAe,kBAAkB;IACpC,GAAG,aAAa,mBAAmB;IACpC;GACF;EACF;;;;;;;AAQH,eAAsB,wBACpB,QACA,SAA0B,IAAI,gBAAgB,OAAO,OAAO,EAC7C;AACf,KACE,OAAO,gBACP,OAAO,cAAc,SAAS,KAC9B,OAAO,WAEP;CAEF,MAAM,WAAW,MAAM,OAAO,eAAe;AAC7C,QAAO,eAAe,SAAS;AAC/B,QAAO,gBAAgB,SAAS;AAChC,QAAO,aAAa,SAAS;AAC7B,QAAO,aAAa,SAAS,cAAc;AAC3C,QAAO,oBAAoB,yBACzB,SAAS,kBACV"}
@@ -1,3 +1,4 @@
1
+ const require_api_client = require('../translators/weglot/api-client.cjs');
1
2
  const require_path_helpers = require('../utils/path-helpers.cjs');
2
3
 
3
4
  //#region src/virtual/code-generator.ts
@@ -13,6 +14,7 @@ export const cacheDir = ${JSON.stringify(cacheDir)};
13
14
  export const sourceLocale = ${JSON.stringify(config.sourceLocale)};
14
15
  export const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};
15
16
  export const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};
17
+ export const apiBaseUrl = ${JSON.stringify(config.apiBaseUrl || require_api_client.DEFAULT_API_BASE_URL)};
16
18
  `;
17
19
  }
18
20
  /**
@@ -1,3 +1,4 @@
1
+ import { DEFAULT_API_BASE_URL } from "../translators/weglot/api-client.mjs";
1
2
  import { getCacheDir } from "../utils/path-helpers.mjs";
2
3
 
3
4
  //#region src/virtual/code-generator.ts
@@ -13,6 +14,7 @@ export const cacheDir = ${JSON.stringify(cacheDir)};
13
14
  export const sourceLocale = ${JSON.stringify(config.sourceLocale)};
14
15
  export const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};
15
16
  export const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};
17
+ export const apiBaseUrl = ${JSON.stringify(config.apiBaseUrl || DEFAULT_API_BASE_URL)};
16
18
  `;
17
19
  }
18
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"code-generator.mjs","names":[],"sources":["../../src/virtual/code-generator.ts"],"sourcesContent":["/**\n * Shared code generation for virtual modules\n * Used by both unplugin (virtual modules) and Turbopack loaders\n *\n * This module provides FULL module generators, not just function bodies.\n * Both loaders and unplugin use these to generate complete modules.\n */\n\nimport type { WeglotConfig } from \"../types\";\nimport { getCacheDir } from \"../utils/path-helpers\";\n\n/**\n * Generate complete config module\n * Exports serverUrl and cacheDir constants\n */\nexport function generateConfigModule(config: WeglotConfig): string {\n const serverUrl = config.dev.translationServerUrl;\n const cacheDir = getCacheDir(config);\n\n return `export const serverUrl = ${JSON.stringify(serverUrl)};\nexport const cacheDir = ${JSON.stringify(cacheDir)};\nexport const sourceLocale = ${JSON.stringify(config.sourceLocale)};\nexport const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};\nexport const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};\n`;\n}\n\n/**\n * Generate complete locale/server module\n * Exports async getServerLocale() function\n */\nexport function generateServerLocaleModule(config: WeglotConfig): string {\n return `\nimport { createNextCookieLocaleResolver } from '@weglot/translate-react/react/next';\nexport const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });\n`;\n}\n\n/**\n * Generate complete locale/client module\n * Exports getClientLocale() and persistLocale() functions\n */\nexport function generateClientLocaleModule(config: WeglotConfig): string {\n const cookieName = config.localePersistence.config.name;\n const maxAge = config.localePersistence.config.maxAge;\n\n return `\nexport function getClientLocale() {\n if (typeof document !== 'undefined') {\n const match = document.cookie.match(/${cookieName}=([^;]+)/);\n if (match) return match[1];\n }\n // Fallback to source locale\n return ${JSON.stringify(config.sourceLocale)};\n}\n\nexport function persistLocale(locale) {\n if (typeof document !== 'undefined') {\n document.cookie = \\`${cookieName}=\\${locale}; path=/; max-age=${maxAge}\\`;\n }\n}\n`;\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,qBAAqB,QAA8B;CACjE,MAAM,YAAY,OAAO,IAAI;CAC7B,MAAM,WAAW,YAAY,OAAO;AAEpC,QAAO,4BAA4B,KAAK,UAAU,UAAU,CAAC;0BACrC,KAAK,UAAU,SAAS,CAAC;8BACrB,KAAK,UAAU,OAAO,aAAa,CAAC;4BACtC,KAAK,UAAU,OAAO,cAAc,EAAE,CAAC,CAAC;mCACjC,KAAK,UAAU,OAAO,qBAAqB,EAAE,CAAC;;;;;;;AAQjF,SAAgB,2BAA2B,QAA8B;AACvE,QAAO;;gFAEuE,KAAK,UAAU,OAAO,kBAAkB,OAAO,CAAC,mBAAmB,KAAK,UAAU,OAAO,aAAa,CAAC;;;;;;;AAQvL,SAAgB,2BAA2B,QAA8B;CACvE,MAAM,aAAa,OAAO,kBAAkB,OAAO;CACnD,MAAM,SAAS,OAAO,kBAAkB,OAAO;AAE/C,QAAO;;;2CAGkC,WAAW;;;;WAI3C,KAAK,UAAU,OAAO,aAAa,CAAC;;;;;0BAKrB,WAAW,+BAA+B,OAAO"}
1
+ {"version":3,"file":"code-generator.mjs","names":[],"sources":["../../src/virtual/code-generator.ts"],"sourcesContent":["/**\n * Shared code generation for virtual modules\n * Used by both unplugin (virtual modules) and Turbopack loaders\n *\n * This module provides FULL module generators, not just function bodies.\n * Both loaders and unplugin use these to generate complete modules.\n */\n\nimport type { WeglotConfig } from \"../types\";\nimport { getCacheDir } from \"../utils/path-helpers\";\nimport { DEFAULT_API_BASE_URL } from \"../translators/weglot/api-client\";\n\n/**\n * Generate complete config module\n * Exports serverUrl and cacheDir constants\n */\nexport function generateConfigModule(config: WeglotConfig): string {\n const serverUrl = config.dev.translationServerUrl;\n const cacheDir = getCacheDir(config);\n\n return `export const serverUrl = ${JSON.stringify(serverUrl)};\nexport const cacheDir = ${JSON.stringify(cacheDir)};\nexport const sourceLocale = ${JSON.stringify(config.sourceLocale)};\nexport const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};\nexport const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};\nexport const apiBaseUrl = ${JSON.stringify(config.apiBaseUrl || DEFAULT_API_BASE_URL)};\n`;\n}\n\n/**\n * Generate complete locale/server module\n * Exports async getServerLocale() function\n */\nexport function generateServerLocaleModule(config: WeglotConfig): string {\n return `\nimport { createNextCookieLocaleResolver } from '@weglot/translate-react/react/next';\nexport const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });\n`;\n}\n\n/**\n * Generate complete locale/client module\n * Exports getClientLocale() and persistLocale() functions\n */\nexport function generateClientLocaleModule(config: WeglotConfig): string {\n const cookieName = config.localePersistence.config.name;\n const maxAge = config.localePersistence.config.maxAge;\n\n return `\nexport function getClientLocale() {\n if (typeof document !== 'undefined') {\n const match = document.cookie.match(/${cookieName}=([^;]+)/);\n if (match) return match[1];\n }\n // Fallback to source locale\n return ${JSON.stringify(config.sourceLocale)};\n}\n\nexport function persistLocale(locale) {\n if (typeof document !== 'undefined') {\n document.cookie = \\`${cookieName}=\\${locale}; path=/; max-age=${maxAge}\\`;\n }\n}\n`;\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,qBAAqB,QAA8B;CACjE,MAAM,YAAY,OAAO,IAAI;CAC7B,MAAM,WAAW,YAAY,OAAO;AAEpC,QAAO,4BAA4B,KAAK,UAAU,UAAU,CAAC;0BACrC,KAAK,UAAU,SAAS,CAAC;8BACrB,KAAK,UAAU,OAAO,aAAa,CAAC;4BACtC,KAAK,UAAU,OAAO,cAAc,EAAE,CAAC,CAAC;mCACjC,KAAK,UAAU,OAAO,qBAAqB,EAAE,CAAC;4BACrD,KAAK,UAAU,OAAO,cAAc,qBAAqB,CAAC;;;;;;;AAQtF,SAAgB,2BAA2B,QAA8B;AACvE,QAAO;;gFAEuE,KAAK,UAAU,OAAO,kBAAkB,OAAO,CAAC,mBAAmB,KAAK,UAAU,OAAO,aAAa,CAAC;;;;;;;AAQvL,SAAgB,2BAA2B,QAA8B;CACvE,MAAM,aAAa,OAAO,kBAAkB,OAAO;CACnD,MAAM,SAAS,OAAO,kBAAkB,OAAO;AAE/C,QAAO;;;2CAGkC,WAAW;;;;WAI3C,KAAK,UAAU,OAAO,aAAa,CAAC;;;;;0BAKrB,WAAW,+BAA+B,OAAO"}
@@ -7,8 +7,11 @@ const sourceLocale = "__SOURCE_LOCALE__";
7
7
  const apiLocales = {};
8
8
  /** Which inline elements the project's engine permits inside a segment. */
9
9
  const translationEngine = 3;
10
+ /** The project's regional API host. */
11
+ const apiBaseUrl = "https://api.weglot.com";
10
12
 
11
13
  //#endregion
14
+ exports.apiBaseUrl = apiBaseUrl;
12
15
  exports.apiLocales = apiLocales;
13
16
  exports.cacheDir = cacheDir;
14
17
  exports.serverUrl = serverUrl;
@@ -8,6 +8,8 @@ declare const sourceLocale: LocaleCode;
8
8
  declare const apiLocales: Record<string, LocaleCode>;
9
9
  /** Which inline elements the project's engine permits inside a segment. */
10
10
  declare const translationEngine: number;
11
+ /** The project's regional API host. */
12
+ declare const apiBaseUrl: string;
11
13
  //#endregion
12
- export { apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
14
+ export { apiBaseUrl, apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
13
15
  //# sourceMappingURL=config.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.cts","names":[],"sources":["../../src/virtual/config.ts"],"sourcesContent":[],"mappings":";;;cAEa,SAAA;cACA,QAAA;AADA,cAEA,YAFS,EAE6B,UAF7B;AACtB;AACa,cAGA,UAHsC,EAG1B,MAH0B,CAAA,MAAU,EAGrB,UAHqB,CAAA;AAG7D;AAGa,cAAA,iBAA6B,EAAA,MAAA"}
1
+ {"version":3,"file":"config.d.cts","names":[],"sources":["../../src/virtual/config.ts"],"sourcesContent":[],"mappings":";;;cAEa,SAAA;cACA,QAAA;AADA,cAEA,YAFS,EAE6B,UAF7B;AACtB;AACa,cAGA,UAHsC,EAG1B,MAH0B,CAAA,MAAU,EAGrB,UAHqB,CAAA;AAG7D;AAGa,cAAA,iBAA6B,EAAA,MAAA;AAG1C;cAAa"}
@@ -8,6 +8,8 @@ declare const sourceLocale: LocaleCode;
8
8
  declare const apiLocales: Record<string, LocaleCode>;
9
9
  /** Which inline elements the project's engine permits inside a segment. */
10
10
  declare const translationEngine: number;
11
+ /** The project's regional API host. */
12
+ declare const apiBaseUrl: string;
11
13
  //#endregion
12
- export { apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
14
+ export { apiBaseUrl, apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
13
15
  //# sourceMappingURL=config.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","names":[],"sources":["../../src/virtual/config.ts"],"sourcesContent":[],"mappings":";;;cAEa,SAAA;cACA,QAAA;AADA,cAEA,YAFS,EAE6B,UAF7B;AACtB;AACa,cAGA,UAHsC,EAG1B,MAH0B,CAAA,MAAU,EAGrB,UAHqB,CAAA;AAG7D;AAGa,cAAA,iBAA6B,EAAA,MAAA"}
1
+ {"version":3,"file":"config.d.mts","names":[],"sources":["../../src/virtual/config.ts"],"sourcesContent":[],"mappings":";;;cAEa,SAAA;cACA,QAAA;AADA,cAEA,YAFS,EAE6B,UAF7B;AACtB;AACa,cAGA,UAHsC,EAG1B,MAH0B,CAAA,MAAU,EAGrB,UAHqB,CAAA;AAG7D;AAGa,cAAA,iBAA6B,EAAA,MAAA;AAG1C;cAAa"}
@@ -6,7 +6,9 @@ const sourceLocale = "__SOURCE_LOCALE__";
6
6
  const apiLocales = {};
7
7
  /** Which inline elements the project's engine permits inside a segment. */
8
8
  const translationEngine = 3;
9
+ /** The project's regional API host. */
10
+ const apiBaseUrl = "https://api.weglot.com";
9
11
 
10
12
  //#endregion
11
- export { apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
13
+ export { apiBaseUrl, apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
12
14
  //# sourceMappingURL=config.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","names":["apiLocales: Record<string, LocaleCode>","translationEngine: number"],"sources":["../../src/virtual/config.ts"],"sourcesContent":["import type { LocaleCode } from \"../locale\";\n\nexport const serverUrl = \"__SERVER_URL__\";\nexport const cacheDir = \"__CACHE_DIR__\";\nexport const sourceLocale = \"__SOURCE_LOCALE__\" as LocaleCode;\n\n/** Public locale to the language code the translate API expects. */\nexport const apiLocales: Record<string, LocaleCode> = {};\n\n/** Which inline elements the project's engine permits inside a segment. */\nexport const translationEngine: number = 3;\n"],"mappings":";AAEA,MAAa,YAAY;AACzB,MAAa,WAAW;AACxB,MAAa,eAAe;;AAG5B,MAAaA,aAAyC,EAAE;;AAGxD,MAAaC,oBAA4B"}
1
+ {"version":3,"file":"config.mjs","names":["apiLocales: Record<string, LocaleCode>","translationEngine: number","apiBaseUrl: string"],"sources":["../../src/virtual/config.ts"],"sourcesContent":["import type { LocaleCode } from \"../locale\";\n\nexport const serverUrl = \"__SERVER_URL__\";\nexport const cacheDir = \"__CACHE_DIR__\";\nexport const sourceLocale = \"__SOURCE_LOCALE__\" as LocaleCode;\n\n/** Public locale to the language code the translate API expects. */\nexport const apiLocales: Record<string, LocaleCode> = {};\n\n/** Which inline elements the project's engine permits inside a segment. */\nexport const translationEngine: number = 3;\n\n/** The project's regional API host. */\nexport const apiBaseUrl: string = \"https://api.weglot.com\";\n"],"mappings":";AAEA,MAAa,YAAY;AACzB,MAAa,WAAW;AACxB,MAAa,eAAe;;AAG5B,MAAaA,aAAyC,EAAE;;AAGxD,MAAaC,oBAA4B;;AAGzC,MAAaC,aAAqB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weglot/translate-react",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Automatic Weglot translation for React and Next.js apps, detected from your JSX at build time",
5
5
  "sideEffects": false,
6
6
  "type": "module",