@generaltranslation/react-core 12.0.0-samsara.0 → 12.0.0-samsara.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 (83) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/context/InternalGTProvider.cjs.map +1 -1
  3. package/dist/context/InternalGTProvider.d.ts +3 -2
  4. package/dist/context/InternalGTProvider.d.ts.map +1 -1
  5. package/dist/context/InternalGTProvider.mjs.map +1 -1
  6. package/dist/context/context.cjs.map +1 -1
  7. package/dist/context/context.mjs.map +1 -1
  8. package/dist/functions/helpers/getTranslationsSnapshot.cjs.map +1 -1
  9. package/dist/functions/helpers/getTranslationsSnapshot.d.ts +2 -2
  10. package/dist/functions/helpers/getTranslationsSnapshot.d.ts.map +1 -1
  11. package/dist/functions/helpers/getTranslationsSnapshot.mjs.map +1 -1
  12. package/dist/functions/translation/t.cjs.map +1 -1
  13. package/dist/functions/translation/t.d.ts.map +1 -1
  14. package/dist/functions/translation/t.mjs.map +1 -1
  15. package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs +1 -1
  16. package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs.map +1 -1
  17. package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs +1 -1
  18. package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs.map +1 -1
  19. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs +1 -1
  20. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs.map +1 -1
  21. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs +1 -1
  22. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs.map +1 -1
  23. package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs +1 -1
  24. package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs.map +1 -1
  25. package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs +1 -1
  26. package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs.map +1 -1
  27. package/dist/hooks/external-store/useTrackedTranslationResolver.cjs +1 -1
  28. package/dist/hooks/external-store/useTrackedTranslationResolver.cjs.map +1 -1
  29. package/dist/hooks/external-store/useTrackedTranslationResolver.d.ts +1 -1
  30. package/dist/hooks/external-store/useTrackedTranslationResolver.mjs +1 -1
  31. package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
  32. package/dist/hooks/external-store.cjs.map +1 -1
  33. package/dist/hooks/external-store.mjs.map +1 -1
  34. package/dist/hooks/useTranslations.cjs +1 -1
  35. package/dist/hooks/useTranslations.cjs.map +1 -1
  36. package/dist/hooks/useTranslations.d.ts.map +1 -1
  37. package/dist/hooks/useTranslations.mjs +1 -1
  38. package/dist/hooks/useTranslations.mjs.map +1 -1
  39. package/dist/hooks/utils/missing-translation.cjs +1 -1
  40. package/dist/hooks/utils/missing-translation.cjs.map +1 -1
  41. package/dist/hooks/utils/missing-translation.d.ts +2 -2
  42. package/dist/hooks/utils/missing-translation.d.ts.map +1 -1
  43. package/dist/hooks/utils/missing-translation.mjs +1 -1
  44. package/dist/hooks/utils/missing-translation.mjs.map +1 -1
  45. package/dist/i18n-cache/ReactI18nCache.cjs.map +1 -1
  46. package/dist/i18n-cache/ReactI18nCache.d.ts +2 -2
  47. package/dist/i18n-cache/ReactI18nCache.d.ts.map +1 -1
  48. package/dist/i18n-cache/ReactI18nCache.mjs.map +1 -1
  49. package/dist/i18n-cache/singleton-operations.cjs.map +1 -1
  50. package/dist/i18n-cache/singleton-operations.mjs.map +1 -1
  51. package/dist/i18n-store/I18nStore.cjs.map +1 -1
  52. package/dist/i18n-store/I18nStore.d.ts +6 -5
  53. package/dist/i18n-store/I18nStore.d.ts.map +1 -1
  54. package/dist/i18n-store/I18nStore.mjs.map +1 -1
  55. package/dist/i18n-store/storeTypes.d.ts +4 -3
  56. package/dist/i18n-store/storeTypes.d.ts.map +1 -1
  57. package/dist/i18n-store/useI18nStore.cjs.map +1 -1
  58. package/dist/i18n-store/useI18nStore.mjs.map +1 -1
  59. package/dist/i18n-store/utils/translations.cjs.map +1 -1
  60. package/dist/i18n-store/utils/translations.mjs.map +1 -1
  61. package/dist/unstable/t.cjs +2 -0
  62. package/dist/unstable/t.cjs.map +1 -0
  63. package/dist/unstable/t.d.ts +16 -0
  64. package/dist/unstable/t.d.ts.map +1 -0
  65. package/dist/unstable/t.mjs +2 -0
  66. package/dist/unstable/t.mjs.map +1 -0
  67. package/dist/unstable/useGT.cjs +2 -0
  68. package/dist/unstable/useGT.cjs.map +1 -0
  69. package/dist/unstable/useGT.d.ts +17 -0
  70. package/dist/unstable/useGT.d.ts.map +1 -0
  71. package/dist/unstable/useGT.mjs +2 -0
  72. package/dist/unstable/useGT.mjs.map +1 -0
  73. package/dist/unstable/useMessages.cjs +2 -0
  74. package/dist/unstable/useMessages.cjs.map +1 -0
  75. package/dist/unstable/useMessages.d.ts +16 -0
  76. package/dist/unstable/useMessages.d.ts.map +1 -0
  77. package/dist/unstable/useMessages.mjs +2 -0
  78. package/dist/unstable/useMessages.mjs.map +1 -0
  79. package/dist/unstable.cjs +1 -0
  80. package/dist/unstable.d.mts +1 -0
  81. package/dist/unstable.d.ts +5 -0
  82. package/dist/unstable.mjs +1 -0
  83. package/package.json +14 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @generaltranslation/react-core
2
2
 
