@generaltranslation/react-core 11.4.18 → 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.
- package/CHANGELOG.md +57 -0
- package/dist/components-rsc.d.mts +1 -0
- package/dist/components.d.mts +1 -0
- package/dist/context/InternalGTProvider.cjs.map +1 -1
- package/dist/context/InternalGTProvider.d.ts +3 -2
- package/dist/context/InternalGTProvider.d.ts.map +1 -1
- package/dist/context/InternalGTProvider.mjs.map +1 -1
- package/dist/context/context.cjs.map +1 -1
- package/dist/context/context.mjs.map +1 -1
- package/dist/functions/helpers/getTranslationsSnapshot.cjs.map +1 -1
- package/dist/functions/helpers/getTranslationsSnapshot.d.ts +2 -2
- package/dist/functions/helpers/getTranslationsSnapshot.d.ts.map +1 -1
- package/dist/functions/helpers/getTranslationsSnapshot.mjs.map +1 -1
- package/dist/functions/translation/t.cjs.map +1 -1
- package/dist/functions/translation/t.d.ts.map +1 -1
- package/dist/functions/translation/t.mjs.map +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.cjs.map +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.d.ts +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
- package/dist/hooks/external-store.cjs.map +1 -1
- package/dist/hooks/external-store.mjs.map +1 -1
- package/dist/hooks/utils/missing-translation.cjs.map +1 -1
- package/dist/hooks/utils/missing-translation.d.ts +2 -2
- package/dist/hooks/utils/missing-translation.d.ts.map +1 -1
- package/dist/hooks/utils/missing-translation.mjs.map +1 -1
- package/dist/hooks.d.mts +1 -0
- package/dist/i18n-cache/ReactI18nCache.cjs.map +1 -1
- package/dist/i18n-cache/ReactI18nCache.d.ts +2 -2
- package/dist/i18n-cache/ReactI18nCache.d.ts.map +1 -1
- package/dist/i18n-cache/ReactI18nCache.mjs.map +1 -1
- package/dist/i18n-cache/singleton-operations.cjs.map +1 -1
- package/dist/i18n-cache/singleton-operations.mjs.map +1 -1
- package/dist/i18n-store/I18nStore.cjs.map +1 -1
- package/dist/i18n-store/I18nStore.d.ts +6 -5
- package/dist/i18n-store/I18nStore.d.ts.map +1 -1
- package/dist/i18n-store/I18nStore.mjs.map +1 -1
- package/dist/i18n-store/storeTypes.d.ts +4 -3
- package/dist/i18n-store/storeTypes.d.ts.map +1 -1
- package/dist/i18n-store/useI18nStore.cjs.map +1 -1
- package/dist/i18n-store/useI18nStore.mjs.map +1 -1
- package/dist/i18n-store/utils/translations.cjs.map +1 -1
- package/dist/i18n-store/utils/translations.mjs.map +1 -1
- package/dist/pure.d.mts +1 -0
- package/dist/unstable/t.cjs +2 -0
- package/dist/unstable/t.cjs.map +1 -0
- package/dist/unstable/t.d.ts +16 -0
- package/dist/unstable/t.d.ts.map +1 -0
- package/dist/unstable/t.mjs +2 -0
- package/dist/unstable/t.mjs.map +1 -0
- package/dist/unstable/useGT.cjs +2 -0
- package/dist/unstable/useGT.cjs.map +1 -0
- package/dist/unstable/useGT.d.ts +17 -0
- package/dist/unstable/useGT.d.ts.map +1 -0
- package/dist/unstable/useGT.mjs +2 -0
- package/dist/unstable/useGT.mjs.map +1 -0
- package/dist/unstable/useMessages.cjs +2 -0
- package/dist/unstable/useMessages.cjs.map +1 -0
- package/dist/unstable/useMessages.d.ts +16 -0
- package/dist/unstable/useMessages.d.ts.map +1 -0
- package/dist/unstable/useMessages.mjs +2 -0
- package/dist/unstable/useMessages.mjs.map +1 -0
- package/dist/unstable.cjs +1 -0
- package/dist/unstable.d.mts +1 -0
- package/dist/unstable.d.ts +5 -0
- package/dist/unstable.mjs +1 -0
- package/package.json +46 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
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
|
+
|
|
35
|
+
## 12.0.0-samsara.0
|
|
36
|
+
|
|
37
|
+
### Major Changes
|
|
38
|
+
|
|
39
|
+
- bb107a8: Remove `typesVersions`. Subpath types such as `gt-next/server` now resolve only through `exports`, which needs `moduleResolution` `bundler` (TypeScript 5.0+) or `node16`/`nodenext` (TypeScript 4.7+). `moduleResolution` `node` (node10) is no longer supported, including its implicit use with `module: commonjs` in TypeScript 5.9 and earlier and in create-next-app projects from Next.js 13.4.10 and earlier.
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- bb107a8: Fix published type declarations that failed to resolve, or resolved to CommonJS types, under `moduleResolution` `node16` or `nodenext`.
|
|
44
|
+
- Updated dependencies [da7af80]
|
|
45
|
+
- Updated dependencies [bb107a8]
|
|
46
|
+
- Updated dependencies [85eab51]
|
|
47
|
+
- Updated dependencies [002f579]
|
|
48
|
+
- generaltranslation@10.0.0-samsara.0
|
|
49
|
+
- @generaltranslation/format@1.0.0-samsara.1
|
|
50
|
+
- gt-i18n@2.0.0-samsara.0
|
|
51
|
+
|
|
3
52
|
## 11.4.18
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
|
@@ -24,6 +73,14 @@
|
|
|
24
73
|
|
|
25
74
|
## 11.4.15
|
|
26
75
|
|
|
76
|
+
## 11.4.15-samsara.0
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- generaltranslation@9.5.8-samsara.0
|
|
81
|
+
- @generaltranslation/format@0.1.10-samsara.0
|
|
82
|
+
- gt-i18n@1.0.39-samsara.0
|
|
83
|
+
|
|
27
84
|
## 11.4.14
|
|
28
85
|
|
|
29
86
|
## 11.4.13
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components-rsc.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components.js';
|
|
@@ -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
|
|
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
|
|
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,
|
|
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":"
|
|
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
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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,
|
|
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,
|
|
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 {
|
|
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 */\
|
|
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;;;;;
|
|
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 */\
|
|
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 +1 @@
|
|
|
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 {
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTrackedTranslationResolver.mjs","names":[],"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 {
|
|
1
|
+
{"version":3,"file":"useTrackedTranslationResolver.mjs","names":[],"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":"gcA4CA,SAAgB,EACd,EAAsB,EAAE,CACxB,EACA,EAC4B,CAC5B,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EACJ,EAA0C,EAAgB,CAKtD,EAAiB,EAA2B,KAAK,CAoBvD,MAnBA,CACE,EAAe,UAAU,IAAI,IAI/B,EAA0B,EAAU,EAAgB,EAAQ,EAAgB,CAcrE,EACe,GAAqD,CAEvE,IAAM,EAAY,EAAwB,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,EApC0B,EAC5B,EACA,EAAU,6BACV,EAkCuB,CACtB,CACF,CAUH,SAAS,EACP,EACA,EACA,EACA,EACA,CACA,IAAM,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAAuB,GAAyB,CAChD,EAAqB,MAClB,GAAU,OAAS,GAAK,GAAmB,EACjD,CAAC,EAAU,EAAiB,EAAoB,CAAC,CAG9C,EAA+C,MAC9C,EACE,EAAS,KAAK,CAAE,UAAS,GAAG,KAAc,CAC/C,IAAM,EAAe,EAAQ,SAAW,EAMlC,EAAS,CACb,OAAQ,EACR,UACA,QARoB,EACpB,EACA,EACA,MAKsB,CACvB,CACD,MAAO,CAAC,EAAQ,EAAwB,EAAO,CAAC,EAChD,CAd8B,EAAE,CAejC,CAAC,EAAQ,EAAoB,EAAS,CAAC,CAGtC,GACF,EAAQ,SAAS,EAAG,KAAe,CACjC,EAAe,QAAS,IAAI,EAAU,EACtC,CAYJ,MAAgB,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-store.cjs","names":["useI18nStore","useTranslationsSnapshot","useHandleMissingTranslation"],"sources":["../../src/hooks/external-store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type {
|
|
1
|
+
{"version":3,"file":"external-store.cjs","names":["useI18nStore","useTranslationsSnapshot","useHandleMissingTranslation"],"sources":["../../src/hooks/external-store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type { Content } from '@generaltranslation/format/types';\nimport type {\n TranslateLookup,\n TranslateSnapshot,\n} from '../i18n-store/storeTypes';\nimport {\n useI18nStore,\n useTranslationsSnapshot,\n} from '../i18n-store/useI18nStore';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingTranslation } from './utils/missing-translation';\n\n/**\n * @internal\n */\nexport function useTranslate<T extends Content>(\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const i18nStore = useI18nStore();\n const translationsSnapshot = useTranslationsSnapshot();\n const onMissingTranslation = useHandleMissingTranslation();\n\n /**\n * TODO: for snapshot lookup, we can use the translation snapshot\n * to avoid the adapter.resolveTranslation call.\n */\n const storeTranslation = useSyncExternalStore(\n (listener) => i18nStore.subscribeToTranslate(lookup, listener),\n () => i18nStore.getTranslateSnapshot(lookup, translationsSnapshot),\n () => i18nStore.getTranslateSnapshot(lookup, translationsSnapshot)\n );\n\n if (\n process.env.NODE_ENV !== 'production' &&\n storeTranslation == null &&\n getI18nConfig().isDevHotReloadEnabled()\n ) {\n // TODO: (separate PR): add configuration for a use() + suspense strategy\n // TODO: consider moving this to a useEffect\n onMissingTranslation(lookup);\n }\n\n return storeTranslation;\n}\n"],"mappings":"iMAgBA,SAAgB,EACd,EACsB,CACtB,IAAM,EAAYA,EAAAA,cAAc,CAC1B,EAAuBC,EAAAA,yBAAyB,CAChD,EAAuBC,EAAAA,6BAA6B,CAMpD,GAAA,EAAA,EAAA,sBACH,GAAa,EAAU,qBAAqB,EAAQ,EAAS,KACxD,EAAU,qBAAqB,EAAQ,EAAqB,KAC5D,EAAU,qBAAqB,EAAQ,EAAqB,CACnE,CAYD,OATE,QAAQ,IAAI,WAAa,cACzB,GAAoB,OAAA,EAAA,EAAA,gBACL,CAAC,uBAAuB,EAIvC,EAAqB,EAAO,CAGvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-store.mjs","names":[],"sources":["../../src/hooks/external-store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type {
|
|
1
|
+
{"version":3,"file":"external-store.mjs","names":[],"sources":["../../src/hooks/external-store.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type { Content } from '@generaltranslation/format/types';\nimport type {\n TranslateLookup,\n TranslateSnapshot,\n} from '../i18n-store/storeTypes';\nimport {\n useI18nStore,\n useTranslationsSnapshot,\n} from '../i18n-store/useI18nStore';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingTranslation } from './utils/missing-translation';\n\n/**\n * @internal\n */\nexport function useTranslate<T extends Content>(\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const i18nStore = useI18nStore();\n const translationsSnapshot = useTranslationsSnapshot();\n const onMissingTranslation = useHandleMissingTranslation();\n\n /**\n * TODO: for snapshot lookup, we can use the translation snapshot\n * to avoid the adapter.resolveTranslation call.\n */\n const storeTranslation = useSyncExternalStore(\n (listener) => i18nStore.subscribeToTranslate(lookup, listener),\n () => i18nStore.getTranslateSnapshot(lookup, translationsSnapshot),\n () => i18nStore.getTranslateSnapshot(lookup, translationsSnapshot)\n );\n\n if (\n process.env.NODE_ENV !== 'production' &&\n storeTranslation == null &&\n getI18nConfig().isDevHotReloadEnabled()\n ) {\n // TODO: (separate PR): add configuration for a use() + suspense strategy\n // TODO: consider moving this to a useEffect\n onMissingTranslation(lookup);\n }\n\n return storeTranslation;\n}\n"],"mappings":"uQAgBA,SAAgB,EACd,EACsB,CACtB,IAAM,EAAY,GAAc,CAC1B,EAAuB,GAAyB,CAChD,EAAuB,GAA6B,CAMpD,EAAmB,EACtB,GAAa,EAAU,qBAAqB,EAAQ,EAAS,KACxD,EAAU,qBAAqB,EAAQ,EAAqB,KAC5D,EAAU,qBAAqB,EAAQ,EAAqB,CACnE,CAYD,OATE,QAAQ,IAAI,WAAa,cACzB,GAAoB,MACpB,GAAe,CAAC,uBAAuB,EAIvC,EAAqB,EAAO,CAGvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missing-translation.cjs","names":["useShouldTranslate","useGTContext","useI18nStore"],"sources":["../../../src/hooks/utils/missing-translation.ts"],"sourcesContent":["import {\n getDictionaryListenerKey,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport { useShouldTranslate } from '../utils';\nimport { useI18nStore } from '../../i18n-store/useI18nStore';\nimport { DictionaryLookup, TranslateLookup } from '../../i18n-store/storeTypes';\nimport { useCallback, useEffect, useRef } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"missing-translation.cjs","names":["useShouldTranslate","useGTContext","useI18nStore"],"sources":["../../../src/hooks/utils/missing-translation.ts"],"sourcesContent":["import {\n getDictionaryListenerKey,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport { useShouldTranslate } from '../utils';\nimport { useI18nStore } from '../../i18n-store/useI18nStore';\nimport { DictionaryLookup, TranslateLookup } from '../../i18n-store/storeTypes';\nimport { useCallback, useEffect, useRef } from 'react';\nimport type { Content } from '@generaltranslation/format/types';\nimport { useGTContext } from '../../context/context';\n\nexport type OnMissingTranslation = <T extends Content>(\n lookup: TranslateLookup<T>\n) => void;\nexport type OnMissingDictionaryEntry = (lookup: DictionaryLookup) => void;\n// TODO: rename to OnMissingDictionaryObject\nexport type OnMissingDictionaryObj = (lookup: DictionaryLookup) => void;\n\ntype PendingLookup =\n | {\n type: 'translation';\n lookup: TranslateLookup;\n }\n | {\n type: 'dictionaryEntry' | 'dictionaryObject';\n lookup: DictionaryLookup;\n };\n\n/**\n * Why have custom handleMissing functions?\n *\n * Some runtimes (like server) cannot make useEffect calls, so\n * we need to give them access to a callback where they can embed\n * their own translation calls\n *\n * While this is technnically not pure behavior, this is acceptable\n * in development hot reload\n */\n\nconst noopOnMissingTranslation: OnMissingTranslation = () => {};\nconst noopOnMissingDictionaryEntry: OnMissingDictionaryEntry = () => {};\nconst noopOnMissingDictionaryObj: OnMissingDictionaryObj = () => {};\n\n// TODO: reduce code duplication with the three below functions\nfunction useHandleMissingTranslationProd(): OnMissingTranslation {\n return noopOnMissingTranslation;\n}\n\nfunction useHandleMissingTranslationDev(): OnMissingTranslation {\n return useHandleMissingTranslationWithConditionsDev(useShouldTranslate());\n}\n\nfunction useHandleMissingTranslationWithConditionsDev(\n shouldTranslate: boolean\n): OnMissingTranslation {\n const customHandleMissing = useGTContext()?.onMissingTranslation;\n const pureHandleMissing = useDevHotReloadQueue(shouldTranslate);\n\n return useCallback(\n (lookup: TranslateLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getTranslateListenerKey(lookup), {\n type: 'translation',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nfunction useHandleMissingDictionaryEntryProd(): OnMissingDictionaryEntry {\n return noopOnMissingDictionaryEntry;\n}\n\nfunction useHandleMissingDictionaryEntryDev(): OnMissingDictionaryEntry {\n const customHandleMissing = useGTContext()?.onMissingDictionaryEntry;\n const pureHandleMissing = useDevHotReloadQueue(useShouldTranslate());\n\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryEntry',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nfunction useHandleMissingDictionaryObjectProd(): OnMissingDictionaryObj {\n return noopOnMissingDictionaryObj;\n}\n\nfunction useHandleMissingDictionaryObjectDev(): OnMissingDictionaryObj {\n const customHandleMissing = useGTContext()?.onMissingDictionaryObj;\n const pureHandleMissing = useDevHotReloadQueue(useShouldTranslate());\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryObject',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nexport const useHandleMissingTranslation: () => OnMissingTranslation =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingTranslationProd\n : useHandleMissingTranslationDev;\n\nexport const useHandleMissingTranslationWithConditions: (\n shouldTranslate: boolean\n) => OnMissingTranslation =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingTranslationProd\n : useHandleMissingTranslationWithConditionsDev;\n\nexport const useHandleMissingDictionaryEntry: () => OnMissingDictionaryEntry =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryEntryProd\n : useHandleMissingDictionaryEntryDev;\n\nexport const useHandleMissingDictionaryObject: () => OnMissingDictionaryObj =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryObjectProd\n : useHandleMissingDictionaryObjectDev;\n\n/**\n * HMR translation needs to be deferred to post-commit phase\n */\nfunction useDevHotReloadQueue(shouldTranslate: boolean) {\n // Statically gated so bundlers can drop dev hot-reload work from\n // production builds.\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const i18nStore = useI18nStore();\n\n // Persist the queue across renders so the enqueue callback keeps a stable\n // identity. An unstable callback would change the identity of every\n // translation function built on top of it (e.g. gt() from useGT()), which\n // re-runs user effects that depend on it after every render.\n const pendingLookupsRef = useRef<Map<string, PendingLookup> | null>(null);\n if (pendingLookupsRef.current == null) {\n pendingLookupsRef.current = new Map();\n }\n\n // Pure react: effects run after render\n // No dependency array: flush whatever was enqueued after every commit\n useEffect(() => {\n const pendingLookups = pendingLookupsRef.current!;\n if (pendingLookups.size === 0) return;\n const lookups = Array.from(pendingLookups.values());\n pendingLookups.clear();\n if (!devHotReloadEnabled || !shouldTranslate) return;\n\n lookups.forEach(({ type, lookup }) => {\n switch (type) {\n case 'translation':\n i18nStore.translate(lookup);\n break;\n case 'dictionaryEntry':\n i18nStore.translateDictionaryEntry(lookup);\n break;\n case 'dictionaryObject':\n i18nStore.translateDictionaryObject(lookup);\n break;\n }\n });\n });\n\n return useCallback((key: string, pendingLookup: PendingLookup) => {\n pendingLookupsRef.current!.set(key, pendingLookup);\n }, []);\n}\n"],"mappings":"2NAwCA,MAAM,MAAuD,GACvD,MAA+D,GAC/D,MAA2D,GAGjE,SAAS,GAAwD,CAC/D,OAAO,EAGT,SAAS,GAAuD,CAC9D,OAAO,EAA6CA,EAAAA,oBAAoB,CAAC,CAG3E,SAAS,EACP,EACsB,CACtB,IAAM,EAAsBC,EAAAA,cAAc,EAAE,qBACtC,EAAoB,EAAqB,EAAgB,CAE/D,OAAA,EAAA,EAAA,aACG,GAA4B,CACvB,EACF,EAAoB,EAAO,CAE3B,GAAA,EAAA,EAAA,yBAA0C,EAAO,CAAE,CACjD,KAAM,cACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,SAAS,GAAgE,CACvE,OAAO,EAGT,SAAS,GAA+D,CACtE,IAAM,EAAsBA,EAAAA,cAAc,EAAE,yBACtC,EAAoB,EAAqBD,EAAAA,oBAAoB,CAAC,CAEpE,OAAA,EAAA,EAAA,aACG,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,GAAA,EAAA,EAAA,0BAA2C,EAAO,CAAE,CAClD,KAAM,kBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,SAAS,GAA+D,CACtE,OAAO,EAGT,SAAS,GAA8D,CACrE,IAAM,EAAsBC,EAAAA,cAAc,EAAE,uBACtC,EAAoB,EAAqBD,EAAAA,oBAAoB,CAAC,CACpE,OAAA,EAAA,EAAA,aACG,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,GAAA,EAAA,EAAA,0BAA2C,EAAO,CAAE,CAClD,KAAM,mBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,MAAa,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EAGX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAKN,SAAS,EAAqB,EAA0B,CAGtD,IAAM,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAYE,EAAAA,cAAc,CAM1B,GAAA,EAAA,EAAA,QAA8D,KAAK,CA6BzE,MA5BA,CACE,EAAkB,UAAU,IAAI,KAKlC,EAAA,EAAA,eAAgB,CACd,IAAM,EAAiB,EAAkB,QACzC,GAAI,EAAe,OAAS,EAAG,OAC/B,IAAM,EAAU,MAAM,KAAK,EAAe,QAAQ,CAAC,CACnD,EAAe,OAAO,CAClB,GAAC,GAAuB,CAAC,IAE7B,EAAQ,SAAS,CAAE,OAAM,YAAa,CACpC,OAAQ,EAAR,CACE,IAAK,cACH,EAAU,UAAU,EAAO,CAC3B,MACF,IAAK,kBACH,EAAU,yBAAyB,EAAO,CAC1C,MACF,IAAK,mBACH,EAAU,0BAA0B,EAAO,CAC3C,QAEJ,EACF,EAEF,EAAA,EAAA,cAAoB,EAAa,IAAiC,CAChE,EAAkB,QAAS,IAAI,EAAK,EAAc,EACjD,EAAE,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DictionaryLookup, TranslateLookup } from "../../i18n-store/storeTypes.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Content } from "@generaltranslation/format/types";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/utils/missing-translation.d.ts
|
|
5
|
-
type OnMissingTranslation = <T extends
|
|
5
|
+
type OnMissingTranslation = <T extends Content>(lookup: TranslateLookup<T>) => void;
|
|
6
6
|
type OnMissingDictionaryEntry = (lookup: DictionaryLookup) => void;
|
|
7
7
|
type OnMissingDictionaryObj = (lookup: DictionaryLookup) => void;
|
|
8
8
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missing-translation.d.ts","names":[],"sources":["../../../src/hooks/utils/missing-translation.ts"],"mappings":";;;;KAYY,oBAAA,cAAkC,
|
|
1
|
+
{"version":3,"file":"missing-translation.d.ts","names":[],"sources":["../../../src/hooks/utils/missing-translation.ts"],"mappings":";;;;KAYY,oBAAA,cAAkC,OAAA,EAC5C,MAAA,EAAQ,eAAA,CAAgB,CAAA;AAAA,KAEd,wBAAA,IAA4B,MAAA,EAAQ,gBAAA;AAAA,KAEpC,sBAAA,IAA0B,MAAA,EAAQ,gBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missing-translation.mjs","names":[],"sources":["../../../src/hooks/utils/missing-translation.ts"],"sourcesContent":["import {\n getDictionaryListenerKey,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport { useShouldTranslate } from '../utils';\nimport { useI18nStore } from '../../i18n-store/useI18nStore';\nimport { DictionaryLookup, TranslateLookup } from '../../i18n-store/storeTypes';\nimport { useCallback, useEffect, useRef } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"missing-translation.mjs","names":[],"sources":["../../../src/hooks/utils/missing-translation.ts"],"sourcesContent":["import {\n getDictionaryListenerKey,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport { useShouldTranslate } from '../utils';\nimport { useI18nStore } from '../../i18n-store/useI18nStore';\nimport { DictionaryLookup, TranslateLookup } from '../../i18n-store/storeTypes';\nimport { useCallback, useEffect, useRef } from 'react';\nimport type { Content } from '@generaltranslation/format/types';\nimport { useGTContext } from '../../context/context';\n\nexport type OnMissingTranslation = <T extends Content>(\n lookup: TranslateLookup<T>\n) => void;\nexport type OnMissingDictionaryEntry = (lookup: DictionaryLookup) => void;\n// TODO: rename to OnMissingDictionaryObject\nexport type OnMissingDictionaryObj = (lookup: DictionaryLookup) => void;\n\ntype PendingLookup =\n | {\n type: 'translation';\n lookup: TranslateLookup;\n }\n | {\n type: 'dictionaryEntry' | 'dictionaryObject';\n lookup: DictionaryLookup;\n };\n\n/**\n * Why have custom handleMissing functions?\n *\n * Some runtimes (like server) cannot make useEffect calls, so\n * we need to give them access to a callback where they can embed\n * their own translation calls\n *\n * While this is technnically not pure behavior, this is acceptable\n * in development hot reload\n */\n\nconst noopOnMissingTranslation: OnMissingTranslation = () => {};\nconst noopOnMissingDictionaryEntry: OnMissingDictionaryEntry = () => {};\nconst noopOnMissingDictionaryObj: OnMissingDictionaryObj = () => {};\n\n// TODO: reduce code duplication with the three below functions\nfunction useHandleMissingTranslationProd(): OnMissingTranslation {\n return noopOnMissingTranslation;\n}\n\nfunction useHandleMissingTranslationDev(): OnMissingTranslation {\n return useHandleMissingTranslationWithConditionsDev(useShouldTranslate());\n}\n\nfunction useHandleMissingTranslationWithConditionsDev(\n shouldTranslate: boolean\n): OnMissingTranslation {\n const customHandleMissing = useGTContext()?.onMissingTranslation;\n const pureHandleMissing = useDevHotReloadQueue(shouldTranslate);\n\n return useCallback(\n (lookup: TranslateLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getTranslateListenerKey(lookup), {\n type: 'translation',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nfunction useHandleMissingDictionaryEntryProd(): OnMissingDictionaryEntry {\n return noopOnMissingDictionaryEntry;\n}\n\nfunction useHandleMissingDictionaryEntryDev(): OnMissingDictionaryEntry {\n const customHandleMissing = useGTContext()?.onMissingDictionaryEntry;\n const pureHandleMissing = useDevHotReloadQueue(useShouldTranslate());\n\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryEntry',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nfunction useHandleMissingDictionaryObjectProd(): OnMissingDictionaryObj {\n return noopOnMissingDictionaryObj;\n}\n\nfunction useHandleMissingDictionaryObjectDev(): OnMissingDictionaryObj {\n const customHandleMissing = useGTContext()?.onMissingDictionaryObj;\n const pureHandleMissing = useDevHotReloadQueue(useShouldTranslate());\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryObject',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nexport const useHandleMissingTranslation: () => OnMissingTranslation =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingTranslationProd\n : useHandleMissingTranslationDev;\n\nexport const useHandleMissingTranslationWithConditions: (\n shouldTranslate: boolean\n) => OnMissingTranslation =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingTranslationProd\n : useHandleMissingTranslationWithConditionsDev;\n\nexport const useHandleMissingDictionaryEntry: () => OnMissingDictionaryEntry =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryEntryProd\n : useHandleMissingDictionaryEntryDev;\n\nexport const useHandleMissingDictionaryObject: () => OnMissingDictionaryObj =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryObjectProd\n : useHandleMissingDictionaryObjectDev;\n\n/**\n * HMR translation needs to be deferred to post-commit phase\n */\nfunction useDevHotReloadQueue(shouldTranslate: boolean) {\n // Statically gated so bundlers can drop dev hot-reload work from\n // production builds.\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const i18nStore = useI18nStore();\n\n // Persist the queue across renders so the enqueue callback keeps a stable\n // identity. An unstable callback would change the identity of every\n // translation function built on top of it (e.g. gt() from useGT()), which\n // re-runs user effects that depend on it after every render.\n const pendingLookupsRef = useRef<Map<string, PendingLookup> | null>(null);\n if (pendingLookupsRef.current == null) {\n pendingLookupsRef.current = new Map();\n }\n\n // Pure react: effects run after render\n // No dependency array: flush whatever was enqueued after every commit\n useEffect(() => {\n const pendingLookups = pendingLookupsRef.current!;\n if (pendingLookups.size === 0) return;\n const lookups = Array.from(pendingLookups.values());\n pendingLookups.clear();\n if (!devHotReloadEnabled || !shouldTranslate) return;\n\n lookups.forEach(({ type, lookup }) => {\n switch (type) {\n case 'translation':\n i18nStore.translate(lookup);\n break;\n case 'dictionaryEntry':\n i18nStore.translateDictionaryEntry(lookup);\n break;\n case 'dictionaryObject':\n i18nStore.translateDictionaryObject(lookup);\n break;\n }\n });\n });\n\n return useCallback((key: string, pendingLookup: PendingLookup) => {\n pendingLookupsRef.current!.set(key, pendingLookup);\n }, []);\n}\n"],"mappings":"uVAwCA,MAAM,MAAuD,GACvD,MAA+D,GAC/D,MAA2D,GAGjE,SAAS,GAAwD,CAC/D,OAAO,EAGT,SAAS,GAAuD,CAC9D,OAAO,EAA6C,GAAoB,CAAC,CAG3E,SAAS,EACP,EACsB,CACtB,IAAM,EAAsB,GAAc,EAAE,qBACtC,EAAoB,EAAqB,EAAgB,CAE/D,OAAO,EACJ,GAA4B,CACvB,EACF,EAAoB,EAAO,CAE3B,EAAkB,EAAwB,EAAO,CAAE,CACjD,KAAM,cACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,SAAS,GAAgE,CACvE,OAAO,EAGT,SAAS,GAA+D,CACtE,IAAM,EAAsB,GAAc,EAAE,yBACtC,EAAoB,EAAqB,GAAoB,CAAC,CAEpE,OAAO,EACJ,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,EAAkB,EAAyB,EAAO,CAAE,CAClD,KAAM,kBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,SAAS,GAA+D,CACtE,OAAO,EAGT,SAAS,GAA8D,CACrE,IAAM,EAAsB,GAAc,EAAE,uBACtC,EAAoB,EAAqB,GAAoB,CAAC,CACpE,OAAO,EACJ,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,EAAkB,EAAyB,EAAO,CAAE,CAClD,KAAM,mBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,MAAa,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EAGX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAKN,SAAS,EAAqB,EAA0B,CAGtD,IAAM,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAAY,GAAc,CAM1B,EAAoB,EAA0C,KAAK,CA6BzE,MA5BA,CACE,EAAkB,UAAU,IAAI,IAKlC,MAAgB,CACd,IAAM,EAAiB,EAAkB,QACzC,GAAI,EAAe,OAAS,EAAG,OAC/B,IAAM,EAAU,MAAM,KAAK,EAAe,QAAQ,CAAC,CACnD,EAAe,OAAO,CAClB,GAAC,GAAuB,CAAC,IAE7B,EAAQ,SAAS,CAAE,OAAM,YAAa,CACpC,OAAQ,EAAR,CACE,IAAK,cACH,EAAU,UAAU,EAAO,CAC3B,MACF,IAAK,kBACH,EAAU,yBAAyB,EAAO,CAC1C,MACF,IAAK,mBACH,EAAU,0BAA0B,EAAO,CAC3C,QAEJ,EACF,CAEK,GAAa,EAAa,IAAiC,CAChE,EAAkB,QAAS,IAAI,EAAK,EAAc,EACjD,EAAE,CAAC"}
|
package/dist/hooks.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactI18nCache.cjs","names":["I18nCache"],"sources":["../../src/i18n-cache/ReactI18nCache.ts"],"sourcesContent":["import { I18nCache } from 'gt-i18n/internal';\nimport type { I18nCacheConstructorParams } from 'gt-i18n/internal/types';\nimport type {
|
|
1
|
+
{"version":3,"file":"ReactI18nCache.cjs","names":["I18nCache"],"sources":["../../src/i18n-cache/ReactI18nCache.ts"],"sourcesContent":["import { I18nCache } from 'gt-i18n/internal';\nimport type { I18nCacheConstructorParams } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\n\nexport class ReactI18nCache extends I18nCache<Content> {}\nexport type ReactI18nCacheParams = I18nCacheConstructorParams;\n"],"mappings":"+EAIA,IAAa,EAAb,cAAoCA,EAAAA,SAAmB"}
|