langie 1.9.26 → 1.10.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * langie v1.9.26
2
+ * langie v1.10.1
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 = {};
@@ -1257,8 +1258,7 @@ function useLangieCore(options = {}) {
1257
1258
  const cachedLanguages = getCache("langie_languages_cache");
1258
1259
  if (cachedLanguages && availableLanguages.value.length === 0) {
1259
1260
  availableLanguages.value = cachedLanguages;
1260
- _languagesCache = cachedLanguages;
1261
- devDebug("[useLangie] Loaded languages from cache:", cachedLanguages.length);
1261
+ devDebug("[useLangie] Seeded languages from cache (will revalidate):", cachedLanguages.length);
1262
1262
  } else if (cachedLanguages) {
1263
1263
  devDebug(
1264
1264
  "[useLangie] Cache exists but languages already loaded:",
@@ -1560,21 +1560,29 @@ var TranslationBatching = class {
1560
1560
  "items",
1561
1561
  batchRequests
1562
1562
  );
1563
- const response = await fetch(`${this.translatorHost}/translate`, {
1563
+ const buildBody = (turnstileToken) => JSON.stringify({
1564
+ translations: batchRequests.map((req) => ({
1565
+ [API_FIELD_TEXT]: req[API_FIELD_TEXT],
1566
+ ...useGlobalContext ? {} : { [API_FIELD_CTX]: req[API_FIELD_CTX] }
1567
+ })),
1568
+ [API_FIELD_FROM]: from,
1569
+ [API_FIELD_TO]: to,
1570
+ ...useGlobalContext ? { [API_FIELD_CTX]: "ui" } : {},
1571
+ ...turnstileToken ? { [API_FIELD_TURNSTILE]: turnstileToken } : {}
1572
+ });
1573
+ const postTranslate = (turnstileToken) => fetch(`${this.translatorHost}/translate`, {
1564
1574
  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
- })
1575
+ // Carry the /frontend session cookie the proxy issues after one
1576
+ // Turnstile check, so we don't solve a challenge on every request.
1577
+ credentials: "include",
1578
+ headers: { "Content-Type": "application/json" },
1579
+ body: buildBody(turnstileToken)
1577
1580
  });
1581
+ let response = await postTranslate();
1582
+ if ((response.status === 401 || response.status === 400) && this.options.getTurnstileToken) {
1583
+ const turnstileToken = await this.options.getTurnstileToken();
1584
+ response = await postTranslate(turnstileToken);
1585
+ }
1578
1586
  let result;
1579
1587
  try {
1580
1588
  result = await response.json();
@@ -1764,7 +1772,8 @@ function createLangieInstance(options = {}) {
1764
1772
  initialBatchDelay: options.initialBatchDelay,
1765
1773
  followupBatchDelay: options.followupBatchDelay,
1766
1774
  maxBatchSize: options.maxBatchSize,
1767
- maxWaitTime: options.maxWaitTime
1775
+ maxWaitTime: options.maxWaitTime,
1776
+ getTurnstileToken: options.getTurnstileToken
1768
1777
  },
1769
1778
  translatorHost,
1770
1779
  () => currentLanguage2.value,
@@ -1826,7 +1835,7 @@ function createLangieInstance(options = {}) {
1826
1835
  return;
1827
1836
  }
1828
1837
  const effectiveCtx = originalCtx;
1829
- const cacheKey = `${originalText}|${effectiveCtx}`;
1838
+ const cacheKey = request.cacheKey || `${originalText}|${effectiveCtx}`;
1830
1839
  const cache = effectiveCtx === "ui" ? uiTranslations2 : translations2;
1831
1840
  cache[cacheKey] = translatedText;
1832
1841
  devDebug("[useLangie] Cached translation:", {
@@ -1854,7 +1863,8 @@ function createLangieInstance(options = {}) {
1854
1863
  return text;
1855
1864
  }
1856
1865
  const effectiveCtx = ctx !== void 0 ? ctx : ltDefaults.ctx || "ui";
1857
- const cacheKey = `${text}|${effectiveCtx}`;
1866
+ const baseKey = `${text}|${effectiveCtx}`;
1867
+ const cacheKey = to !== currentLanguage2.value ? `${baseKey}|${from}|${to}` : baseKey;
1858
1868
  const cache = effectiveCtx === "ui" ? uiTranslations2 : translations2;
1859
1869
  if (cache[cacheKey]) {
1860
1870
  return cache[cacheKey];
@@ -1863,7 +1873,7 @@ function createLangieInstance(options = {}) {
1863
1873
  if (translationErrors.has(errorKey)) {
1864
1874
  return text;
1865
1875
  }
1866
- const languageCacheKey = `${cacheKey}|${from}|${to}`;
1876
+ const languageCacheKey = `${baseKey}|${from}|${to}`;
1867
1877
  if (recentlyQueued.has(languageCacheKey)) {
1868
1878
  return text;
1869
1879
  }