3
+ ## 12.0.0-samsara.1
4
+
5
+ ### Minor Changes
6
+
7
+ - c5275b4: Add experimental opt-in `/unstable` entries for tagged-template message trees from `gt-i18n/unstable`. Each entry exports the `plural`, `selectordinal`, `select`, `number`, `date`, `part`, and `derive` helpers, `n` for the plural count, and the `GT`, `GTOptions`, `Placeholder`, and `Fragment` types. The `t` tag is only for client-rendered (SPA) apps, so only `gt-react/unstable` and `@generaltranslation/react-core/unstable` export it; server-rendered apps use `useGT()` in components and `getGT()` on the server. Root entries are unchanged. `/unstable` entries may change in any minor release and are not covered by semver.
8
+ - `@generaltranslation/react-core/unstable`: `useGT()` returns a GT bound to the render locale. It reads translations like the legacy `useGT()`: the provider's translations, then the translation cache, and in dev hot reload it sends misses for runtime translation and re-renders when they arrive. `t` works only in client-rendered (SPA) apps, where module-level calls work too; in a server-rendered app every call throws in development and renders the source with an error in production. Messages render untranslated when i18n is disabled or the requested locale needs no translation.
9
+ - `gt-react/unstable` and `gt-react-native/unstable`: the react-core client surface, without `t` in React Native. `gt-react/unstable` resolves to an RSC variant under `react-server`, where `useGT()` waits for the request locale's translations and `t` is not exported.
10
+ - `gt-next/unstable` resolves under the same conditions as `gt-next` and exports `useGT()` instead of `t`. `gt-next/unstable/server` exports an async `getGT()` for the request locale.
11
+ - `gt-tanstack-start/unstable` adds an async `getGT()` bound to the request on the server and to the browser locale in the browser. It exports no `t`, since TanStack Start renders on the server.
12
+ - `gt-node/unstable`: an async `getGT()` for the current `withGT()` locale.
13
+
14
+ - 5ccf4ef: Add deferred messages to the `/unstable` entries. Each entry exports `msg`, `mFallback` and the `M` and `Msg` types from `gt-i18n/unstable`, plus an `m` beside each `GT`: `useMessages()` wherever `useGT()` is exported (react-core, gt-react, gt-react-native, gt-next and gt-tanstack-start, with the gt-react and gt-next RSC variants waiting for the request locale's translations), and an async `getMessages()` wherever `getGT()` is (`gt-next/unstable/server`, `gt-node/unstable` and `gt-tanstack-start/unstable`). ``m(msg`...`)`` renders the message in the bound locale like `useGT()` and `getGT()` do.
15
+
16
+ ### Patch Changes
17
+
18
+ - cc73381: Add experimental `gt-i18n/unstable` and `gt-i18n/unstable/internal` entries. Their API may change in any minor release and is not covered by semver. `t` is a tagged template (`` t`Hello, ${{ name }}!` `` or `` t({ context })`Save` ``) that builds a message tree from the template, hashes it with `hashSource`, and formats loaded tree translations without the ICU string parser. Helpers `plural`, `selectordinal`, `select`, `number`, `date`, `part`, `derive`, and `n` are exported from `gt-i18n/unstable`; framework packages use `createGT` and `getGT` from `gt-i18n/unstable/internal`. Missing tree translations render the source message and, in dev hot reload, are sent for runtime translation like string and JSX messages. Template text is always literal, including ICU syntax such as `#`. A bare value (`` t`Hi ${name}` ``) is an anonymous variable and `${{ name }}` a named one; either renders like a template literal (`true` as `'true'`, `12n` as `'12'`, `null` and `undefined` as nothing), and a `Date` is a type error that points to `date()`; helpers take either form, as in `plural({ count }, ...)` or `plural(count, ...)`. Plural and select branches are strings, or `part` templates when they hold placeholders, and a plain template literal with values in a branch is a type error; `n` is the count of the nearest plural (`` part`${n} items` ``). `derive()` inlines static text chosen in code; its argument must be typed as a string literal or a union of them, so the CLI can read every variant from the type.
19
+
20
+ `Content` from `@generaltranslation/format/types` and `generaltranslation/types` replaces the `Translation` type, which `gt-i18n/types` no longer exports. Loaded catalogs, translation loaders, and the translations passed to React Core providers, gt-react-native's `LocaleTranslations`, and gt-svelte's `loadTranslations()` and `<GTProvider>` can hold message trees alongside string and JSX entries. Translation lookups and runtime translation take message trees with `$format: 'ICU_TREE'`, like any other format.
21
+
22
+ - 040ea63: From `main` (react-core 11.4.17): keep the `gt` function from `useGT()` (and the dictionary hooks built on the same dev hot reload queue) stable across renders in development, so effects that list it as a dependency no longer re-run after every render. Its identity still changes when a hot-reloaded translation arrives (#2554).
23
+ - Updated dependencies [22b6915]
24
+ - Updated dependencies [f3ed76d]
25
+ - Updated dependencies [4b6ea22]
26
+ - Updated dependencies [5ccf4ef]
27
+ - Updated dependencies [cc73381]
28
+ - Updated dependencies [726168a]
29
+ - Updated dependencies [040ea63]
30
+ - Updated dependencies [e6ef0c0]
31
+ - generaltranslation@10.0.0-samsara.1
32
+ - @generaltranslation/format@1.0.0-samsara.2
33
+ - gt-i18n@2.0.0-samsara.1
34
+
3
35
  ## 12.0.0-samsara.0
4
36
 
5
37
  ### Major Changes
@@ -17,6 +49,20 @@
17
49
  - @generaltranslation/format@1.0.0-samsara.1
18
50
  - gt-i18n@2.0.0-samsara.0
19
51
 
52
+ ## 11.4.18
53
+
54
+ ### Patch Changes
55
+
56
+ - Updated dependencies [[`c460193`](https://github.com/generaltranslation/gt/commit/c46019337dda8440a7174d783ad94a0f9b15f79a)]:
57
+ - generaltranslation@9.5.9
58
+ - gt-i18n@1.0.40
59
+
60
+ ## 11.4.17
61
+
62
+ ### Patch Changes
63
+
64
+ - [#2554](https://github.com/generaltranslation/gt/pull/2554) [`a9c1e61`](https://github.com/generaltranslation/gt/commit/a9c1e61c523951637ef0e480e0f6200fd2426643) Thanks [@dyc3](https://github.com/dyc3)! - Keep the `gt` function from `useGT()` (and the dictionary hooks built on the same dev hot reload queue) stable across renders in development, so effects that list it as a dependency no longer re-run after every render. Its identity still changes when a hot-reloaded translation arrives, so memoized and effect-derived strings pick up the new translation.
65
+
20
66
  ## 11.4.16
21
67
 
22
68
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"InternalGTProvider.cjs","names":["getGTContext"],"sources":["../../src/context/InternalGTProvider.tsx"],"sourcesContent":["import { useEffect, useMemo, type ReactNode } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport type { Dictionary, Translation } from 'gt-i18n/types';\nimport type { Locale, Hash } from 'gt-i18n/internal/types';\nimport { getGTContext } from './context';\nimport type {\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n OnMissingTranslation,\n} from '../hooks/utils/missing-translation';\n\nexport type InternalGTProviderProps = {\n children?: ReactNode;\n // For streaming translations to server\n translations: Record<Locale, Record<Hash, Translation>>;\n dictionaries?: Record<Locale, Dictionary>;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n i18nStore: I18nStore;\n // Custom override missing translation behavior for dev hot reload\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\n// ===== Component ===== //\nconst GTContext = getGTContext();\n/**\n * - Shared provider logic btwn client and server providers\n * - This is not userfacing, it should be wrapped in a userfacing provider with runtime-specific logic\n * - Locale and translations (and dictionaries if applicable) are required\n *\n * TODO: selectively filter to only pass new translations to client for dev hot reload\n * TODO: rename parent directory to \"/provider\" (separate PR)\n */\nexport function InternalGTProvider({\n children,\n translations,\n dictionaries,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n i18nStore,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n}: InternalGTProviderProps) {\n const value = useMemo(\n () => ({\n translationsSnapshot: translations,\n dictionariesSnapshot: dictionaries ?? {},\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n }),\n [\n translations,\n dictionaries,\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n ]\n );\n\n // Update cache with data from server, do not emit events\n useEffect(() => {\n i18nStore.updateTranslations(translations);\n i18nStore.updateDictionaries(dictionaries ?? {});\n }, [translations, dictionaries, i18nStore]);\n\n return <GTContext.Provider value={value}>{children}</GTContext.Provider>;\n}\n"],"mappings":"oIA8BA,MAAM,EAAYA,EAAAA,cAAc,CAShC,SAAgB,EAAmB,CACjC,WACA,eACA,eACA,SACA,SACA,aACA,YACA,YACA,gBACA,YACA,uBACA,2BACA,0BAC0B,CAC1B,IAAM,GAAA,EAAA,EAAA,cACG,CACL,qBAAsB,EACtB,qBAAsB,GAAgB,EAAE,CACxC,YACA,SACA,SACA,aACA,YACA,YACA,gBACA,uBACA,2BACA,yBACD,EACD,CACE,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CACF,CAQD,OALA,EAAA,EAAA,eAAgB,CACd,EAAU,mBAAmB,EAAa,CAC1C,EAAU,mBAAmB,GAAgB,EAAE,CAAC,EAC/C,CAAC,EAAc,EAAc,EAAU,CAAC,EAEpC,EAAA,EAAA,KAAC,EAAU,SAAX,CAA2B,QAAQ,WAA8B,CAAA"}
1
+ {"version":3,"file":"InternalGTProvider.cjs","names":["getGTContext"],"sources":["../../src/context/InternalGTProvider.tsx"],"sourcesContent":["import { useEffect, useMemo, type ReactNode } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { Locale, Hash } from 'gt-i18n/internal/types';\nimport { getGTContext } from './context';\nimport type {\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n OnMissingTranslation,\n} from '../hooks/utils/missing-translation';\n\nexport type InternalGTProviderProps = {\n children?: ReactNode;\n // For streaming translations to server\n translations: Record<Locale, Record<Hash, Content>>;\n dictionaries?: Record<Locale, Dictionary>;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n i18nStore: I18nStore;\n // Custom override missing translation behavior for dev hot reload\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\n// ===== Component ===== //\nconst GTContext = getGTContext();\n/**\n * - Shared provider logic btwn client and server providers\n * - This is not userfacing, it should be wrapped in a userfacing provider with runtime-specific logic\n * - Locale and translations (and dictionaries if applicable) are required\n *\n * TODO: selectively filter to only pass new translations to client for dev hot reload\n * TODO: rename parent directory to \"/provider\" (separate PR)\n */\nexport function InternalGTProvider({\n children,\n translations,\n dictionaries,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n i18nStore,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n}: InternalGTProviderProps) {\n const value = useMemo(\n () => ({\n translationsSnapshot: translations,\n dictionariesSnapshot: dictionaries ?? {},\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n }),\n [\n translations,\n dictionaries,\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n ]\n );\n\n // Update cache with data from server, do not emit events\n useEffect(() => {\n i18nStore.updateTranslations(translations);\n i18nStore.updateDictionaries(dictionaries ?? {});\n }, [translations, dictionaries, i18nStore]);\n\n return <GTContext.Provider value={value}>{children}</GTContext.Provider>;\n}\n"],"mappings":"oIA+BA,MAAM,EAAYA,EAAAA,cAAc,CAShC,SAAgB,EAAmB,CACjC,WACA,eACA,eACA,SACA,SACA,aACA,YACA,YACA,gBACA,YACA,uBACA,2BACA,0BAC0B,CAC1B,IAAM,GAAA,EAAA,EAAA,cACG,CACL,qBAAsB,EACtB,qBAAsB,GAAgB,EAAE,CACxC,YACA,SACA,SACA,aACA,YACA,YACA,gBACA,uBACA,2BACA,yBACD,EACD,CACE,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CACF,CAQD,OALA,EAAA,EAAA,eAAgB,CACd,EAAU,mBAAmB,EAAa,CAC1C,EAAU,mBAAmB,GAAgB,EAAE,CAAC,EAC/C,CAAC,EAAc,EAAc,EAAU,CAAC,EAEpC,EAAA,EAAA,KAAC,EAAU,SAAX,CAA2B,QAAQ,WAA8B,CAAA"}
@@ -1,14 +1,15 @@
1
1
  import { I18nStore } from "../i18n-store/I18nStore.js";
2
2
  import { OnMissingDictionaryEntry, OnMissingDictionaryObj, OnMissingTranslation } from "../hooks/utils/missing-translation.js";
3
3
  import { ReactNode } from "react";
4
- import { Dictionary, Translation } from "gt-i18n/types";
4
+ import { Dictionary } from "gt-i18n/types";
5
+ import { Content } from "@generaltranslation/format/types";
5
6
  import { Hash, Locale } from "gt-i18n/internal/types";
6
7
  import * as _$react_jsx_runtime0 from "react/jsx-runtime";
7
8
 
8
9
  //#region src/context/InternalGTProvider.d.ts
9
10
  type InternalGTProviderProps = {
10
11
  children?: ReactNode;
11
- translations: Record<Locale, Record<Hash, Translation>>;
12
+ translations: Record<Locale, Record<Hash, Content>>;
12
13
  dictionaries?: Record<Locale, Dictionary>;
13
14
  locale: string;
14
15
  region: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"InternalGTProvider.d.ts","names":[],"sources":["../../src/context/InternalGTProvider.tsx"],"mappings":";;;;;;;;KAWY,uBAAA;EACV,QAAA,GAAW,SAAA;EAEX,YAAA,EAAc,MAAA,CAAO,MAAA,EAAQ,MAAA,CAAO,IAAA,EAAM,WAAA;EAC1C,YAAA,GAAe,MAAA,CAAO,MAAA,EAAQ,UAAA;EAC9B,MAAA;EACA,MAAA;EACA,UAAA;EACA,SAAA,GAAY,MAAA;EACZ,SAAA,GAAY,MAAA;EACZ,aAAA,GAAgB,OAAA;EAChB,SAAA,EAAW,SAAA;EAEX,oBAAA,GAAuB,oBAAA;EACvB,wBAAA,GAA2B,wBAAA;EAC3B,sBAAA,GAAyB,sBAAA;AAAA;;;;;;;;;iBAaX,kBAAA,CAAA;EACd,QAAA;EACA,YAAA;EACA,YAAA;EACA,MAAA;EACA,MAAA;EACA,UAAA;EACA,SAAA;EACA,SAAA;EACA,aAAA;EACA,SAAA;EACA,oBAAA;EACA,wBAAA;EACA;AAAA,GACC,uBAAA,GAAuB,oBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"InternalGTProvider.d.ts","names":[],"sources":["../../src/context/InternalGTProvider.tsx"],"mappings":";;;;;;;;;KAYY,uBAAA;EACV,QAAA,GAAW,SAAA;EAEX,YAAA,EAAc,MAAA,CAAO,MAAA,EAAQ,MAAA,CAAO,IAAA,EAAM,OAAA;EAC1C,YAAA,GAAe,MAAA,CAAO,MAAA,EAAQ,UAAA;EAC9B,MAAA;EACA,MAAA;EACA,UAAA;EACA,SAAA,GAAY,MAAA;EACZ,SAAA,GAAY,MAAA;EACZ,aAAA,GAAgB,OAAA;EAChB,SAAA,EAAW,SAAA;EAEX,oBAAA,GAAuB,oBAAA;EACvB,wBAAA,GAA2B,wBAAA;EAC3B,sBAAA,GAAyB,sBAAA;AAAA;;;;;;;;;iBAaX,kBAAA,CAAA;EACd,QAAA;EACA,YAAA;EACA,YAAA;EACA,MAAA;EACA,MAAA;EACA,UAAA;EACA,SAAA;EACA,SAAA;EACA,aAAA;EACA,SAAA;EACA,oBAAA;EACA,wBAAA;EACA;AAAA,GACC,uBAAA,GAAuB,oBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"InternalGTProvider.mjs","names":[],"sources":["../../src/context/InternalGTProvider.tsx"],"sourcesContent":["import { useEffect, useMemo, type ReactNode } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport type { Dictionary, Translation } from 'gt-i18n/types';\nimport type { Locale, Hash } from 'gt-i18n/internal/types';\nimport { getGTContext } from './context';\nimport type {\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n OnMissingTranslation,\n} from '../hooks/utils/missing-translation';\n\nexport type InternalGTProviderProps = {\n children?: ReactNode;\n // For streaming translations to server\n translations: Record<Locale, Record<Hash, Translation>>;\n dictionaries?: Record<Locale, Dictionary>;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n i18nStore: I18nStore;\n // Custom override missing translation behavior for dev hot reload\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\n// ===== Component ===== //\nconst GTContext = getGTContext();\n/**\n * - Shared provider logic btwn client and server providers\n * - This is not userfacing, it should be wrapped in a userfacing provider with runtime-specific logic\n * - Locale and translations (and dictionaries if applicable) are required\n *\n * TODO: selectively filter to only pass new translations to client for dev hot reload\n * TODO: rename parent directory to \"/provider\" (separate PR)\n */\nexport function InternalGTProvider({\n children,\n translations,\n dictionaries,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n i18nStore,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n}: InternalGTProviderProps) {\n const value = useMemo(\n () => ({\n translationsSnapshot: translations,\n dictionariesSnapshot: dictionaries ?? {},\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n }),\n [\n translations,\n dictionaries,\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n ]\n );\n\n // Update cache with data from server, do not emit events\n useEffect(() => {\n i18nStore.updateTranslations(translations);\n i18nStore.updateDictionaries(dictionaries ?? {});\n }, [translations, dictionaries, i18nStore]);\n\n return <GTContext.Provider value={value}>{children}</GTContext.Provider>;\n}\n"],"mappings":"oIA8BA,MAAM,EAAY,GAAc,CAShC,SAAgB,EAAmB,CACjC,WACA,eACA,eACA,SACA,SACA,aACA,YACA,YACA,gBACA,YACA,uBACA,2BACA,0BAC0B,CAC1B,IAAM,EAAQ,OACL,CACL,qBAAsB,EACtB,qBAAsB,GAAgB,EAAE,CACxC,YACA,SACA,SACA,aACA,YACA,YACA,gBACA,uBACA,2BACA,yBACD,EACD,CACE,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CACF,CAQD,OALA,MAAgB,CACd,EAAU,mBAAmB,EAAa,CAC1C,EAAU,mBAAmB,GAAgB,EAAE,CAAC,EAC/C,CAAC,EAAc,EAAc,EAAU,CAAC,CAEpC,EAAC,EAAU,SAAX,CAA2B,QAAQ,WAA8B,CAAA"}
1
+ {"version":3,"file":"InternalGTProvider.mjs","names":[],"sources":["../../src/context/InternalGTProvider.tsx"],"sourcesContent":["import { useEffect, useMemo, type ReactNode } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { Locale, Hash } from 'gt-i18n/internal/types';\nimport { getGTContext } from './context';\nimport type {\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n OnMissingTranslation,\n} from '../hooks/utils/missing-translation';\n\nexport type InternalGTProviderProps = {\n children?: ReactNode;\n // For streaming translations to server\n translations: Record<Locale, Record<Hash, Content>>;\n dictionaries?: Record<Locale, Dictionary>;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n i18nStore: I18nStore;\n // Custom override missing translation behavior for dev hot reload\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\n// ===== Component ===== //\nconst GTContext = getGTContext();\n/**\n * - Shared provider logic btwn client and server providers\n * - This is not userfacing, it should be wrapped in a userfacing provider with runtime-specific logic\n * - Locale and translations (and dictionaries if applicable) are required\n *\n * TODO: selectively filter to only pass new translations to client for dev hot reload\n * TODO: rename parent directory to \"/provider\" (separate PR)\n */\nexport function InternalGTProvider({\n children,\n translations,\n dictionaries,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n i18nStore,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n}: InternalGTProviderProps) {\n const value = useMemo(\n () => ({\n translationsSnapshot: translations,\n dictionariesSnapshot: dictionaries ?? {},\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n }),\n [\n translations,\n dictionaries,\n i18nStore,\n locale,\n region,\n enableI18n,\n setLocale,\n setRegion,\n setEnableI18n,\n onMissingTranslation,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n ]\n );\n\n // Update cache with data from server, do not emit events\n useEffect(() => {\n i18nStore.updateTranslations(translations);\n i18nStore.updateDictionaries(dictionaries ?? {});\n }, [translations, dictionaries, i18nStore]);\n\n return <GTContext.Provider value={value}>{children}</GTContext.Provider>;\n}\n"],"mappings":"oIA+BA,MAAM,EAAY,GAAc,CAShC,SAAgB,EAAmB,CACjC,WACA,eACA,eACA,SACA,SACA,aACA,YACA,YACA,gBACA,YACA,uBACA,2BACA,0BAC0B,CAC1B,IAAM,EAAQ,OACL,CACL,qBAAsB,EACtB,qBAAsB,GAAgB,EAAE,CACxC,YACA,SACA,SACA,aACA,YACA,YACA,gBACA,uBACA,2BACA,yBACD,EACD,CACE,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CACF,CAQD,OALA,MAAgB,CACd,EAAU,mBAAmB,EAAa,CAC1C,EAAU,mBAAmB,GAAgB,EAAE,CAAC,EAC/C,CAAC,EAAc,EAAc,EAAU,CAAC,CAEpC,EAAC,EAAU,SAAX,CAA2B,QAAQ,WAA8B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.cjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Translation>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GTContext before it has been initialized',\n why: 'the internal GTContext singleton is unavailable',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n }),\n});\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n // Lazily create the React context once and share it across instances.\n if (!gtContextSingleton.isInitialized()) {\n gtContextSingleton.set(createContext<GTContextType | undefined>(undefined));\n }\n return gtContextSingleton.get();\n}\n\nexport function useGTContext(): GTContextType | undefined {\n const context = useContext(getGTContext());\n if (context || getI18nConfig().getRenderStrategy() === 'SPA') {\n return context;\n }\n /**\n * TODO: in a separate PR, we should figure out how to make this more of a forgiving system\n */\n throw new Error(createMissingGTProviderError());\n}\n\nfunction createMissingGTProviderError(): string {\n return createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'GT runtime context could not be read',\n why: 'GTContext was accessed outside of a <GTProvider>',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n });\n}\n"],"mappings":"sLAyCA,MAAM,GAAA,EAAA,EAAA,uBAEJ,CACA,UAAW,YACX,IAAK,YACL,OAAQ,iCACR,oBAAA,EAAA,EAAA,yBAC0B,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,uDACd,IAAK,kDACL,IAAK,yDACN,CAAC,CACL,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,KAAA,EAAA,EAAA,eAA6C,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,GAAA,EAAA,EAAA,YAAqB,GAAc,CAAC,CAC1C,GAAI,GAAWA,EAAAA,eAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAA,EAAA,EAAA,yBAA+B,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
1
+ {"version":3,"file":"context.cjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Content>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GTContext before it has been initialized',\n why: 'the internal GTContext singleton is unavailable',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n }),\n});\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n // Lazily create the React context once and share it across instances.\n if (!gtContextSingleton.isInitialized()) {\n gtContextSingleton.set(createContext<GTContextType | undefined>(undefined));\n }\n return gtContextSingleton.get();\n}\n\nexport function useGTContext(): GTContextType | undefined {\n const context = useContext(getGTContext());\n if (context || getI18nConfig().getRenderStrategy() === 'SPA') {\n return context;\n }\n /**\n * TODO: in a separate PR, we should figure out how to make this more of a forgiving system\n */\n throw new Error(createMissingGTProviderError());\n}\n\nfunction createMissingGTProviderError(): string {\n return createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'GT runtime context could not be read',\n why: 'GTContext was accessed outside of a <GTProvider>',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n });\n}\n"],"mappings":"sLAyCA,MAAM,GAAA,EAAA,EAAA,uBAEJ,CACA,UAAW,YACX,IAAK,YACL,OAAQ,iCACR,oBAAA,EAAA,EAAA,yBAC0B,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,uDACd,IAAK,kDACL,IAAK,yDACN,CAAC,CACL,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,KAAA,EAAA,EAAA,eAA6C,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,GAAA,EAAA,EAAA,YAAqB,GAAc,CAAC,CAC1C,GAAI,GAAWA,EAAAA,eAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAA,EAAA,EAAA,yBAA+B,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.mjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Translation>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GTContext before it has been initialized',\n why: 'the internal GTContext singleton is unavailable',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n }),\n});\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n // Lazily create the React context once and share it across instances.\n if (!gtContextSingleton.isInitialized()) {\n gtContextSingleton.set(createContext<GTContextType | undefined>(undefined));\n }\n return gtContextSingleton.get();\n}\n\nexport function useGTContext(): GTContextType | undefined {\n const context = useContext(getGTContext());\n if (context || getI18nConfig().getRenderStrategy() === 'SPA') {\n return context;\n }\n /**\n * TODO: in a separate PR, we should figure out how to make this more of a forgiving system\n */\n throw new Error(createMissingGTProviderError());\n}\n\nfunction createMissingGTProviderError(): string {\n return createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'GT runtime context could not be read',\n why: 'GTContext was accessed outside of a <GTProvider>',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n });\n}\n"],"mappings":"6OAyCA,MAAM,EAAqB,EAEzB,CACA,UAAW,YACX,IAAK,YACL,OAAQ,iCACR,mBACE,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,uDACd,IAAK,kDACL,IAAK,yDACN,CAAC,CACL,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,IAAI,EAAyC,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,EAAU,EAAW,GAAc,CAAC,CAC1C,GAAI,GAAWA,GAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAO,EAAwB,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
1
+ {"version":3,"file":"context.mjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import { Dictionary, Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Content>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n setLocale: (locale: string) => void;\n setRegion: (region: string | undefined) => void;\n setEnableI18n: (enabled: boolean) => void;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GTContext before it has been initialized',\n why: 'the internal GTContext singleton is unavailable',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n }),\n});\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n // Lazily create the React context once and share it across instances.\n if (!gtContextSingleton.isInitialized()) {\n gtContextSingleton.set(createContext<GTContextType | undefined>(undefined));\n }\n return gtContextSingleton.get();\n}\n\nexport function useGTContext(): GTContextType | undefined {\n const context = useContext(getGTContext());\n if (context || getI18nConfig().getRenderStrategy() === 'SPA') {\n return context;\n }\n /**\n * TODO: in a separate PR, we should figure out how to make this more of a forgiving system\n */\n throw new Error(createMissingGTProviderError());\n}\n\nfunction createMissingGTProviderError(): string {\n return createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'GT runtime context could not be read',\n why: 'GTContext was accessed outside of a <GTProvider>',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n });\n}\n"],"mappings":"6OAyCA,MAAM,EAAqB,EAEzB,CACA,UAAW,YACX,IAAK,YACL,OAAQ,iCACR,mBACE,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,uDACd,IAAK,kDACL,IAAK,yDACN,CAAC,CACL,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,IAAI,EAAyC,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,EAAU,EAAW,GAAc,CAAC,CAC1C,GAAI,GAAWA,GAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAO,EAAwB,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTranslationsSnapshot.cjs","names":["getReactI18nCache"],"sources":["../../../src/functions/helpers/getTranslationsSnapshot.ts"],"sourcesContent":["import { Hash, Locale } from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\n\n/**\n * Serializable cached translations for provider hydration; a failed load\n * yields a snapshot with no entry for the locale, so hydration caches nothing\n * and a later lookup retries. TODO: perhaps move to /i18n for type generics\n */\nexport async function getTranslationsSnapshot(\n locale: Locale\n): Promise<Record<Locale, Record<Hash, Translation>>> {\n const i18nCache = getReactI18nCache();\n try {\n return { [locale]: await i18nCache.loadTranslations(locale) };\n } catch (error) {\n console.warn(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Warning',\n whatHappened: `Could not load translations for locale \"${locale}\", so content for this locale renders untranslated`,\n why: 'the translation loader failed, usually because translations for this locale have not been generated yet',\n fix: 'Generate translations for this locale, or check your loadTranslations configuration.',\n details: formatDiagnosticErrorDetails(error),\n })\n );\n return {};\n }\n}\n"],"mappings":"0JAaA,eAAsB,EACpB,EACoD,CACpD,IAAM,EAAYA,EAAAA,mBAAmB,CACrC,GAAI,CACF,MAAO,EAAG,GAAS,MAAM,EAAU,iBAAiB,EAAO,CAAE,OACtD,EAAO,CAWd,OAVA,QAAQ,MAAA,EAAA,EAAA,yBACkB,CACtB,OAAQ,iCACR,SAAU,UACV,aAAc,2CAA2C,EAAO,oDAChE,IAAK,0GACL,IAAK,uFACL,SAAA,EAAA,EAAA,8BAAsC,EAAM,CAC7C,CAAC,CACH,CACM,EAAE"}
1
+ {"version":3,"file":"getTranslationsSnapshot.cjs","names":["getReactI18nCache"],"sources":["../../../src/functions/helpers/getTranslationsSnapshot.ts"],"sourcesContent":["import { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\n\n/**\n * Serializable cached translations for provider hydration; a failed load\n * yields a snapshot with no entry for the locale, so hydration caches nothing\n * and a later lookup retries. TODO: perhaps move to /i18n for type generics\n */\nexport async function getTranslationsSnapshot(\n locale: Locale\n): Promise<Record<Locale, Record<Hash, Content>>> {\n const i18nCache = getReactI18nCache();\n try {\n return { [locale]: await i18nCache.loadTranslations(locale) };\n } catch (error) {\n console.warn(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Warning',\n whatHappened: `Could not load translations for locale \"${locale}\", so content for this locale renders untranslated`,\n why: 'the translation loader failed, usually because translations for this locale have not been generated yet',\n fix: 'Generate translations for this locale, or check your loadTranslations configuration.',\n details: formatDiagnosticErrorDetails(error),\n })\n );\n return {};\n }\n}\n"],"mappings":"0JAaA,eAAsB,EACpB,EACgD,CAChD,IAAM,EAAYA,EAAAA,mBAAmB,CACrC,GAAI,CACF,MAAO,EAAG,GAAS,MAAM,EAAU,iBAAiB,EAAO,CAAE,OACtD,EAAO,CAWd,OAVA,QAAQ,MAAA,EAAA,EAAA,yBACkB,CACtB,OAAQ,iCACR,SAAU,UACV,aAAc,2CAA2C,EAAO,oDAChE,IAAK,0GACL,IAAK,uFACL,SAAA,EAAA,EAAA,8BAAsC,EAAM,CAC7C,CAAC,CACH,CACM,EAAE"}
@@ -1,4 +1,4 @@
1
- import { Translation } from "gt-i18n/types";
1
+ import { Content } from "@generaltranslation/format/types";
2
2
  import { Hash, Locale } from "gt-i18n/internal/types";
3
3
 
4
4
  //#region src/functions/helpers/getTranslationsSnapshot.d.ts
@@ -7,7 +7,7 @@ import { Hash, Locale } from "gt-i18n/internal/types";
7
7
  * yields a snapshot with no entry for the locale, so hydration caches nothing
8
8
  * and a later lookup retries. TODO: perhaps move to /i18n for type generics
9
9
  */
10
- declare function getTranslationsSnapshot(locale: Locale): Promise<Record<Locale, Record<Hash, Translation>>>;
10
+ declare function getTranslationsSnapshot(locale: Locale): Promise<Record<Locale, Record<Hash, Content>>>;
11
11
  //#endregion
12
12
  export { getTranslationsSnapshot };
13
13
  //# sourceMappingURL=getTranslationsSnapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTranslationsSnapshot.d.ts","names":[],"sources":["../../../src/functions/helpers/getTranslationsSnapshot.ts"],"mappings":";;;;;;AAaA;;;iBAAsB,uBAAA,CACpB,MAAA,EAAQ,MAAA,GACP,OAAA,CAAQ,MAAA,CAAO,MAAA,EAAQ,MAAA,CAAO,IAAA,EAAM,WAAA"}
1
+ {"version":3,"file":"getTranslationsSnapshot.d.ts","names":[],"sources":["../../../src/functions/helpers/getTranslationsSnapshot.ts"],"mappings":";;;;;;AAaA;;;iBAAsB,uBAAA,CACpB,MAAA,EAAQ,MAAA,GACP,OAAA,CAAQ,MAAA,CAAO,MAAA,EAAQ,MAAA,CAAO,IAAA,EAAM,OAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTranslationsSnapshot.mjs","names":[],"sources":["../../../src/functions/helpers/getTranslationsSnapshot.ts"],"sourcesContent":["import { Hash, Locale } from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\n\n/**\n * Serializable cached translations for provider hydration; a failed load\n * yields a snapshot with no entry for the locale, so hydration caches nothing\n * and a later lookup retries. TODO: perhaps move to /i18n for type generics\n */\nexport async function getTranslationsSnapshot(\n locale: Locale\n): Promise<Record<Locale, Record<Hash, Translation>>> {\n const i18nCache = getReactI18nCache();\n try {\n return { [locale]: await i18nCache.loadTranslations(locale) };\n } catch (error) {\n console.warn(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Warning',\n whatHappened: `Could not load translations for locale \"${locale}\", so content for this locale renders untranslated`,\n why: 'the translation loader failed, usually because translations for this locale have not been generated yet',\n fix: 'Generate translations for this locale, or check your loadTranslations configuration.',\n details: formatDiagnosticErrorDetails(error),\n })\n );\n return {};\n }\n}\n"],"mappings":"sLAaA,eAAsB,EACpB,EACoD,CACpD,IAAM,EAAY,GAAmB,CACrC,GAAI,CACF,MAAO,EAAG,GAAS,MAAM,EAAU,iBAAiB,EAAO,CAAE,OACtD,EAAO,CAWd,OAVA,QAAQ,KACN,EAAwB,CACtB,OAAQ,iCACR,SAAU,UACV,aAAc,2CAA2C,EAAO,oDAChE,IAAK,0GACL,IAAK,uFACL,QAAS,EAA6B,EAAM,CAC7C,CAAC,CACH,CACM,EAAE"}
1
+ {"version":3,"file":"getTranslationsSnapshot.mjs","names":[],"sources":["../../../src/functions/helpers/getTranslationsSnapshot.ts"],"sourcesContent":["import { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\n\n/**\n * Serializable cached translations for provider hydration; a failed load\n * yields a snapshot with no entry for the locale, so hydration caches nothing\n * and a later lookup retries. TODO: perhaps move to /i18n for type generics\n */\nexport async function getTranslationsSnapshot(\n locale: Locale\n): Promise<Record<Locale, Record<Hash, Content>>> {\n const i18nCache = getReactI18nCache();\n try {\n return { [locale]: await i18nCache.loadTranslations(locale) };\n } catch (error) {\n console.warn(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Warning',\n whatHappened: `Could not load translations for locale \"${locale}\", so content for this locale renders untranslated`,\n why: 'the translation loader failed, usually because translations for this locale have not been generated yet',\n fix: 'Generate translations for this locale, or check your loadTranslations configuration.',\n details: formatDiagnosticErrorDetails(error),\n })\n );\n return {};\n }\n}\n"],"mappings":"sLAaA,eAAsB,EACpB,EACgD,CAChD,IAAM,EAAY,GAAmB,CACrC,GAAI,CACF,MAAO,EAAG,GAAS,MAAM,EAAU,iBAAiB,EAAO,CAAE,OACtD,EAAO,CAWd,OAVA,QAAQ,KACN,EAAwB,CACtB,OAAQ,iCACR,SAAU,UACV,aAAc,2CAA2C,EAAO,oDAChE,IAAK,0GACL,IAAK,uFACL,QAAS,EAA6B,EAAM,CAC7C,CAAC,CACH,CACM,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"t.cjs","names":["getReactI18nCache","getI18nConfig","getShouldTranslate","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions } from 'gt-i18n/types';\nimport type { LookupOptionsFor } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\nfunction enforceSSRRules(messageOrStrings: string | TemplateStringsArray) {\n const ssrEnabled = getI18nConfig().getRenderStrategy() === 'server-render';\n const moduleLevel = !isReadonlyConditionStoreInitialized();\n if (!ssrEnabled || !moduleLevel) return;\n\n const message =\n typeof messageOrStrings === 'string'\n ? messageOrStrings\n : messageOrStrings.join('');\n const runtimeEnvironment = getRuntimeEnvironment();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Using the t() function at the module level is forbidden in server-rendered applications.',\n fix: 'Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : 'Falling back to defaultLocale value.',\n details: `Message: \"${message}\"`,\n });\n if (getRuntimeEnvironment() === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n}\n\nfunction getLocale(): string {\n return getReadonlyConditionStore().getLocale();\n}\n\n/**\n * Overloaded type for the `t` function.\n * - Tagged template: t`Hello, ${name}` (transformed by the compiler plugin at build time)\n * - Function call: t(\"Hello, {name}\", { name: \"John\" })\n *\n * {@link TemplateSyncResolutionFunction}\n * {@link SyncResolutionFunction}\n */\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\n/**\n * Type for the `t` function when used as a tagged template literal.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The translated message.\n */\ntype TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n"],"mappings":"kVAiCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,GAAA,EAAA,EAAA,qBACoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAYA,EAAAA,mBAAmB,CAC/B,EAAgBC,EAAAA,eAAe,CAAC,kBAAkB,CACxD,GAAI,CAACC,EAAAA,oBAAoB,CACvB,OAAA,EAAA,EAAA,oBAA0B,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,GAAA,EAAA,EAAA,qBAAoC,EAAQ,EAAS,MAAM,CAMjE,OAAA,EAAA,EAAA,oBAA0B,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADYF,EAAAA,mBAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,SAAS,EAAgB,EAAiD,CACxE,IAAM,EAAaC,EAAAA,eAAe,CAAC,mBAAmB,GAAK,gBACrD,EAAc,CAACE,EAAAA,6BAAqC,CAC1D,GAAI,CAAC,GAAc,CAAC,EAAa,OAEjC,IAAM,EACJ,OAAO,GAAqB,SACxB,EACA,EAAiB,KAAK,GAAG,CAEzB,GAAA,EAAA,EAAA,yBAAuC,CAC3C,OAAQ,iCACR,SAAU,QACV,aACE,2FACF,IAAK,8NACL,QAAA,EAAA,EAAA,wBACoB,GAAK,cACnB,IAAA,GACA,uCACN,QAAS,aAAa,EAAQ,GAC/B,CAAC,CACF,IAAA,EAAA,EAAA,wBAA2B,GAAK,cAC9B,MAAU,MAAM,EAAa,CAE7B,QAAQ,MAAM,EAAa,CAI/B,SAAS,GAAoB,CAC3B,OAAOC,EAAAA,mBAA2B,CAAC,WAAW"}
1
+ {"version":3,"file":"t.cjs","names":["getReactI18nCache","getI18nConfig","getShouldTranslate","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions } from 'gt-i18n/types';\nimport type { LookupOptionsFor } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\nexport function enforceSSRRules(\n messageOrStrings: string | TemplateStringsArray\n) {\n const ssrEnabled = getI18nConfig().getRenderStrategy() === 'server-render';\n const moduleLevel = !isReadonlyConditionStoreInitialized();\n if (!ssrEnabled || !moduleLevel) return;\n\n const message =\n typeof messageOrStrings === 'string'\n ? messageOrStrings\n : messageOrStrings.join('');\n const runtimeEnvironment = getRuntimeEnvironment();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Using the t() function at the module level is forbidden in server-rendered applications.',\n fix: 'Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : 'Falling back to defaultLocale value.',\n details: `Message: \"${message}\"`,\n });\n if (getRuntimeEnvironment() === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n}\n\nfunction getLocale(): string {\n return getReadonlyConditionStore().getLocale();\n}\n\n/**\n * Overloaded type for the `t` function.\n * - Tagged template: t`Hello, ${name}` (transformed by the compiler plugin at build time)\n * - Function call: t(\"Hello, {name}\", { name: \"John\" })\n *\n * {@link TemplateSyncResolutionFunction}\n * {@link SyncResolutionFunction}\n */\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\n/**\n * Type for the `t` function when used as a tagged template literal.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The translated message.\n */\ntype TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n"],"mappings":"kVAiCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,GAAA,EAAA,EAAA,qBACoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAYA,EAAAA,mBAAmB,CAC/B,EAAgBC,EAAAA,eAAe,CAAC,kBAAkB,CACxD,GAAI,CAACC,EAAAA,oBAAoB,CACvB,OAAA,EAAA,EAAA,oBAA0B,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,GAAA,EAAA,EAAA,qBAAoC,EAAQ,EAAS,MAAM,CAMjE,OAAA,EAAA,EAAA,oBAA0B,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADYF,EAAAA,mBAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,SAAgB,EACd,EACA,CACA,IAAM,EAAaC,EAAAA,eAAe,CAAC,mBAAmB,GAAK,gBACrD,EAAc,CAACE,EAAAA,6BAAqC,CAC1D,GAAI,CAAC,GAAc,CAAC,EAAa,OAEjC,IAAM,EACJ,OAAO,GAAqB,SACxB,EACA,EAAiB,KAAK,GAAG,CAEzB,GAAA,EAAA,EAAA,yBAAuC,CAC3C,OAAQ,iCACR,SAAU,QACV,aACE,2FACF,IAAK,8NACL,QAAA,EAAA,EAAA,wBACoB,GAAK,cACnB,IAAA,GACA,uCACN,QAAS,aAAa,EAAQ,GAC/B,CAAC,CACF,IAAA,EAAA,EAAA,wBAA2B,GAAK,cAC9B,MAAU,MAAM,EAAa,CAE7B,QAAQ,MAAM,EAAa,CAI/B,SAAS,GAAoB,CAC3B,OAAOC,EAAAA,mBAA2B,CAAC,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"t.d.ts","names":[],"sources":["../../../src/functions/translation/t.ts"],"mappings":";;;;AAiCA;;;;;AAmDC;;;;;;;;;cAnDY,CAAA,EAAG,sCAAA;;;;;;;;;UA+LN,sCAAA;EAAA,CACP,OAAA,EAAS,oBAAA,KAAyB,MAAA;EAAA,CAClC,OAAA,UAAiB,OAAA,GAAU,oBAAA;AAAA"}
1
+ {"version":3,"file":"t.d.ts","names":[],"sources":["../../../src/functions/translation/t.ts"],"mappings":";;;;AAiCA;;;;;AAmLC;;;;;;;;;cAnLY,CAAA,EAAG,sCAAA;;;;;;;;;UAiMN,sCAAA;EAAA,CACP,OAAA,EAAS,oBAAA,KAAyB,MAAA;EAAA,CAClC,OAAA,UAAiB,OAAA,GAAU,oBAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"t.mjs","names":["getI18nConfig","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions } from 'gt-i18n/types';\nimport type { LookupOptionsFor } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\nfunction enforceSSRRules(messageOrStrings: string | TemplateStringsArray) {\n const ssrEnabled = getI18nConfig().getRenderStrategy() === 'server-render';\n const moduleLevel = !isReadonlyConditionStoreInitialized();\n if (!ssrEnabled || !moduleLevel) return;\n\n const message =\n typeof messageOrStrings === 'string'\n ? messageOrStrings\n : messageOrStrings.join('');\n const runtimeEnvironment = getRuntimeEnvironment();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Using the t() function at the module level is forbidden in server-rendered applications.',\n fix: 'Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : 'Falling back to defaultLocale value.',\n details: `Message: \"${message}\"`,\n });\n if (getRuntimeEnvironment() === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n}\n\nfunction getLocale(): string {\n return getReadonlyConditionStore().getLocale();\n}\n\n/**\n * Overloaded type for the `t` function.\n * - Tagged template: t`Hello, ${name}` (transformed by the compiler plugin at build time)\n * - Function call: t(\"Hello, {name}\", { name: \"John\" })\n *\n * {@link TemplateSyncResolutionFunction}\n * {@link SyncResolutionFunction}\n */\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\n/**\n * Type for the `t` function when used as a tagged template literal.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The translated message.\n */\ntype TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n"],"mappings":"2fAiCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,EACA,EAAoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAY,GAAmB,CAC/B,EAAgBA,GAAe,CAAC,kBAAkB,CACxD,GAAI,CAAC,GAAoB,CACvB,OAAO,EAAmB,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,EAAgB,EAAoB,EAAQ,EAAS,MAAM,CAMjE,OAAO,EAAmB,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADY,GAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,SAAS,EAAgB,EAAiD,CACxE,IAAM,EAAaA,GAAe,CAAC,mBAAmB,GAAK,gBACrD,EAAc,CAACC,GAAqC,CAC1D,GAAI,CAAC,GAAc,CAAC,EAAa,OAEjC,IAAM,EACJ,OAAO,GAAqB,SACxB,EACA,EAAiB,KAAK,GAAG,CAEzB,EAAe,EAAwB,CAC3C,OAAQ,iCACR,SAAU,QACV,aACE,2FACF,IAAK,8NACL,OAPyB,GAQL,GAAK,cACnB,IAAA,GACA,uCACN,QAAS,aAAa,EAAQ,GAC/B,CAAC,CACF,GAAI,GAAuB,GAAK,cAC9B,MAAU,MAAM,EAAa,CAE7B,QAAQ,MAAM,EAAa,CAI/B,SAAS,GAAoB,CAC3B,OAAOC,GAA2B,CAAC,WAAW"}
1
+ {"version":3,"file":"t.mjs","names":["getI18nConfig","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions } from 'gt-i18n/types';\nimport type { LookupOptionsFor } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\nexport function enforceSSRRules(\n messageOrStrings: string | TemplateStringsArray\n) {\n const ssrEnabled = getI18nConfig().getRenderStrategy() === 'server-render';\n const moduleLevel = !isReadonlyConditionStoreInitialized();\n if (!ssrEnabled || !moduleLevel) return;\n\n const message =\n typeof messageOrStrings === 'string'\n ? messageOrStrings\n : messageOrStrings.join('');\n const runtimeEnvironment = getRuntimeEnvironment();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Using the t() function at the module level is forbidden in server-rendered applications.',\n fix: 'Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : 'Falling back to defaultLocale value.',\n details: `Message: \"${message}\"`,\n });\n if (getRuntimeEnvironment() === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n}\n\nfunction getLocale(): string {\n return getReadonlyConditionStore().getLocale();\n}\n\n/**\n * Overloaded type for the `t` function.\n * - Tagged template: t`Hello, ${name}` (transformed by the compiler plugin at build time)\n * - Function call: t(\"Hello, {name}\", { name: \"John\" })\n *\n * {@link TemplateSyncResolutionFunction}\n * {@link SyncResolutionFunction}\n */\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\n/**\n * Type for the `t` function when used as a tagged template literal.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The translated message.\n */\ntype TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n"],"mappings":"2fAiCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,EACA,EAAoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAY,GAAmB,CAC/B,EAAgBA,GAAe,CAAC,kBAAkB,CACxD,GAAI,CAAC,GAAoB,CACvB,OAAO,EAAmB,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,EAAgB,EAAoB,EAAQ,EAAS,MAAM,CAMjE,OAAO,EAAmB,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADY,GAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,SAAgB,EACd,EACA,CACA,IAAM,EAAaA,GAAe,CAAC,mBAAmB,GAAK,gBACrD,EAAc,CAACC,GAAqC,CAC1D,GAAI,CAAC,GAAc,CAAC,EAAa,OAEjC,IAAM,EACJ,OAAO,GAAqB,SACxB,EACA,EAAiB,KAAK,GAAG,CAEzB,EAAe,EAAwB,CAC3C,OAAQ,iCACR,SAAU,QACV,aACE,2FACF,IAAK,8NACL,OAPyB,GAQL,GAAK,cACnB,IAAA,GACA,uCACN,QAAS,aAAa,EAAQ,GAC/B,CAAC,CACF,GAAI,GAAuB,GAAK,cAC9B,MAAU,MAAM,EAAa,CAE7B,QAAQ,MAAM,EAAa,CAI/B,SAAS,GAAoB,CAC3B,OAAOC,GAA2B,CAAC,WAAW"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);let e=require(`react`);function t(t,n,r){let i=(0,e.useRef)(0),a=(0,e.useCallback)(e=>n(n=>{t.current.has(r(n))&&(i.current++,e())}),[n,r,t]),o=(0,e.useCallback)(()=>i.current,[]);(0,e.useSyncExternalStore)(a,o,o)}const n=process.env.NODE_ENV===`production`?()=>{}:t;exports.useSubscribeToTrackedLookups=n;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);let e=require(`react`);function t(t,n,r){let i=(0,e.useRef)(0),a=(0,e.useCallback)(e=>n(n=>{t.current.has(r(n))&&(i.current++,e())}),[n,r,t]),o=(0,e.useCallback)(()=>i.current,[]);return(0,e.useSyncExternalStore)(a,o,o)}const n=process.env.NODE_ENV===`production`?()=>0:t;exports.useSubscribeToTrackedLookups=n;
2
2
  //# sourceMappingURL=useSubscribeToTrackedLookups.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSubscribeToTrackedLookups.cjs","names":[],"sources":["../../../src/hooks/external-store/useSubscribeToTrackedLookups.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport type { StoreListener, Unsubscribe } from '../../i18n-store/storeTypes';\n\ntype UseSubscribeToTrackedLookups = <L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) => void;\n\n/**\n * Subscribe to store events, but only trigger re-renders when the event's\n * lookup is in the tracked keys set. Shared by the tracked translation and\n * dictionary resolvers, which differ only in the store subscribe method and the\n * listener-key function.\n *\n * Remember that we can make no assumptions about when the tracked set gets\n * updated. This is technically not pure, but it is an acceptable trade since it\n * only drives dev translation hot reload.\n */\nfunction useSubscribeToTrackedLookupsDev<L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return subscribeToEvents((lookup) => {\n if (!trackedKeysRef.current!.has(getListenerKey(lookup))) return;\n versionRef.current++;\n listener();\n });\n },\n [subscribeToEvents, getListenerKey, trackedKeysRef]\n );\n const getSnapshot = useCallback(() => versionRef.current, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nconst useSubscribeToTrackedLookupsProd: UseSubscribeToTrackedLookups = () => {};\n\nexport const useSubscribeToTrackedLookups: UseSubscribeToTrackedLookups =\n process.env.NODE_ENV === 'production'\n ? useSubscribeToTrackedLookupsProd\n : useSubscribeToTrackedLookupsDev;\n"],"mappings":"uEAwBA,SAAS,EACP,EACA,EACA,EACA,CAEA,IAAM,GAAA,EAAA,EAAA,QAAoB,EAAE,CACtB,GAAA,EAAA,EAAA,aACH,GACQ,EAAmB,GAAW,CAC9B,EAAe,QAAS,IAAI,EAAe,EAAO,CAAC,GACxD,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAmB,EAAgB,EAAe,CACpD,CACK,GAAA,EAAA,EAAA,iBAAgC,EAAW,QAAS,EAAE,CAAC,EAE7D,EAAA,EAAA,sBAAqB,EAAW,EAAa,EAAY,CAK3D,MAAa,EACX,QAAQ,IAAI,WAAa,iBAHkD,GAKvE"}
