gt-i18n 1.0.1 → 1.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # gt-i18n
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1861](https://github.com/generaltranslation/gt/pull/1861) [`6345dc5`](https://github.com/generaltranslation/gt/commit/6345dc5e3fe0a1e3ead9a3c30a0adaa4037d50a8) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Skip interpolation in compiler-injected string prefetch calls so dev hot reload no longer logs "String interpolation failed" for messages with placeholders
8
+
9
+ ## 1.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1858](https://github.com/generaltranslation/gt/pull/1858) [`006e071`](https://github.com/generaltranslation/gt/commit/006e071bf87ffe80f2d18958ddfa8f18cc2d85d2) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Accept parsed `gt.config.json` objects in the compiler and React SPA configuration types.
14
+
15
+ - [#1846](https://github.com/generaltranslation/gt/pull/1846) [`7fb4a74`](https://github.com/generaltranslation/gt/commit/7fb4a74c52065694a40deafcf4596acc09e17f58) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add `parseLocale(request)` to resolve server-rendered React locales from the configured cookie, the `Accept-Language` header, or the default locale.
16
+
17
+ Share cookie and `Accept-Language` parsing across the framework packages.
18
+
19
+ - [#1848](https://github.com/generaltranslation/gt/pull/1848) [`1f33d5f`](https://github.com/generaltranslation/gt/commit/1f33d5f76ffc879d2d21aa2508e07e1d3b66c4e3) Thanks [@bgub](https://github.com/bgub)! - Remove unused dependencies: `@generaltranslation/supported-locales` from gt-react, gt-next, gt-i18n, and @generaltranslation/react-core, and `@generaltranslation/format` from gt-react. Nothing in these packages imports them, so this only reduces install weight.
20
+
3
21
  ## 1.0.1
4
22
 
5
23
  ### Patch Changes
@@ -40,6 +40,7 @@ type GTConfig = {
40
40
  _disableDevHotReload?: boolean;
41
41
  files?: {
42
42
  gt?: {
43
+ output?: string;
43
44
  parsingFlags?: {
44
45
  /**
45
46
  * Dev hot reload config, gt-react browser runtime only.
@@ -237,4 +238,4 @@ declare class WritableConditionStore extends ReadonlyConditionStore implements W
237
238
  type Locale = string;
238
239
  //#endregion
239
240
  export { TranslationsLoader as _, ReadonlyConditionStoreParams as a, LocaleCandidates as c, I18nCacheConfig as d, I18nCacheConstructorParams as f, WritableConditionStoreInterface as g, ScopedConditionStoreInterface as h, ReadonlyConditionStore as i, AsyncReadonlyConditionStoreInterface as l, ReadonlyConditionStoreInterface as m, WritableConditionStore as n, I18nConfig as o, LocaleResolverConfig as p, WritableConditionStoreParams as r, I18nConfigParams as s, Locale as t, DictionaryConfig as u, Hash as v, GTConfig as y };
240
- //# sourceMappingURL=LocalesCache-6hJpulfR.d.cts.map
241
+ //# sourceMappingURL=LocalesCache-BrqsSW3K.d.cts.map
@@ -39,6 +39,7 @@ type GTConfig = {
39
39
  _disableDevHotReload?: boolean;
40
40
  files?: {
41
41
  gt?: {
42
+ output?: string;
42
43
  parsingFlags?: {
43
44
  /**
44
45
  * Dev hot reload config, gt-react browser runtime only.
@@ -236,4 +237,4 @@ declare class WritableConditionStore extends ReadonlyConditionStore implements W
236
237
  type Locale = string;
237
238
  //#endregion
238
239
  export { TranslationsLoader as _, ReadonlyConditionStoreParams as a, LocaleCandidates as c, I18nCacheConfig as d, I18nCacheConstructorParams as f, WritableConditionStoreInterface as g, ScopedConditionStoreInterface as h, ReadonlyConditionStore as i, AsyncReadonlyConditionStoreInterface as l, ReadonlyConditionStoreInterface as m, WritableConditionStore as n, I18nConfig as o, LocaleResolverConfig as p, WritableConditionStoreParams as r, I18nConfigParams as s, Locale as t, DictionaryConfig as u, Hash as v, GTConfig as y };
239
- //# sourceMappingURL=LocalesCache-CO3aKdqI.d.mts.map
240
+ //# sourceMappingURL=LocalesCache-Cgg8OjSV.d.mts.map
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_versionId = require("./versionId-CSjMQCR_.cjs");
2
+ const require_versionId = require("./versionId-Bm1R4Gnm.cjs");
3
3
  let generaltranslation_internal = require("generaltranslation/internal");
4
4
  let _generaltranslation_format = require("@generaltranslation/format");
5
5
  let generaltranslation = require("generaltranslation");
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { E as logger_default, a as getDefaultLocale, b as createInterpolationFailureMessage, c as getLocales, d as getWritableConditionStore, g as resolveStringContentWithFallback, h as resolveStringContent, i as hashMessage, l as getRegion, n as isEncodedTranslationOptions, o as getLocale, r as decodeOptions, s as getLocaleProperties, t as getVersionId, u as resolveCanonicalLocale, x as extractVariables, y as interpolateIcuMessage } from "./versionId-CfPcJY78.mjs";
1
+ import { D as logger_default, S as extractVariables, _ as resolveStringContentWithFallback, a as getDefaultLocale, b as interpolateIcuMessage, c as getLocales, d as getWritableConditionStore, g as resolveStringContent, i as hashMessage, l as getRegion, n as isEncodedTranslationOptions, o as getLocale, r as decodeOptions, s as getLocaleProperties, t as getVersionId, u as resolveCanonicalLocale, x as createInterpolationFailureMessage } from "./versionId-BMLrkyzj.mjs";
2
2
  import { VAR_IDENTIFIER, encode, libraryDefaultLocale } from "generaltranslation/internal";
3
3
  import { formatMessage } from "@generaltranslation/format";
4
4
  import { declareVar, decodeVars, derive } from "generaltranslation";
@@ -1,4 +1,4 @@
1
1
  import { a as JsxTranslationOptions, c as NormalizedLookupOptions, d as TranslationOptions, f as TranslationVariables, i as GTTranslationOptions, l as RuntimeTranslationOptions, n as DictionaryLookupOptions, o as LookupOptions, r as EncodedTranslationOptions, s as LookupOptionsFor, t as DictionaryEntryOptions, u as TranslationMetadata } from "./options-BXeFwN0R.cjs";
2
- import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-6hJpulfR.cjs";
2
+ import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-BrqsSW3K.cjs";
3
3
  import { a as DictionaryLeaf, c as DictionaryValue, i as DictionaryKey, n as Dictionary, o as DictionaryObject, r as DictionaryEntry, s as DictionaryPath, t as DictionaryLoader } from "./DictionaryCache-DjAdDNiM.cjs";
4
4
  export { type AsyncReadonlyConditionStoreInterface, type Dictionary, type DictionaryConfig, type DictionaryEntry, DictionaryEntryOptions, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryPath, type DictionaryValue, EncodedTranslationOptions, type GTConfig, GTTranslationOptions, type Hash, type I18nCacheConfig, type I18nCacheConstructorParams, type I18nConfigParams, JsxTranslationOptions, type Locale, type LocaleCandidates, type LocaleResolverConfig, LookupOptions, LookupOptionsFor, NormalizedLookupOptions, type ReadonlyConditionStoreInterface, type ReadonlyConditionStoreParams, RuntimeTranslationOptions, type ScopedConditionStoreInterface, TranslationMetadata, TranslationOptions, TranslationVariables, type TranslationsLoader, type WritableConditionStoreInterface, type WritableConditionStoreParams };
@@ -1,4 +1,4 @@
1
1
  import { a as JsxTranslationOptions, c as NormalizedLookupOptions, d as TranslationOptions, f as TranslationVariables, i as GTTranslationOptions, l as RuntimeTranslationOptions, n as DictionaryLookupOptions, o as LookupOptions, r as EncodedTranslationOptions, s as LookupOptionsFor, t as DictionaryEntryOptions, u as TranslationMetadata } from "./options-DDUyXaLT.mjs";
2
- import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-CO3aKdqI.mjs";
2
+ import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-Cgg8OjSV.mjs";
3
3
  import { a as DictionaryLeaf, c as DictionaryValue, i as DictionaryKey, n as Dictionary, o as DictionaryObject, r as DictionaryEntry, s as DictionaryPath, t as DictionaryLoader } from "./DictionaryCache-B7oTBs5W.mjs";
4
4
  export { type AsyncReadonlyConditionStoreInterface, type Dictionary, type DictionaryConfig, type DictionaryEntry, DictionaryEntryOptions, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryPath, type DictionaryValue, EncodedTranslationOptions, type GTConfig, GTTranslationOptions, type Hash, type I18nCacheConfig, type I18nCacheConstructorParams, type I18nConfigParams, JsxTranslationOptions, type Locale, type LocaleCandidates, type LocaleResolverConfig, LookupOptions, LookupOptionsFor, NormalizedLookupOptions, type ReadonlyConditionStoreInterface, type ReadonlyConditionStoreParams, RuntimeTranslationOptions, type ScopedConditionStoreInterface, TranslationMetadata, TranslationOptions, TranslationVariables, type TranslationsLoader, type WritableConditionStoreInterface, type WritableConditionStoreParams };
package/dist/internal.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_versionId = require("./versionId-CSjMQCR_.cjs");
2
+ const require_versionId = require("./versionId-Bm1R4Gnm.cjs");
3
3
  let generaltranslation_internal = require("generaltranslation/internal");
4
4
  let _generaltranslation_format = require("@generaltranslation/format");
5
5
  //#region src/translation-functions/internal/getGT.ts
@@ -382,15 +382,39 @@ async function tx(content, options = {}) {
382
382
  * Condition store agnostic tx function
383
383
  */
384
384
  async function txInternal({ locale, enableI18n, content, options }) {
385
- return require_versionId.resolveStringContentWithRuntimeFallback(enableI18n ? typeof options.$locale === "string" ? options.$locale : locale : require_versionId.getI18nConfig().getDefaultLocale(), content, {
385
+ return require_versionId.resolveStringContentWithRuntimeFallback(getTargetLocale({
386
+ locale,
387
+ enableI18n,
388
+ options
389
+ }), content, {
390
+ $format: "STRING",
391
+ ...options
392
+ });
393
+ }
394
+ /**
395
+ * Registers a message for runtime translation without interpolating the
396
+ * result. For compiler-injected prefetch calls: their return value is
397
+ * discarded and variable values only exist at the render-time call site, so
398
+ * interpolating here would fail for any message with placeholders.
399
+ */
400
+ async function txPrefetch(content, options = {}) {
401
+ const conditionStore = require_versionId.getWritableConditionStore();
402
+ await require_versionId.prefetchStringContentWithRuntimeFallback(getTargetLocale({
403
+ locale: conditionStore.getLocale(),
404
+ enableI18n: conditionStore.getEnableI18n(),
405
+ options
406
+ }), content, {
386
407
  $format: "STRING",
387
408
  ...options
388
409
  });
389
410
  }
411
+ function getTargetLocale({ locale, enableI18n, options }) {
412
+ return enableI18n ? typeof options.$locale === "string" ? options.$locale : locale : require_versionId.getI18nConfig().getDefaultLocale();
413
+ }
390
414
  //#endregion
391
415
  //#region src/translation-functions/internal/runtime-translate.ts
392
416
  const GtInternalRuntimeTranslateString = (content, options = {}) => {
393
- return tx(content, {
417
+ return txPrefetch(content, {
394
418
  $format: "ICU",
395
419
  ...options
396
420
  });
@@ -1463,6 +1487,36 @@ function getDictionaryListenerKey({ locale, id }) {
1463
1487
  return `${locale}:${id}`;
1464
1488
  }
1465
1489
  //#endregion
1490
+ //#region src/utils/request.ts
1491
+ /**
1492
+ * Parse an Accept-Language header into locale candidates by preference.
1493
+ */
1494
+ function parseAcceptLanguage(header) {
1495
+ return (Array.isArray(header) ? header : [header]).flatMap((value) => value?.split(",") ?? []).map((entry, index) => {
1496
+ const [locale = "", ...parameters] = entry.split(";").map((value) => value.trim());
1497
+ const qualityParameter = parameters.find((parameter) => parameter.toLowerCase().startsWith("q="));
1498
+ return {
1499
+ locale,
1500
+ quality: Number(qualityParameter?.slice(2) ?? 1),
1501
+ index
1502
+ };
1503
+ }).filter(({ locale, quality }) => locale !== "" && locale !== "*" && quality > 0 && quality <= 1).sort((a, b) => b.quality - a.quality || a.index - b.index).map(({ locale }) => locale);
1504
+ }
1505
+ /**
1506
+ * Read and decode a value from a Cookie header or document.cookie string.
1507
+ */
1508
+ function getCookieValue(cookieHeader, cookieName) {
1509
+ const prefix = `${cookieName}=`;
1510
+ const cookie = cookieHeader?.split(";").map((value) => value.trim()).find((value) => value.startsWith(prefix));
1511
+ if (!cookie) return void 0;
1512
+ const value = cookie.slice(prefix.length);
1513
+ try {
1514
+ return decodeURIComponent(value);
1515
+ } catch {
1516
+ return value;
1517
+ }
1518
+ }
1519
+ //#endregion
1466
1520
  exports.GtInternalRuntimeTranslateJsx = GtInternalRuntimeTranslateJsx;
1467
1521
  exports.GtInternalRuntimeTranslateString = GtInternalRuntimeTranslateString;
1468
1522
  exports.I18nCache = I18nCache;
@@ -1473,6 +1527,7 @@ exports.createConditionStoreSingleton = require_versionId.createConditionStoreSi
1473
1527
  exports.createGlobalSingleton = require_versionId.createGlobalSingleton;
1474
1528
  exports.createLookupOptions = require_versionId.createLookupOptions;
1475
1529
  exports.extractVariables = require_versionId.extractVariables;
1530
+ exports.getCookieValue = getCookieValue;
1476
1531
  exports.getDictionaryEntry = getDictionaryEntry;
1477
1532
  exports.getDictionaryListenerKey = getDictionaryListenerKey;
1478
1533
  exports.getDictionaryValue = getDictionaryValue;
@@ -1492,6 +1547,7 @@ exports.initializeI18nConfig = require_versionId.initializeI18nConfig;
1492
1547
  exports.interpolateMessage = require_versionId.interpolateMessage;
1493
1548
  exports.isDictionaryValue = isDictionaryValue;
1494
1549
  exports.isEncodedTranslationOptions = require_versionId.isEncodedTranslationOptions;
1550
+ exports.parseAcceptLanguage = parseAcceptLanguage;
1495
1551
  exports.renderDictionaryEntry = renderDictionaryEntry;
1496
1552
  exports.renderDictionaryObject = renderDictionaryObject;
1497
1553
  exports.resolveDictionaryLookupOptions = resolveDictionaryLookupOptions;