langie 1.9.26 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * langie v1.9.26
2
+ * langie v1.10.0
3
3
  * (c) 2026 nlit
4
4
  * @license Apache-2.0
5
5
  *
@@ -983,6 +983,7 @@ var API_FIELD_TO = "to";
983
983
  var API_FIELD_CTX = "ctx";
984
984
  var API_FIELD_TRANSLATIONS = "translations";
985
985
  var API_FIELD_ERROR = "error";
986
+ var API_FIELD_TURNSTILE = "turnstileToken";
986
987
 
987
988
  // src/utils/debug.ts
988
989
  var import_meta = {};
@@ -1560,21 +1561,29 @@ var TranslationBatching = class {
1560
1561
  "items",
1561
1562
  batchRequests
1562
1563
  );
1563
- const response = await fetch(`${this.translatorHost}/translate`, {
1564
+ const buildBody = (turnstileToken) => JSON.stringify({
1565
+ translations: batchRequests.map((req) => ({
1566
+ [API_FIELD_TEXT]: req[API_FIELD_TEXT],
1567
+ ...useGlobalContext ? {} : { [API_FIELD_CTX]: req[API_FIELD_CTX] }
1568
+ })),
1569
+ [API_FIELD_FROM]: from,
1570
+ [API_FIELD_TO]: to,
1571
+ ...useGlobalContext ? { [API_FIELD_CTX]: "ui" } : {},
1572
+ ...turnstileToken ? { [API_FIELD_TURNSTILE]: turnstileToken } : {}
1573
+ });
1574
+ const postTranslate = (turnstileToken) => fetch(`${this.translatorHost}/translate`, {
1564
1575
  method: "POST",
1565
- headers: {
1566
- "Content-Type": "application/json"
1567
- },
1568
- body: JSON.stringify({
1569
- translations: batchRequests.map((req) => ({
1570
- [API_FIELD_TEXT]: req[API_FIELD_TEXT],
1571
- ...useGlobalContext ? {} : { [API_FIELD_CTX]: req[API_FIELD_CTX] }
1572
- })),
1573
- [API_FIELD_FROM]: from,
1574
- [API_FIELD_TO]: to,
1575
- ...useGlobalContext ? { [API_FIELD_CTX]: "ui" } : {}
1576
- })
1576
+ // Carry the /frontend session cookie the proxy issues after one
1577
+ // Turnstile check, so we don't solve a challenge on every request.
1578
+ credentials: "include",
1579
+ headers: { "Content-Type": "application/json" },
1580
+ body: buildBody(turnstileToken)
1577
1581
  });
1582
+ let response = await postTranslate();
1583
+ if ((response.status === 401 || response.status === 400) && this.options.getTurnstileToken) {
1584
+ const turnstileToken = await this.options.getTurnstileToken();
1585
+ response = await postTranslate(turnstileToken);
1586
+ }
1578
1587
  let result;
1579
1588
  try {
1580
1589
  result = await response.json();
@@ -1764,7 +1773,8 @@ function createLangieInstance(options = {}) {
1764
1773
  initialBatchDelay: options.initialBatchDelay,
1765
1774
  followupBatchDelay: options.followupBatchDelay,
1766
1775
  maxBatchSize: options.maxBatchSize,
1767
- maxWaitTime: options.maxWaitTime
1776
+ maxWaitTime: options.maxWaitTime,
1777
+ getTurnstileToken: options.getTurnstileToken
1768
1778
  },
1769
1779
  translatorHost,
1770
1780
  () => currentLanguage2.value,
@@ -1826,7 +1836,7 @@ function createLangieInstance(options = {}) {
1826
1836
  return;
1827
1837
  }
1828
1838
  const effectiveCtx = originalCtx;
1829
- const cacheKey = `${originalText}|${effectiveCtx}`;
1839
+ const cacheKey = request.cacheKey || `${originalText}|${effectiveCtx}`;
1830
1840
  const cache = effectiveCtx === "ui" ? uiTranslations2 : translations2;
1831
1841
  cache[cacheKey] = translatedText;
1832
1842
  devDebug("[useLangie] Cached translation:", {
@@ -1854,7 +1864,8 @@ function createLangieInstance(options = {}) {
1854
1864
  return text;
1855
1865
  }
1856
1866
  const effectiveCtx = ctx !== void 0 ? ctx : ltDefaults.ctx || "ui";
1857
- const cacheKey = `${text}|${effectiveCtx}`;
1867
+ const baseKey = `${text}|${effectiveCtx}`;
1868
+ const cacheKey = to !== currentLanguage2.value ? `${baseKey}|${from}|${to}` : baseKey;
1858
1869
  const cache = effectiveCtx === "ui" ? uiTranslations2 : translations2;
1859
1870
  if (cache[cacheKey]) {
1860
1871
  return cache[cacheKey];
@@ -1863,7 +1874,7 @@ function createLangieInstance(options = {}) {
1863
1874
  if (translationErrors.has(errorKey)) {
1864
1875
  return text;
1865
1876
  }
1866
- const languageCacheKey = `${cacheKey}|${from}|${to}`;
1877
+ const languageCacheKey = `${baseKey}|${from}|${to}`;
1867
1878
  if (recentlyQueued.has(languageCacheKey)) {
1868
1879
  return text;
1869
1880
  }