1
+ {"version":3,"file":"useSubscribeToTrackedLookups.cjs","names":[],"sources":["../../../src/hooks/external-store/useSubscribeToTrackedLookups.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport type { StoreListener, Unsubscribe } from '../../i18n-store/storeTypes';\n\ntype UseSubscribeToTrackedLookups = <L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) => number;\n\n/**\n * Subscribe to store events, but only trigger re-renders when the event's\n * lookup is in the tracked keys set. Shared by the tracked translation and\n * dictionary resolvers, which differ only in the store subscribe method and the\n * listener-key function.\n *\n * Returns a version that changes whenever a tracked lookup updates. Resolvers\n * include it in their memoization dependencies so the translation functions\n * they return change identity when, and only when, a tracked translation\n * arrives.\n *\n * Remember that we can make no assumptions about when the tracked set gets\n * updated. This is technically not pure, but it is an acceptable trade since it\n * only drives dev translation hot reload.\n */\nfunction useSubscribeToTrackedLookupsDev<L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n): number {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return subscribeToEvents((lookup) => {\n if (!trackedKeysRef.current!.has(getListenerKey(lookup))) return;\n versionRef.current++;\n listener();\n });\n },\n [subscribeToEvents, getListenerKey, trackedKeysRef]\n );\n const getSnapshot = useCallback(() => versionRef.current, []);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nconst useSubscribeToTrackedLookupsProd: UseSubscribeToTrackedLookups = () => 0;\n\nexport const useSubscribeToTrackedLookups: UseSubscribeToTrackedLookups =\n process.env.NODE_ENV === 'production'\n ? useSubscribeToTrackedLookupsProd\n : useSubscribeToTrackedLookupsDev;\n"],"mappings":"uEA6BA,SAAS,EACP,EACA,EACA,EACQ,CAER,IAAM,GAAA,EAAA,EAAA,QAAoB,EAAE,CACtB,GAAA,EAAA,EAAA,aACH,GACQ,EAAmB,GAAW,CAC9B,EAAe,QAAS,IAAI,EAAe,EAAO,CAAC,GACxD,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAmB,EAAgB,EAAe,CACpD,CACK,GAAA,EAAA,EAAA,iBAAgC,EAAW,QAAS,EAAE,CAAC,CAE7D,OAAA,EAAA,EAAA,sBAA4B,EAAW,EAAa,EAAY,CAKlE,MAAa,EACX,QAAQ,IAAI,WAAa,iBAHkD,EAKvE"}
@@ -1,2 +1,2 @@
1
- import{useCallback as e,useRef as t,useSyncExternalStore as n}from"react";function r(r,i,a){let o=t(0),s=e(e=>i(t=>{r.current.has(a(t))&&(o.current++,e())}),[i,a,r]),c=e(()=>o.current,[]);n(s,c,c)}const i=process.env.NODE_ENV===`production`?()=>{}:r;export{i as useSubscribeToTrackedLookups};
1
+ import{useCallback as e,useRef as t,useSyncExternalStore as n}from"react";function r(r,i,a){let o=t(0),s=e(e=>i(t=>{r.current.has(a(t))&&(o.current++,e())}),[i,a,r]),c=e(()=>o.current,[]);return n(s,c,c)}const i=process.env.NODE_ENV===`production`?()=>0:r;export{i as useSubscribeToTrackedLookups};
2
2
  //# sourceMappingURL=useSubscribeToTrackedLookups.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSubscribeToTrackedLookups.mjs","names":[],"sources":["../../../src/hooks/external-store/useSubscribeToTrackedLookups.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport type { StoreListener, Unsubscribe } from '../../i18n-store/storeTypes';\n\ntype UseSubscribeToTrackedLookups = <L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) => void;\n\n/**\n * Subscribe to store events, but only trigger re-renders when the event's\n * lookup is in the tracked keys set. Shared by the tracked translation and\n * dictionary resolvers, which differ only in the store subscribe method and the\n * listener-key function.\n *\n * Remember that we can make no assumptions about when the tracked set gets\n * updated. This is technically not pure, but it is an acceptable trade since it\n * only drives dev translation hot reload.\n */\nfunction useSubscribeToTrackedLookupsDev<L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return subscribeToEvents((lookup) => {\n if (!trackedKeysRef.current!.has(getListenerKey(lookup))) return;\n versionRef.current++;\n listener();\n });\n },\n [subscribeToEvents, getListenerKey, trackedKeysRef]\n );\n const getSnapshot = useCallback(() => versionRef.current, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nconst useSubscribeToTrackedLookupsProd: UseSubscribeToTrackedLookups = () => {};\n\nexport const useSubscribeToTrackedLookups: UseSubscribeToTrackedLookups =\n process.env.NODE_ENV === 'production'\n ? useSubscribeToTrackedLookupsProd\n : useSubscribeToTrackedLookupsDev;\n"],"mappings":"0EAwBA,SAAS,EACP,EACA,EACA,EACA,CAEA,IAAM,EAAa,EAAO,EAAE,CACtB,EAAY,EACf,GACQ,EAAmB,GAAW,CAC9B,EAAe,QAAS,IAAI,EAAe,EAAO,CAAC,GACxD,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAmB,EAAgB,EAAe,CACpD,CACK,EAAc,MAAkB,EAAW,QAAS,EAAE,CAAC,CAE7D,EAAqB,EAAW,EAAa,EAAY,CAK3D,MAAa,EACX,QAAQ,IAAI,WAAa,iBAHkD,GAKvE"}
1
+ {"version":3,"file":"useSubscribeToTrackedLookups.mjs","names":[],"sources":["../../../src/hooks/external-store/useSubscribeToTrackedLookups.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport type { StoreListener, Unsubscribe } from '../../i18n-store/storeTypes';\n\ntype UseSubscribeToTrackedLookups = <L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) => number;\n\n/**\n * Subscribe to store events, but only trigger re-renders when the event's\n * lookup is in the tracked keys set. Shared by the tracked translation and\n * dictionary resolvers, which differ only in the store subscribe method and the\n * listener-key function.\n *\n * Returns a version that changes whenever a tracked lookup updates. Resolvers\n * include it in their memoization dependencies so the translation functions\n * they return change identity when, and only when, a tracked translation\n * arrives.\n *\n * Remember that we can make no assumptions about when the tracked set gets\n * updated. This is technically not pure, but it is an acceptable trade since it\n * only drives dev translation hot reload.\n */\nfunction useSubscribeToTrackedLookupsDev<L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n): number {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return subscribeToEvents((lookup) => {\n if (!trackedKeysRef.current!.has(getListenerKey(lookup))) return;\n versionRef.current++;\n listener();\n });\n },\n [subscribeToEvents, getListenerKey, trackedKeysRef]\n );\n const getSnapshot = useCallback(() => versionRef.current, []);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nconst useSubscribeToTrackedLookupsProd: UseSubscribeToTrackedLookups = () => 0;\n\nexport const useSubscribeToTrackedLookups: UseSubscribeToTrackedLookups =\n process.env.NODE_ENV === 'production'\n ? useSubscribeToTrackedLookupsProd\n : useSubscribeToTrackedLookupsDev;\n"],"mappings":"0EA6BA,SAAS,EACP,EACA,EACA,EACQ,CAER,IAAM,EAAa,EAAO,EAAE,CACtB,EAAY,EACf,GACQ,EAAmB,GAAW,CAC9B,EAAe,QAAS,IAAI,EAAe,EAAO,CAAC,GACxD,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAmB,EAAgB,EAAe,CACpD,CACK,EAAc,MAAkB,EAAW,QAAS,EAAE,CAAC,CAE7D,OAAO,EAAqB,EAAW,EAAa,EAAY,CAKlE,MAAa,EACX,QAAQ,IAAI,WAAa,iBAHkD,EAKvE"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(){let a=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryObject(),l=(0,i.useRef)(null);return l.current??=new Set,n.useSubscribeToTrackedLookups(l,o.subscribeToDictionaryObjectEvents,r.getDictionaryListenerKey),(0,i.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryObjectSnapshot(e,a);return n==null&&s&&c(e),n},[o,a,s,c])}exports.useTrackedDictionaryObjResolver=a;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(){let a=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryObject(),l=(0,i.useRef)(null);return l.current??=new Set,(0,i.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryObjectSnapshot(e,a);return n==null&&s&&c(e),n},[o,a,s,c,n.useSubscribeToTrackedLookups(l,o.subscribeToDictionaryObjectEvents,r.getDictionaryListenerKey)])}exports.useTrackedDictionaryObjResolver=a;
2
2
  //# sourceMappingURL=useTrackedDictionaryObjResolver.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryObjResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryObject","getDictionaryListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary object updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryObjectEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n ]\n );\n}\n"],"mappings":"wPAkBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAyBC,EAAAA,kCAAkC,CAE3D,GAAA,EAAA,EAAA,QAA4C,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAA,6BACE,EACA,EAAU,kCACVC,EAAAA,yBACD,EAGD,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
1
+ {"version":3,"file":"useTrackedDictionaryObjResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryObject","useSubscribeToTrackedLookups","getDictionaryListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary object updates\n const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryObjectEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"wPAkBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAyBC,EAAAA,kCAAkC,CAE3D,GAAA,EAAA,EAAA,QAA4C,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,KAW/B,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAGT,CACE,EACA,EACA,EACA,EAjC0BC,EAAAA,6BAC5B,EACA,EAAU,kCACVC,EAAAA,yBA+BuB,CACtB,CACF"}
@@ -1,2 +1,2 @@
1
- import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryObject as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{getDictionaryListenerKey as i,getI18nConfig as a}from"gt-i18n/internal";import{useCallback as o,useRef as s}from"react";function c(){let c=e(),l=t(),u=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),d=n(),f=s(null);return f.current??=new Set,r(f,l.subscribeToDictionaryObjectEvents,i),o(e=>{let t=i(e);u&&f.current.add(t);let n=l.getDictionaryObjectSnapshot(e,c);return n==null&&u&&d(e),n},[l,c,u,d])}export{c as useTrackedDictionaryObjResolver};
1
+ import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryObject as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{getDictionaryListenerKey as i,getI18nConfig as a}from"gt-i18n/internal";import{useCallback as o,useRef as s}from"react";function c(){let c=e(),l=t(),u=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),d=n(),f=s(null);return f.current??=new Set,o(e=>{let t=i(e);u&&f.current.add(t);let n=l.getDictionaryObjectSnapshot(e,c);return n==null&&u&&d(e),n},[l,c,u,d,r(f,l.subscribeToDictionaryObjectEvents,i)])}export{c as useTrackedDictionaryObjResolver};
2
2
  //# sourceMappingURL=useTrackedDictionaryObjResolver.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryObjResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary object updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryObjectEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n ]\n );\n}\n"],"mappings":"mYAkBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAAyB,GAAkC,CAE3D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EACE,EACA,EAAU,kCACV,EACD,CAGM,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
1
+ {"version":3,"file":"useTrackedDictionaryObjResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary object updates\n const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryObjectEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"mYAkBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAAyB,GAAkC,CAE3D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAWxB,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAGT,CACE,EACA,EACA,EACA,EAjC0B,EAC5B,EACA,EAAU,kCACV,EA+BuB,CACtB,CACF"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(){let a=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryEntry(),l=(0,i.useRef)(null);return l.current??=new Set,n.useSubscribeToTrackedLookups(l,o.subscribeToDictionaryEntryEvents,r.getDictionaryListenerKey),(0,i.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryEntrySnapshot(e,a);return n==null&&s&&c(e),n},[o,a,s,c])}exports.useTrackedDictionaryResolver=a;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(){let a=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryEntry(),l=(0,i.useRef)(null);return l.current??=new Set,(0,i.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryEntrySnapshot(e,a);return n==null&&s&&c(e),n},[o,a,s,c,n.useSubscribeToTrackedLookups(l,o.subscribeToDictionaryEntryEvents,r.getDictionaryListenerKey)])}exports.useTrackedDictionaryResolver=a;
2
2
  //# sourceMappingURL=useTrackedDictionaryResolver.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryEntry","getDictionaryListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryEntryEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n ]\n );\n}\n"],"mappings":"wPAkBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAA2BC,EAAAA,iCAAiC,CAE5D,GAAA,EAAA,EAAA,QAA4C,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAA,6BACE,EACA,EAAU,iCACVC,EAAAA,yBACD,EAGD,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
1
+ {"version":3,"file":"useTrackedDictionaryResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryEntry","useSubscribeToTrackedLookups","getDictionaryListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryEntryEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"wPAkBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAA2BC,EAAAA,iCAAiC,CAE5D,GAAA,EAAA,EAAA,QAA4C,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,KAW/B,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAGT,CACE,EACA,EACA,EACA,EAjC0BC,EAAAA,6BAC5B,EACA,EAAU,iCACVC,EAAAA,yBA+BuB,CACtB,CACF"}
@@ -1,2 +1,2 @@
1
- import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryEntry as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{getDictionaryListenerKey as i,getI18nConfig as a}from"gt-i18n/internal";import{useCallback as o,useRef as s}from"react";function c(){let c=e(),l=t(),u=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),d=n(),f=s(null);return f.current??=new Set,r(f,l.subscribeToDictionaryEntryEvents,i),o(e=>{let t=i(e);u&&f.current.add(t);let n=l.getDictionaryEntrySnapshot(e,c);return n==null&&u&&d(e),n},[l,c,u,d])}export{c as useTrackedDictionaryResolver};
1
+ import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryEntry as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{getDictionaryListenerKey as i,getI18nConfig as a}from"gt-i18n/internal";import{useCallback as o,useRef as s}from"react";function c(){let c=e(),l=t(),u=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),d=n(),f=s(null);return f.current??=new Set,o(e=>{let t=i(e);u&&f.current.add(t);let n=l.getDictionaryEntrySnapshot(e,c);return n==null&&u&&d(e),n},[l,c,u,d,r(f,l.subscribeToDictionaryEntryEvents,i)])}export{c as useTrackedDictionaryResolver};
2
2
  //# sourceMappingURL=useTrackedDictionaryResolver.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryEntryEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n ]\n );\n}\n"],"mappings":"kYAkBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAA2B,GAAiC,CAE5D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EACE,EACA,EAAU,iCACV,EACD,CAGM,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
1
+ {"version":3,"file":"useTrackedDictionaryResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryEntryEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"kYAkBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAA2B,GAAiC,CAE5D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAWxB,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAGT,CACE,EACA,EACA,EACA,EAjC0B,EAC5B,EACA,EAAU,iCACV,EA+BuB,CACtB,CACF"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(a=[],s,c){let l=e.useTranslationsSnapshot(),u=e.useI18nStore(),d=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),f=t.useHandleMissingTranslationWithConditions(c),p=(0,i.useRef)(null);return p.current??=new Set,o(a,p,s,c),n.useSubscribeToTrackedLookups(p,u.subscribeToTranslationEvents,r.getTranslateListenerKey),(0,i.useCallback)(e=>{let t=(0,r.getTranslateListenerKey)(e);d&&p.current.add(t);let n=u.getTranslateSnapshot(e,l);return n==null&&d&&f(e),n},[u,l,f,d])}function o(t,n,a,o){let s=e.useI18nStore(),c=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),l=e.useTranslationsSnapshot(),u=(0,i.useMemo)(()=>t?.length>0&&o&&c,[t,o,c]),d=(0,i.useMemo)(()=>u?t.map(({message:e,...t})=>{let n=t.$locale??a,i={locale:n,message:e,options:(0,r.createLookupOptions)(n,t,`ICU`)};return[i,(0,r.getTranslateListenerKey)(i)]}):[],[a,u,t]);u&&d.forEach(([,e])=>{n.current.add(e)}),(0,i.useEffect)(()=>{u&&d.filter(([e])=>s.getTranslateSnapshot(e,l)==null).forEach(([e])=>s.translate(e))},[u,s,d,l])}exports.useTrackedTranslationResolver=a;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(a=[],s,c){let l=e.useTranslationsSnapshot(),u=e.useI18nStore(),d=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),f=t.useHandleMissingTranslationWithConditions(c),p=(0,i.useRef)(null);return p.current??=new Set,o(a,p,s,c),(0,i.useCallback)(e=>{let t=(0,r.getTranslateListenerKey)(e);d&&p.current.add(t);let n=u.getTranslateSnapshot(e,l);return n==null&&d&&f(e),n},[u,l,f,d,n.useSubscribeToTrackedLookups(p,u.subscribeToTranslationEvents,r.getTranslateListenerKey)])}function o(t,n,a,o){let s=e.useI18nStore(),c=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),l=e.useTranslationsSnapshot(),u=(0,i.useMemo)(()=>t?.length>0&&o&&c,[t,o,c]),d=(0,i.useMemo)(()=>u?t.map(({message:e,...t})=>{let n=t.$locale??a,i={locale:n,message:e,options:(0,r.createLookupOptions)(n,t,`ICU`)};return[i,(0,r.getTranslateListenerKey)(i)]}):[],[a,u,t]);u&&d.forEach(([,e])=>{n.current.add(e)}),(0,i.useEffect)(()=>{u&&d.filter(([e])=>s.getTranslateSnapshot(e,l)==null).forEach(([e])=>s.translate(e))},[u,s,d,l])}exports.useTrackedTranslationResolver=a;
2
2
  //# sourceMappingURL=useTrackedTranslationResolver.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedTranslationResolver.cjs","names":["useTranslationsSnapshot","useI18nStore","useHandleMissingTranslationWithConditions","getTranslateListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedTranslationResolver.ts"],"sourcesContent":["import { type RefObject, useCallback, useEffect, useMemo, useRef } from 'react';\nimport {\n createLookupOptions,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport type { Translation } from 'gt-i18n/types';\nimport type {\n TranslateLookup,\n TranslateSnapshot,\n} from '../../i18n-store/storeTypes';\nimport type { TranslationMetadata } from 'gt-i18n/internal/types';\nimport type { StringFormat } from '@generaltranslation/format';\nimport {\n useI18nStore,\n useTranslationsSnapshot,\n} from '../../i18n-store/useI18nStore';\nimport { useHandleMissingTranslationWithConditions } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\n/**\n * Returns the translation, but also triggers a translation if it is not found\n * when dev hot reload is enabled.\n */\nexport type TrackedTranslationResolver = <T extends Translation>(\n lookup: TranslateLookup<T>\n) => TranslateSnapshot<T>;\n\nexport type Message = TranslationMetadata & {\n message: string;\n};\n\n/**\n * NOTE:\n * gt() may be called during render, so tracking intentionally only mutates\n * hook-local refs. This widens the event filter used by our existing\n * useSyncExternalStore subscription, but does not update React state or mutate\n * the translation cache during render.\n *\n * A render that is later aborted may leave behind an extra tracked key. That is\n * acceptable for dev hot reload because the worst case is an unnecessary\n * invalidation for this hook instance, not incorrect rendered output.\n */\n\nexport function useTrackedTranslationResolver(\n messages: Message[] = [],\n locale: string,\n shouldTranslate: boolean\n): TrackedTranslationResolver {\n const translationsSnapshot = useTranslationsSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingTranslation =\n useHandleMissingTranslationWithConditions(shouldTranslate);\n\n /**\n * Track lookups per hook instance without updating React state during render.\n */\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // (optimization) Pre-subscribe to compiler-injected lookups\n usePreloadCompilerLookups(messages, trackedKeysRef, locale, shouldTranslate);\n\n // (tx hot reload) Subscribe to translation updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToTranslationEvents,\n getTranslateListenerKey\n );\n\n /**\n * Remember that we can make no assumptions about when this cb gets invoked\n * - Resolves translation from lookup\n * - enqueues dev hot reload (if needed)\n */\n return useCallback(\n <T extends Translation>(\n lookup: TranslateLookup<T>\n ): TranslateSnapshot<T> => {\n // Track the lookup for dev hot reload\n const lookupKey = getTranslateListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the translation from the store\n const translation = i18nStore.getTranslateSnapshot(\n lookup,\n translationsSnapshot\n );\n\n // Trigger a hot reload if the translation is not found\n if (translation == null && devHotReloadEnabled) {\n onMissingTranslation(lookup);\n }\n return translation;\n },\n [i18nStore, translationsSnapshot, onMissingTranslation, devHotReloadEnabled]\n );\n}\n\n/**\n * Pre-subscribe to compiler-injected lookups\n * trigger translations for them\n *\n * This ref mutation is safe because this is translation hot reload only\n * and effects are deterministic\n */\nfunction usePreloadCompilerLookups(\n messages: Message[],\n trackedKeysRef: RefObject<Set<string> | null>,\n locale: string,\n shouldTranslate: boolean\n) {\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const translationsSnapshot = useTranslationsSnapshot();\n const txHotReloadEnabled = useMemo(() => {\n return messages?.length > 0 && shouldTranslate && devHotReloadEnabled;\n }, [messages, shouldTranslate, devHotReloadEnabled]);\n\n // Precompute as much as we can\n const lookups: [TranslateLookup<string>, string][] = useMemo(() => {\n if (!txHotReloadEnabled) return [];\n return messages.map(({ message, ...options }) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n const lookup = {\n locale: targetLocale,\n message,\n options: lookupOptions,\n };\n return [lookup, getTranslateListenerKey(lookup)];\n });\n }, [locale, txHotReloadEnabled, messages]);\n\n // Pre-subscribe to the lookups\n if (txHotReloadEnabled) {\n lookups.forEach(([, lookupKey]) => {\n trackedKeysRef.current!.add(lookupKey);\n });\n }\n\n /**\n * Delegate non-pure operations to post commit\n *\n * (Optimization) Trigger a hot reload if the translation is not found\n * for compiler-injected lookups\n *\n * TODO: for use() + suspense strategy, use a Promise.all()\n * TODO: server side translation invocation\n */\n useEffect(() => {\n if (!txHotReloadEnabled) return;\n\n lookups\n .filter(\n ([lookup]) =>\n i18nStore.getTranslateSnapshot(lookup, translationsSnapshot) == null\n )\n .forEach(([lookup]) => i18nStore.translate(lookup));\n }, [txHotReloadEnabled, i18nStore, lookups, translationsSnapshot]);\n}\n"],"mappings":"wPA4CA,SAAgB,EACd,EAAsB,EAAE,CACxB,EACA,EAC4B,CAC5B,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EACJC,EAAAA,0CAA0C,EAAgB,CAKtD,GAAA,EAAA,EAAA,QAA4C,KAAK,CAoBvD,MAnBA,CACE,EAAe,UAAU,IAAI,IAI/B,EAA0B,EAAU,EAAgB,EAAQ,EAAgB,CAG5E,EAAA,6BACE,EACA,EAAU,6BACVC,EAAAA,wBACD,EAOD,EAAA,EAAA,aAEI,GACyB,CAEzB,IAAM,GAAA,EAAA,EAAA,yBAAoC,EAAO,CAC7C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAc,EAAU,qBAC5B,EACA,EACD,CAMD,OAHI,GAAe,MAAQ,GACzB,EAAqB,EAAO,CAEvB,GAET,CAAC,EAAW,EAAsB,EAAsB,EAAoB,CAC7E,CAUH,SAAS,EACP,EACA,EACA,EACA,EACA,CACA,IAAM,EAAYF,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAuBD,EAAAA,yBAAyB,CAChD,GAAA,EAAA,EAAA,aACG,GAAU,OAAS,GAAK,GAAmB,EACjD,CAAC,EAAU,EAAiB,EAAoB,CAAC,CAG9C,GAAA,EAAA,EAAA,aACC,EACE,EAAS,KAAK,CAAE,UAAS,GAAG,KAAc,CAC/C,IAAM,EAAe,EAAQ,SAAW,EAMlC,EAAS,CACb,OAAQ,EACR,UACA,SAAA,EAAA,EAAA,qBAPA,EACA,EACA,MAKsB,CACvB,CACD,MAAO,CAAC,GAAA,EAAA,EAAA,yBAAgC,EAAO,CAAC,EAChD,CAd8B,EAAE,CAejC,CAAC,EAAQ,EAAoB,EAAS,CAAC,CAGtC,GACF,EAAQ,SAAS,EAAG,KAAe,CACjC,EAAe,QAAS,IAAI,EAAU,EACtC,EAYJ,EAAA,EAAA,eAAgB,CACT,GAEL,EACG,QACE,CAAC,KACA,EAAU,qBAAqB,EAAQ,EAAqB,EAAI,KACnE,CACA,SAAS,CAAC,KAAY,EAAU,UAAU,EAAO,CAAC,EACpD,CAAC,EAAoB,EAAW,EAAS,EAAqB,CAAC"}
1
+ {"version":3,"file":"useTrackedTranslationResolver.cjs","names":["useTranslationsSnapshot","useI18nStore","useHandleMissingTranslationWithConditions","useSubscribeToTrackedLookups","getTranslateListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedTranslationResolver.ts"],"sourcesContent":["import { type RefObject, useCallback, useEffect, useMemo, useRef } from 'react';\nimport {\n createLookupOptions,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport type { Content } from '@generaltranslation/format/types';\nimport type {\n TranslateLookup,\n TranslateSnapshot,\n} from '../../i18n-store/storeTypes';\nimport type { TranslationMetadata } from 'gt-i18n/internal/types';\nimport type { StringFormat } from '@generaltranslation/format';\nimport {\n useI18nStore,\n useTranslationsSnapshot,\n} from '../../i18n-store/useI18nStore';\nimport { useHandleMissingTranslationWithConditions } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\n/**\n * Returns the translation, but also triggers a translation if it is not found\n * when dev hot reload is enabled.\n */\nexport type TrackedTranslationResolver = <T extends Content>(\n lookup: TranslateLookup<T>\n) => TranslateSnapshot<T>;\n\nexport type Message = TranslationMetadata & {\n message: string;\n};\n\n/**\n * NOTE:\n * gt() may be called during render, so tracking intentionally only mutates\n * hook-local refs. This widens the event filter used by our existing\n * useSyncExternalStore subscription, but does not update React state or mutate\n * the translation cache during render.\n *\n * A render that is later aborted may leave behind an extra tracked key. That is\n * acceptable for dev hot reload because the worst case is an unnecessary\n * invalidation for this hook instance, not incorrect rendered output.\n */\n\nexport function useTrackedTranslationResolver(\n messages: Message[] = [],\n locale: string,\n shouldTranslate: boolean\n): TrackedTranslationResolver {\n const translationsSnapshot = useTranslationsSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingTranslation =\n useHandleMissingTranslationWithConditions(shouldTranslate);\n\n /**\n * Track lookups per hook instance without updating React state during render.\n */\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // (optimization) Pre-subscribe to compiler-injected lookups\n usePreloadCompilerLookups(messages, trackedKeysRef, locale, shouldTranslate);\n\n // (tx hot reload) Subscribe to translation updates\n const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToTranslationEvents,\n getTranslateListenerKey\n );\n\n /**\n * Remember that we can make no assumptions about when this cb gets invoked\n * - Resolves translation from lookup\n * - enqueues dev hot reload (if needed)\n */\n return useCallback(\n <T extends Content>(lookup: TranslateLookup<T>): TranslateSnapshot<T> => {\n // Track the lookup for dev hot reload\n const lookupKey = getTranslateListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the translation from the store\n const translation = i18nStore.getTranslateSnapshot(\n lookup,\n translationsSnapshot\n );\n\n // Trigger a hot reload if the translation is not found\n if (translation == null && devHotReloadEnabled) {\n onMissingTranslation(lookup);\n }\n return translation;\n },\n // trackedLookupsVersion: change identity when a tracked translation arrives\n [\n i18nStore,\n translationsSnapshot,\n onMissingTranslation,\n devHotReloadEnabled,\n trackedLookupsVersion,\n ]\n );\n}\n\n/**\n * Pre-subscribe to compiler-injected lookups\n * trigger translations for them\n *\n * This ref mutation is safe because this is translation hot reload only\n * and effects are deterministic\n */\nfunction usePreloadCompilerLookups(\n messages: Message[],\n trackedKeysRef: RefObject<Set<string> | null>,\n locale: string,\n shouldTranslate: boolean\n) {\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const translationsSnapshot = useTranslationsSnapshot();\n const txHotReloadEnabled = useMemo(() => {\n return messages?.length > 0 && shouldTranslate && devHotReloadEnabled;\n }, [messages, shouldTranslate, devHotReloadEnabled]);\n\n // Precompute as much as we can\n const lookups: [TranslateLookup<string>, string][] = useMemo(() => {\n if (!txHotReloadEnabled) return [];\n return messages.map(({ message, ...options }) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n const lookup = {\n locale: targetLocale,\n message,\n options: lookupOptions,\n };\n return [lookup, getTranslateListenerKey(lookup)];\n });\n }, [locale, txHotReloadEnabled, messages]);\n\n // Pre-subscribe to the lookups\n if (txHotReloadEnabled) {\n lookups.forEach(([, lookupKey]) => {\n trackedKeysRef.current!.add(lookupKey);\n });\n }\n\n /**\n * Delegate non-pure operations to post commit\n *\n * (Optimization) Trigger a hot reload if the translation is not found\n * for compiler-injected lookups\n *\n * TODO: for use() + suspense strategy, use a Promise.all()\n * TODO: server side translation invocation\n */\n useEffect(() => {\n if (!txHotReloadEnabled) return;\n\n lookups\n .filter(\n ([lookup]) =>\n i18nStore.getTranslateSnapshot(lookup, translationsSnapshot) == null\n )\n .forEach(([lookup]) => i18nStore.translate(lookup));\n }, [txHotReloadEnabled, i18nStore, lookups, translationsSnapshot]);\n}\n"],"mappings":"wPA4CA,SAAgB,EACd,EAAsB,EAAE,CACxB,EACA,EAC4B,CAC5B,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EACJC,EAAAA,0CAA0C,EAAgB,CAKtD,GAAA,EAAA,EAAA,QAA4C,KAAK,CAoBvD,MAnBA,CACE,EAAe,UAAU,IAAI,IAI/B,EAA0B,EAAU,EAAgB,EAAQ,EAAgB,EAc5E,EAAA,EAAA,aACsB,GAAqD,CAEvE,IAAM,GAAA,EAAA,EAAA,yBAAoC,EAAO,CAC7C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAc,EAAU,qBAC5B,EACA,EACD,CAMD,OAHI,GAAe,MAAQ,GACzB,EAAqB,EAAO,CAEvB,GAGT,CACE,EACA,EACA,EACA,EApC0BC,EAAAA,6BAC5B,EACA,EAAU,6BACVC,EAAAA,wBAkCuB,CACtB,CACF,CAUH,SAAS,EACP,EACA,EACA,EACA,EACA,CACA,IAAM,EAAYH,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAuBD,EAAAA,yBAAyB,CAChD,GAAA,EAAA,EAAA,aACG,GAAU,OAAS,GAAK,GAAmB,EACjD,CAAC,EAAU,EAAiB,EAAoB,CAAC,CAG9C,GAAA,EAAA,EAAA,aACC,EACE,EAAS,KAAK,CAAE,UAAS,GAAG,KAAc,CAC/C,IAAM,EAAe,EAAQ,SAAW,EAMlC,EAAS,CACb,OAAQ,EACR,UACA,SAAA,EAAA,EAAA,qBAPA,EACA,EACA,MAKsB,CACvB,CACD,MAAO,CAAC,GAAA,EAAA,EAAA,yBAAgC,EAAO,CAAC,EAChD,CAd8B,EAAE,CAejC,CAAC,EAAQ,EAAoB,EAAS,CAAC,CAGtC,GACF,EAAQ,SAAS,EAAG,KAAe,CACjC,EAAe,QAAS,IAAI,EAAU,EACtC,EAYJ,EAAA,EAAA,eAAgB,CACT,GAEL,EACG,QACE,CAAC,KACA,EAAU,qBAAqB,EAAQ,EAAqB,EAAI,KACnE,CACA,SAAS,CAAC,KAAY,EAAU,UAAU,EAAO,CAAC,EACpD,CAAC,EAAoB,EAAW,EAAS,EAAqB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Translation } from "gt-i18n/types";
1
+ import { Content } from "@generaltranslation/format/types";
2
2
  import { TranslationMetadata } from "gt-i18n/internal/types";
3
3
 
4
4
  //#region src/hooks/external-store/useTrackedTranslationResolver.d.ts
@@ -1,2 +1,2 @@
1
- import{useI18nStore as e,useTranslationsSnapshot as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingTranslationWithConditions as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{createLookupOptions as i,getI18nConfig as a,getTranslateListenerKey as o}from"gt-i18n/internal";import{useCallback as s,useEffect as c,useMemo as l,useRef as u}from"react";function d(i=[],c,l){let d=t(),p=e(),m=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),h=n(l),g=u(null);return g.current??=new Set,f(i,g,c,l),r(g,p.subscribeToTranslationEvents,o),s(e=>{let t=o(e);m&&g.current.add(t);let n=p.getTranslateSnapshot(e,d);return n==null&&m&&h(e),n},[p,d,h,m])}function f(n,r,s,u){let d=e(),f=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),p=t(),m=l(()=>n?.length>0&&u&&f,[n,u,f]),h=l(()=>m?n.map(({message:e,...t})=>{let n=t.$locale??s,r={locale:n,message:e,options:i(n,t,`ICU`)};return[r,o(r)]}):[],[s,m,n]);m&&h.forEach(([,e])=>{r.current.add(e)}),c(()=>{m&&h.filter(([e])=>d.getTranslateSnapshot(e,p)==null).forEach(([e])=>d.translate(e))},[m,d,h,p])}export{d as useTrackedTranslationResolver};
1
+ import{useI18nStore as e,useTranslationsSnapshot as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingTranslationWithConditions as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{createLookupOptions as i,getI18nConfig as a,getTranslateListenerKey as o}from"gt-i18n/internal";import{useCallback as s,useEffect as c,useMemo as l,useRef as u}from"react";function d(i=[],c,l){let d=t(),p=e(),m=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),h=n(l),g=u(null);return g.current??=new Set,f(i,g,c,l),s(e=>{let t=o(e);m&&g.current.add(t);let n=p.getTranslateSnapshot(e,d);return n==null&&m&&h(e),n},[p,d,h,m,r(g,p.subscribeToTranslationEvents,o)])}function f(n,r,s,u){let d=e(),f=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),p=t(),m=l(()=>n?.length>0&&u&&f,[n,u,f]),h=l(()=>m?n.map(({message:e,...t})=>{let n=t.$locale??s,r={locale:n,message:e,options:i(n,t,`ICU`)};return[r,o(r)]}):[],[s,m,n]);m&&h.forEach(([,e])=>{r.current.add(e)}),c(()=>{m&&h.filter(([e])=>d.getTranslateSnapshot(e,p)==null).forEach(([e])=>d.translate(e))},[m,d,h,p])}export{d as useTrackedTranslationResolver};
2
2
  //# sourceMappingURL=useTrackedTranslationResolver.mjs.map