@generaltranslation/react-core 12.0.0-samsara.5 → 12.0.0-samsara.7
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 +47 -0
- package/dist/components/translation/T.cjs +1 -1
- package/dist/components/translation/T.cjs.map +1 -1
- package/dist/components/translation/T.mjs +1 -1
- package/dist/components/translation/T.mjs.map +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.cjs +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.cjs.map +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.mjs +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
- package/dist/hooks/useGT.cjs +1 -1
- package/dist/hooks/useGT.cjs.map +1 -1
- package/dist/hooks/useGT.d.ts +2 -3
- package/dist/hooks/useGT.d.ts.map +1 -1
- package/dist/hooks/useGT.mjs +1 -1
- package/dist/hooks/useGT.mjs.map +1 -1
- package/dist/hooks/useMessages.cjs.map +1 -1
- package/dist/hooks/useMessages.d.ts +2 -3
- package/dist/hooks/useMessages.d.ts.map +1 -1
- package/dist/hooks/useMessages.mjs.map +1 -1
- package/dist/i18n-store/I18nStore.cjs +1 -1
- package/dist/i18n-store/I18nStore.cjs.map +1 -1
- package/dist/i18n-store/I18nStore.mjs +1 -1
- package/dist/i18n-store/I18nStore.mjs.map +1 -1
- package/dist/i18n-store/storeTypes.d.ts +1 -1
- package/dist/i18n-store/utils/translations.cjs +1 -1
- package/dist/i18n-store/utils/translations.cjs.map +1 -1
- package/dist/i18n-store/utils/translations.mjs +1 -1
- package/dist/i18n-store/utils/translations.mjs.map +1 -1
- package/dist/unstable/useGT.cjs +1 -1
- package/dist/unstable/useGT.cjs.map +1 -1
- package/dist/unstable/useGT.mjs +1 -1
- package/dist/unstable/useGT.mjs.map +1 -1
- package/dist/unstable/useMessages.cjs +1 -1
- package/dist/unstable/useMessages.cjs.map +1 -1
- package/dist/unstable/useMessages.mjs +1 -1
- package/dist/unstable/useMessages.mjs.map +1 -1
- package/dist/utils/translation/resolveTagHash.cjs +1 -1
- package/dist/utils/translation/resolveTagHash.cjs.map +1 -1
- package/dist/utils/translation/resolveTagHash.mjs +1 -1
- package/dist/utils/translation/resolveTagHash.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/hooks/external-store/useTrackedTranslationResolver.d.ts +0 -10
- package/dist/hooks/external-store/useTrackedTranslationResolver.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @generaltranslation/react-core
|
|
2
2
|
|
|
3
|
+
## 12.0.0-samsara.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [27c26cd]
|
|
8
|
+
- Updated dependencies [27c26cd]
|
|
9
|
+
- gt-i18n@2.0.0-samsara.7
|
|
10
|
+
- @generaltranslation/format@1.0.0-samsara.7
|
|
11
|
+
- generaltranslation@10.0.0-samsara.7
|
|
12
|
+
|
|
13
|
+
## 12.0.0-samsara.6
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- f88a4dc: Rename the `message` field of translation lookups to `content`, to match `GLOSSARY.md`: it holds content in any data format, JSX and message trees included, not only string messages. No behavior changes.
|
|
18
|
+
- `gt-i18n/internal`: the variant of `TranslateListenerLookup` that carries the source is `{ locale, content, options }`; the `{ locale, hash }` variant is unchanged. The entries passed to a lookup's `prefetchEntries` are `{ content, options }`.
|
|
19
|
+
- `@generaltranslation/react-core`: `TranslateLookup` is `{ locale, content, options }`.
|
|
20
|
+
|
|
21
|
+
`RegisteredMessage.message` is unchanged: it is a string message.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- ada6894: Rename three names to match `GLOSSARY.md`. No behavior changes.
|
|
26
|
+
- The `Message` type in `gt-i18n/types`, a string message with its metadata as passed to `getGT()` and `useGT()`, is now `RegisteredMessage`. `Message` is left to mean a message tree and its formats.
|
|
27
|
+
- `hashMessage` in `gt-i18n/internal` is now `hashContent`: it hashes content in any data format, JSX included.
|
|
28
|
+
- `LocaleConfig.formatMessageTree()` takes the data for its variables as `values`, not `variables`, as `formatMessageTree` does everywhere else. This also applies to `LocaleConfig` in `generaltranslation` and `I18nConfig` in `gt-i18n`.
|
|
29
|
+
|
|
30
|
+
- 067e175: `gt-next` and `@generaltranslation/react-core` use `RegisteredMessage` from `gt-i18n/types` instead of declaring their own copies. The copy in `gt-next` had fallen behind, so the messages passed to its `useGT()` and `useMessages()` now also accept `$format`, `$locale` and `$requiresReview`.
|
|
31
|
+
- Updated dependencies [6440bd1]
|
|
32
|
+
- Updated dependencies [f88a4dc]
|
|
33
|
+
- Updated dependencies [8dde4bb]
|
|
34
|
+
- Updated dependencies [ada6894]
|
|
35
|
+
- @generaltranslation/format@1.0.0-samsara.6
|
|
36
|
+
- generaltranslation@10.0.0-samsara.6
|
|
37
|
+
- gt-i18n@2.0.0-samsara.6
|
|
38
|
+
|
|
3
39
|
## 12.0.0-samsara.5
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
|
@@ -89,6 +125,17 @@
|
|
|
89
125
|
- @generaltranslation/format@1.0.0-samsara.1
|
|
90
126
|
- gt-i18n@2.0.0-samsara.0
|
|
91
127
|
|
|
128
|
+
## 11.4.22
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- Updated dependencies [[`7aae545`](https://github.com/generaltranslation/gt/commit/7aae545bd9e65148b8cbf98a4df3ce750ab1cdbf)]:
|
|
133
|
+
- @generaltranslation/format@0.1.10
|
|
134
|
+
- generaltranslation@9.5.12
|
|
135
|
+
- gt-i18n@1.0.43
|
|
136
|
+
|
|
137
|
+
## 11.4.21
|
|
138
|
+
|
|
92
139
|
## 11.4.20
|
|
93
140
|
|
|
94
141
|
### Patch Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../hooks/external-store.cjs`),t=require(`../../utils/rendering/renderPipeline.cjs`),n=require(`../../utils/translation/usePrepareT.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(e){return s(e)}function o(e){return s(e)}a._gtt=`translate-client`,o._gtt=`translate-client-automatic`;function s({children:a,_locale:o,_enableI18n:s,_renderPreparedT:c=t.renderPreparedT,...l}){let{defaultLocale:u,locale:d,enableI18n:f,targetOptions:p,taggedSourceChildren:m,sourceJsxChildren:h,shouldTranslate:g}=n.usePrepareT({sourceChildren:a,params:l,_locale:o,_enableI18n:s}),_=e.useTranslate({locale:d,
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../hooks/external-store.cjs`),t=require(`../../utils/rendering/renderPipeline.cjs`),n=require(`../../utils/translation/usePrepareT.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(e){return s(e)}function o(e){return s(e)}a._gtt=`translate-client`,o._gtt=`translate-client-automatic`;function s({children:a,_locale:o,_enableI18n:s,_renderPreparedT:c=t.renderPreparedT,...l}){let{defaultLocale:u,locale:d,enableI18n:f,targetOptions:p,taggedSourceChildren:m,sourceJsxChildren:h,shouldTranslate:g}=n.usePrepareT({sourceChildren:a,params:l,_locale:o,_enableI18n:s}),_=e.useTranslate({locale:d,content:h,options:p}),v=(0,i.useRef)(null);if(process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled()&&_==null&&v.current!=null&&g)return v.current;let y=c({taggedSourceChildren:m,targetJsxChildren:_,locale:d,defaultLocale:u,enableI18n:f,shouldTranslate:g,hash:p.$_hash});return v.current=y,y}exports.GtInternalTranslateJsx=o,exports.T=a;
|
|
2
2
|
//# sourceMappingURL=T.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"T.cjs","names":["renderPreparedT","usePrepareT","useTranslate"],"sources":["../../../src/components/translation/T.tsx"],"sourcesContent":["import { useTranslate } from '../../hooks/external-store';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { useRef, type ReactNode } from 'react';\nimport { renderPreparedT } from '../../utils/rendering/renderPipeline';\nimport type { TProps } from '../../utils/translation/prepareT.shared';\nimport { usePrepareT } from '../../utils/translation/usePrepareT';\n\n// ===== Component ===== //\n\n/**\n * External-store version of the `<T>` component.\n */\nfunction T(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\nfunction GtInternalTranslateJsx(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\n/** @internal _gtt - The GT transformation for the component. */\nT._gtt = 'translate-client';\nGtInternalTranslateJsx._gtt = 'translate-client-automatic';\n\nexport { GtInternalTranslateJsx, T };\n\n/**\n * Render logic\n */\nfunction useComputeT({\n children: sourceChildren,\n _locale,\n _enableI18n,\n _renderPreparedT = renderPreparedT,\n ...params\n}: TProps): ReactNode {\n // Prepare our source children for rendering\n const {\n defaultLocale,\n locale,\n enableI18n,\n targetOptions,\n taggedSourceChildren,\n sourceJsxChildren,\n shouldTranslate,\n } = usePrepareT({\n sourceChildren,\n params,\n _locale,\n _enableI18n,\n });\n\n // Lookup translation in cache\n const targetJsxChildren = useTranslate({\n locale,\n
|
|
1
|
+
{"version":3,"file":"T.cjs","names":["renderPreparedT","usePrepareT","useTranslate"],"sources":["../../../src/components/translation/T.tsx"],"sourcesContent":["import { useTranslate } from '../../hooks/external-store';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { useRef, type ReactNode } from 'react';\nimport { renderPreparedT } from '../../utils/rendering/renderPipeline';\nimport type { TProps } from '../../utils/translation/prepareT.shared';\nimport { usePrepareT } from '../../utils/translation/usePrepareT';\n\n// ===== Component ===== //\n\n/**\n * External-store version of the `<T>` component.\n */\nfunction T(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\nfunction GtInternalTranslateJsx(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\n/** @internal _gtt - The GT transformation for the component. */\nT._gtt = 'translate-client';\nGtInternalTranslateJsx._gtt = 'translate-client-automatic';\n\nexport { GtInternalTranslateJsx, T };\n\n/**\n * Render logic\n */\nfunction useComputeT({\n children: sourceChildren,\n _locale,\n _enableI18n,\n _renderPreparedT = renderPreparedT,\n ...params\n}: TProps): ReactNode {\n // Prepare our source children for rendering\n const {\n defaultLocale,\n locale,\n enableI18n,\n targetOptions,\n taggedSourceChildren,\n sourceJsxChildren,\n shouldTranslate,\n } = usePrepareT({\n sourceChildren,\n params,\n _locale,\n _enableI18n,\n });\n\n // Lookup translation in cache\n const targetJsxChildren = useTranslate({\n locale,\n content: sourceJsxChildren,\n options: targetOptions,\n });\n\n // Tx hot reload: render previous translation while loading new one\n // TODO: account for success vs loading vs failed request states\n const prev = useRef<ReactNode | null>(null);\n if (\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled() &&\n targetJsxChildren == null &&\n prev.current != null &&\n shouldTranslate\n ) {\n return prev.current;\n }\n\n const result = _renderPreparedT({\n taggedSourceChildren,\n targetJsxChildren,\n locale,\n defaultLocale,\n enableI18n,\n shouldTranslate,\n hash: targetOptions.$_hash,\n });\n\n // record previous result\n prev.current = result;\n\n return result;\n}\n"],"mappings":"kQAYA,SAAS,EAAE,EAA0B,CACnC,OAAO,EAAY,EAAM,CAG3B,SAAS,EAAuB,EAA0B,CACxD,OAAO,EAAY,EAAM,CAI3B,EAAE,KAAO,mBACT,EAAuB,KAAO,6BAO9B,SAAS,EAAY,CACnB,SAAU,EACV,UACA,cACA,mBAAmBA,EAAAA,gBACnB,GAAG,GACiB,CAEpB,GAAM,CACJ,gBACA,SACA,aACA,gBACA,uBACA,oBACA,mBACEC,EAAAA,YAAY,CACd,iBACA,SACA,UACA,cACD,CAAC,CAGI,EAAoBC,EAAAA,aAAa,CACrC,SACA,QAAS,EACT,QAAS,EACV,CAAC,CAII,GAAA,EAAA,EAAA,QAAgC,KAAK,CAC3C,GACE,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,EACvC,GAAqB,MACrB,EAAK,SAAW,MAChB,EAEA,OAAO,EAAK,QAGd,IAAM,EAAS,EAAiB,CAC9B,uBACA,oBACA,SACA,gBACA,aACA,kBACA,KAAM,EAAc,OACrB,CAAC,CAKF,MAFA,GAAK,QAAU,EAER"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useTranslate as e}from"../../hooks/external-store.mjs";import{renderPreparedT as t}from"../../utils/rendering/renderPipeline.mjs";import{usePrepareT as n}from"../../utils/translation/usePrepareT.mjs";import{getI18nConfig as r}from"gt-i18n/internal";import{useRef as i}from"react";function a(e){return s(e)}function o(e){return s(e)}a._gtt=`translate-client`,o._gtt=`translate-client-automatic`;function s({children:a,_locale:o,_enableI18n:s,_renderPreparedT:c=t,...l}){let{defaultLocale:u,locale:d,enableI18n:f,targetOptions:p,taggedSourceChildren:m,sourceJsxChildren:h,shouldTranslate:g}=n({sourceChildren:a,params:l,_locale:o,_enableI18n:s}),_=e({locale:d,
|
|
1
|
+
import{useTranslate as e}from"../../hooks/external-store.mjs";import{renderPreparedT as t}from"../../utils/rendering/renderPipeline.mjs";import{usePrepareT as n}from"../../utils/translation/usePrepareT.mjs";import{getI18nConfig as r}from"gt-i18n/internal";import{useRef as i}from"react";function a(e){return s(e)}function o(e){return s(e)}a._gtt=`translate-client`,o._gtt=`translate-client-automatic`;function s({children:a,_locale:o,_enableI18n:s,_renderPreparedT:c=t,...l}){let{defaultLocale:u,locale:d,enableI18n:f,targetOptions:p,taggedSourceChildren:m,sourceJsxChildren:h,shouldTranslate:g}=n({sourceChildren:a,params:l,_locale:o,_enableI18n:s}),_=e({locale:d,content:h,options:p}),v=i(null);if(process.env.NODE_ENV!==`production`&&r().isDevHotReloadEnabled()&&_==null&&v.current!=null&&g)return v.current;let y=c({taggedSourceChildren:m,targetJsxChildren:_,locale:d,defaultLocale:u,enableI18n:f,shouldTranslate:g,hash:p.$_hash});return v.current=y,y}export{o as GtInternalTranslateJsx,a as T};
|
|
2
2
|
//# sourceMappingURL=T.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"T.mjs","names":[],"sources":["../../../src/components/translation/T.tsx"],"sourcesContent":["import { useTranslate } from '../../hooks/external-store';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { useRef, type ReactNode } from 'react';\nimport { renderPreparedT } from '../../utils/rendering/renderPipeline';\nimport type { TProps } from '../../utils/translation/prepareT.shared';\nimport { usePrepareT } from '../../utils/translation/usePrepareT';\n\n// ===== Component ===== //\n\n/**\n * External-store version of the `<T>` component.\n */\nfunction T(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\nfunction GtInternalTranslateJsx(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\n/** @internal _gtt - The GT transformation for the component. */\nT._gtt = 'translate-client';\nGtInternalTranslateJsx._gtt = 'translate-client-automatic';\n\nexport { GtInternalTranslateJsx, T };\n\n/**\n * Render logic\n */\nfunction useComputeT({\n children: sourceChildren,\n _locale,\n _enableI18n,\n _renderPreparedT = renderPreparedT,\n ...params\n}: TProps): ReactNode {\n // Prepare our source children for rendering\n const {\n defaultLocale,\n locale,\n enableI18n,\n targetOptions,\n taggedSourceChildren,\n sourceJsxChildren,\n shouldTranslate,\n } = usePrepareT({\n sourceChildren,\n params,\n _locale,\n _enableI18n,\n });\n\n // Lookup translation in cache\n const targetJsxChildren = useTranslate({\n locale,\n
|
|
1
|
+
{"version":3,"file":"T.mjs","names":[],"sources":["../../../src/components/translation/T.tsx"],"sourcesContent":["import { useTranslate } from '../../hooks/external-store';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { useRef, type ReactNode } from 'react';\nimport { renderPreparedT } from '../../utils/rendering/renderPipeline';\nimport type { TProps } from '../../utils/translation/prepareT.shared';\nimport { usePrepareT } from '../../utils/translation/usePrepareT';\n\n// ===== Component ===== //\n\n/**\n * External-store version of the `<T>` component.\n */\nfunction T(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\nfunction GtInternalTranslateJsx(props: TProps): ReactNode {\n return useComputeT(props);\n}\n\n/** @internal _gtt - The GT transformation for the component. */\nT._gtt = 'translate-client';\nGtInternalTranslateJsx._gtt = 'translate-client-automatic';\n\nexport { GtInternalTranslateJsx, T };\n\n/**\n * Render logic\n */\nfunction useComputeT({\n children: sourceChildren,\n _locale,\n _enableI18n,\n _renderPreparedT = renderPreparedT,\n ...params\n}: TProps): ReactNode {\n // Prepare our source children for rendering\n const {\n defaultLocale,\n locale,\n enableI18n,\n targetOptions,\n taggedSourceChildren,\n sourceJsxChildren,\n shouldTranslate,\n } = usePrepareT({\n sourceChildren,\n params,\n _locale,\n _enableI18n,\n });\n\n // Lookup translation in cache\n const targetJsxChildren = useTranslate({\n locale,\n content: sourceJsxChildren,\n options: targetOptions,\n });\n\n // Tx hot reload: render previous translation while loading new one\n // TODO: account for success vs loading vs failed request states\n const prev = useRef<ReactNode | null>(null);\n if (\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled() &&\n targetJsxChildren == null &&\n prev.current != null &&\n shouldTranslate\n ) {\n return prev.current;\n }\n\n const result = _renderPreparedT({\n taggedSourceChildren,\n targetJsxChildren,\n locale,\n defaultLocale,\n enableI18n,\n shouldTranslate,\n hash: targetOptions.$_hash,\n });\n\n // record previous result\n prev.current = result;\n\n return result;\n}\n"],"mappings":"+RAYA,SAAS,EAAE,EAA0B,CACnC,OAAO,EAAY,EAAM,CAG3B,SAAS,EAAuB,EAA0B,CACxD,OAAO,EAAY,EAAM,CAI3B,EAAE,KAAO,mBACT,EAAuB,KAAO,6BAO9B,SAAS,EAAY,CACnB,SAAU,EACV,UACA,cACA,mBAAmB,EACnB,GAAG,GACiB,CAEpB,GAAM,CACJ,gBACA,SACA,aACA,gBACA,uBACA,oBACA,mBACE,EAAY,CACd,iBACA,SACA,UACA,cACD,CAAC,CAGI,EAAoB,EAAa,CACrC,SACA,QAAS,EACT,QAAS,EACV,CAAC,CAII,EAAO,EAAyB,KAAK,CAC3C,GACE,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,EACvC,GAAqB,MACrB,EAAK,SAAW,MAChB,EAEA,OAAO,EAAK,QAGd,IAAM,EAAS,EAAiB,CAC9B,uBACA,oBACA,SACA,gBACA,aACA,kBACA,KAAM,EAAc,OACrB,CAAC,CAKF,MAFA,GAAK,QAAU,EAER"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(a=[],s,c){let l=e.useTranslationsSnapshot(),u=e.useI18nStore(),d=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),f=t.useHandleMissingTranslationWithConditions(c),p=(0,i.useRef)(null);return p.current??=new Set,o(a,p,s,c),(0,i.useCallback)(e=>{let t=(0,r.getTranslateListenerKey)(e);d&&p.current.add(t);let n=u.getTranslateSnapshot(e,l);return n==null&&d&&f(e),n},[u,l,f,d,n.useSubscribeToTrackedLookups(p,u.subscribeToTranslationEvents,r.getTranslateListenerKey)])}function o(t,n,a,o){let s=e.useI18nStore(),c=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),l=e.useTranslationsSnapshot(),u=(0,i.useMemo)(()=>t?.length>0&&o&&c,[t,o,c]),d=(0,i.useMemo)(()=>u?t.map(({message:e,...t})=>{let n=t.$locale??a,i={locale:n,
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(a=[],s,c){let l=e.useTranslationsSnapshot(),u=e.useI18nStore(),d=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),f=t.useHandleMissingTranslationWithConditions(c),p=(0,i.useRef)(null);return p.current??=new Set,o(a,p,s,c),(0,i.useCallback)(e=>{let t=(0,r.getTranslateListenerKey)(e);d&&p.current.add(t);let n=u.getTranslateSnapshot(e,l);return n==null&&d&&f(e),n},[u,l,f,d,n.useSubscribeToTrackedLookups(p,u.subscribeToTranslationEvents,r.getTranslateListenerKey)])}function o(t,n,a,o){let s=e.useI18nStore(),c=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),l=e.useTranslationsSnapshot(),u=(0,i.useMemo)(()=>t?.length>0&&o&&c,[t,o,c]),d=(0,i.useMemo)(()=>u?t.map(({message:e,...t})=>{let n=t.$locale??a,i={locale:n,content:e,options:(0,r.createLookupOptions)(n,t,`ICU`)};return[i,(0,r.getTranslateListenerKey)(i)]}):[],[a,u,t]);u&&d.forEach(([,e])=>{n.current.add(e)}),(0,i.useEffect)(()=>{u&&d.filter(([e])=>s.getTranslateSnapshot(e,l)==null).forEach(([e])=>s.translate(e))},[u,s,d,l])}exports.useTrackedTranslationResolver=a;
|
|
2
2
|
//# sourceMappingURL=useTrackedTranslationResolver.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTrackedTranslationResolver.cjs","names":["useTranslationsSnapshot","useI18nStore","useHandleMissingTranslationWithConditions","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 {
|
|
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 { RegisteredMessage } from 'gt-i18n/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\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: RegisteredMessage[] = [],\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: RegisteredMessage[],\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 content: 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":"wPAwCA,SAAgB,EACd,EAAgC,EAAE,CAClC,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,QAAS,EACT,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,2 +1,2 @@
|
|
|
1
|
-
import{useI18nStore as e,useTranslationsSnapshot as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingTranslationWithConditions as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{createLookupOptions as i,getI18nConfig as a,getTranslateListenerKey as o}from"gt-i18n/internal";import{useCallback as s,useEffect as c,useMemo as l,useRef as u}from"react";function d(i=[],c,l){let d=t(),p=e(),m=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),h=n(l),g=u(null);return g.current??=new Set,f(i,g,c,l),s(e=>{let t=o(e);m&&g.current.add(t);let n=p.getTranslateSnapshot(e,d);return n==null&&m&&h(e),n},[p,d,h,m,r(g,p.subscribeToTranslationEvents,o)])}function f(n,r,s,u){let d=e(),f=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),p=t(),m=l(()=>n?.length>0&&u&&f,[n,u,f]),h=l(()=>m?n.map(({message:e,...t})=>{let n=t.$locale??s,r={locale:n,
|
|
1
|
+
import{useI18nStore as e,useTranslationsSnapshot as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingTranslationWithConditions as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{createLookupOptions as i,getI18nConfig as a,getTranslateListenerKey as o}from"gt-i18n/internal";import{useCallback as s,useEffect as c,useMemo as l,useRef as u}from"react";function d(i=[],c,l){let d=t(),p=e(),m=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),h=n(l),g=u(null);return g.current??=new Set,f(i,g,c,l),s(e=>{let t=o(e);m&&g.current.add(t);let n=p.getTranslateSnapshot(e,d);return n==null&&m&&h(e),n},[p,d,h,m,r(g,p.subscribeToTranslationEvents,o)])}function f(n,r,s,u){let d=e(),f=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),p=t(),m=l(()=>n?.length>0&&u&&f,[n,u,f]),h=l(()=>m?n.map(({message:e,...t})=>{let n=t.$locale??s,r={locale:n,content:e,options:i(n,t,`ICU`)};return[r,o(r)]}):[],[s,m,n]);m&&h.forEach(([,e])=>{r.current.add(e)}),c(()=>{m&&h.filter(([e])=>d.getTranslateSnapshot(e,p)==null).forEach(([e])=>d.translate(e))},[m,d,h,p])}export{d as useTrackedTranslationResolver};
|
|
2
2
|
//# sourceMappingURL=useTrackedTranslationResolver.mjs.map
|
|
@@ -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 { Content } from '@generaltranslation/format/types';\nimport type {\n TranslateLookup,\n TranslateSnapshot,\n} from '../../i18n-store/storeTypes';\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 { RegisteredMessage } from 'gt-i18n/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\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: RegisteredMessage[] = [],\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: RegisteredMessage[],\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 content: 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":"gcAwCA,SAAgB,EACd,EAAgC,EAAE,CAClC,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,QAAS,EACT,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"}
|
package/dist/hooks/useGT.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./i18n-config.cjs`),t=require(`./utils.cjs`),n=require(`./external-store/useTrackedTranslationResolver.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(a){let{locale:o,shouldTranslate:s}=t.useTranslationConditions(),c=e.useDefaultLocale(),l=n.useTrackedTranslationResolver(a,o,s);return(0,i.useCallback)((e,t={})=>{let n=(0,r.createLookupOptions)(t.$locale??o,t,`ICU`);return s?(0,r.interpolateMessage)({source:e,target:l({locale:n.$locale,
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./i18n-config.cjs`),t=require(`./utils.cjs`),n=require(`./external-store/useTrackedTranslationResolver.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(a){let{locale:o,shouldTranslate:s}=t.useTranslationConditions(),c=e.useDefaultLocale(),l=n.useTrackedTranslationResolver(a,o,s);return(0,i.useCallback)((e,t={})=>{let n=(0,r.createLookupOptions)(t.$locale??o,t,`ICU`);return s?(0,r.interpolateMessage)({source:e,target:l({locale:n.$locale,content:e,options:n}),options:n,sourceLocale:c}):(0,r.interpolateMessage)({options:n,source:e,sourceLocale:c})},[c,o,s,l])}exports.useGT=a;
|
|
2
2
|
//# sourceMappingURL=useGT.cjs.map
|
package/dist/hooks/useGT.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.cjs","names":["useTranslationConditions","useDefaultLocale","useTrackedTranslationResolver"],"sources":["../../src/hooks/useGT.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { createLookupOptions, interpolateMessage } from 'gt-i18n/internal';\nimport { useTranslationConditions } from './utils';\nimport type {
|
|
1
|
+
{"version":3,"file":"useGT.cjs","names":["useTranslationConditions","useDefaultLocale","useTrackedTranslationResolver"],"sources":["../../src/hooks/useGT.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { createLookupOptions, interpolateMessage } from 'gt-i18n/internal';\nimport { useTranslationConditions } from './utils';\nimport type {\n GTFunctionType,\n GTTranslationOptions,\n RegisteredMessage,\n} from 'gt-i18n/types';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport { useDefaultLocale } from './i18n-config';\nimport { useTrackedTranslationResolver } from './external-store/useTrackedTranslationResolver';\n\n// ===== Hook ===== //\n\nexport function useGT(_messages?: RegisteredMessage[]): GTFunctionType {\n const { locale, shouldTranslate } = useTranslationConditions();\n const defaultLocale = useDefaultLocale();\n const resolveTranslation = useTrackedTranslationResolver(\n _messages,\n locale,\n shouldTranslate\n );\n\n /**\n * gt() string translation callback\n */\n return useCallback(\n (message: string, options: GTTranslationOptions = {}) => {\n const lookupOptions = createLookupOptions<StringFormat>(\n options.$locale ?? locale,\n options,\n 'ICU'\n );\n\n if (!shouldTranslate) {\n return interpolateMessage({\n options: lookupOptions,\n source: message,\n sourceLocale: defaultLocale,\n });\n }\n\n const translation = resolveTranslation({\n locale: lookupOptions.$locale,\n content: message,\n options: lookupOptions,\n });\n\n return interpolateMessage({\n source: message,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n },\n [defaultLocale, locale, shouldTranslate, resolveTranslation]\n );\n}\n"],"mappings":"gOAcA,SAAgB,EAAM,EAAiD,CACrE,GAAM,CAAE,SAAQ,mBAAoBA,EAAAA,0BAA0B,CACxD,EAAgBC,EAAAA,kBAAkB,CAClC,EAAqBC,EAAAA,8BACzB,EACA,EACA,EACD,CAKD,OAAA,EAAA,EAAA,cACG,EAAiB,EAAgC,EAAE,GAAK,CACvD,IAAM,GAAA,EAAA,EAAA,qBACJ,EAAQ,SAAW,EACnB,EACA,MACD,CAgBD,OAdK,GAcL,EAAA,EAAA,oBAA0B,CACxB,OAAQ,EACR,OARkB,EAAmB,CACrC,OAAQ,EAAc,QACtB,QAAS,EACT,QAAS,EACV,CAIoB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,EAlBA,EAAA,EAAA,oBAA0B,CACxB,QAAS,EACT,OAAQ,EACR,aAAc,EACf,CAAC,EAgBN,CAAC,EAAe,EAAQ,EAAiB,EAAmB,CAC7D"}
|
package/dist/hooks/useGT.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GTFunctionType } from "gt-i18n/types";
|
|
1
|
+
import { GTFunctionType, RegisteredMessage } from "gt-i18n/types";
|
|
3
2
|
|
|
4
3
|
//#region src/hooks/useGT.d.ts
|
|
5
|
-
declare function useGT(_messages?:
|
|
4
|
+
declare function useGT(_messages?: RegisteredMessage[]): GTFunctionType;
|
|
6
5
|
//#endregion
|
|
7
6
|
export { useGT };
|
|
8
7
|
//# sourceMappingURL=useGT.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.d.ts","names":[],"sources":["../../src/hooks/useGT.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGT.d.ts","names":[],"sources":["../../src/hooks/useGT.ts"],"mappings":";;;iBAcgB,KAAA,CAAM,SAAA,GAAY,iBAAA,KAAsB,cAAA"}
|
package/dist/hooks/useGT.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useDefaultLocale as e}from"./i18n-config.mjs";import{useTranslationConditions as t}from"./utils.mjs";import{useTrackedTranslationResolver as n}from"./external-store/useTrackedTranslationResolver.mjs";import{createLookupOptions as r,interpolateMessage as i}from"gt-i18n/internal";import{useCallback as a}from"react";function o(o){let{locale:s,shouldTranslate:c}=t(),l=e(),u=n(o,s,c);return a((e,t={})=>{let n=r(t.$locale??s,t,`ICU`);return i(c?{source:e,target:u({locale:n.$locale,
|
|
1
|
+
import{useDefaultLocale as e}from"./i18n-config.mjs";import{useTranslationConditions as t}from"./utils.mjs";import{useTrackedTranslationResolver as n}from"./external-store/useTrackedTranslationResolver.mjs";import{createLookupOptions as r,interpolateMessage as i}from"gt-i18n/internal";import{useCallback as a}from"react";function o(o){let{locale:s,shouldTranslate:c}=t(),l=e(),u=n(o,s,c);return a((e,t={})=>{let n=r(t.$locale??s,t,`ICU`);return i(c?{source:e,target:u({locale:n.$locale,content:e,options:n}),options:n,sourceLocale:l}:{options:n,source:e,sourceLocale:l})},[l,s,c,u])}export{o as useGT};
|
|
2
2
|
//# sourceMappingURL=useGT.mjs.map
|
package/dist/hooks/useGT.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.mjs","names":[],"sources":["../../src/hooks/useGT.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { createLookupOptions, interpolateMessage } from 'gt-i18n/internal';\nimport { useTranslationConditions } from './utils';\nimport type {
|
|
1
|
+
{"version":3,"file":"useGT.mjs","names":[],"sources":["../../src/hooks/useGT.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { createLookupOptions, interpolateMessage } from 'gt-i18n/internal';\nimport { useTranslationConditions } from './utils';\nimport type {\n GTFunctionType,\n GTTranslationOptions,\n RegisteredMessage,\n} from 'gt-i18n/types';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport { useDefaultLocale } from './i18n-config';\nimport { useTrackedTranslationResolver } from './external-store/useTrackedTranslationResolver';\n\n// ===== Hook ===== //\n\nexport function useGT(_messages?: RegisteredMessage[]): GTFunctionType {\n const { locale, shouldTranslate } = useTranslationConditions();\n const defaultLocale = useDefaultLocale();\n const resolveTranslation = useTrackedTranslationResolver(\n _messages,\n locale,\n shouldTranslate\n );\n\n /**\n * gt() string translation callback\n */\n return useCallback(\n (message: string, options: GTTranslationOptions = {}) => {\n const lookupOptions = createLookupOptions<StringFormat>(\n options.$locale ?? locale,\n options,\n 'ICU'\n );\n\n if (!shouldTranslate) {\n return interpolateMessage({\n options: lookupOptions,\n source: message,\n sourceLocale: defaultLocale,\n });\n }\n\n const translation = resolveTranslation({\n locale: lookupOptions.$locale,\n content: message,\n options: lookupOptions,\n });\n\n return interpolateMessage({\n source: message,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n },\n [defaultLocale, locale, shouldTranslate, resolveTranslation]\n );\n}\n"],"mappings":"kUAcA,SAAgB,EAAM,EAAiD,CACrE,GAAM,CAAE,SAAQ,mBAAoB,GAA0B,CACxD,EAAgB,GAAkB,CAClC,EAAqB,EACzB,EACA,EACA,EACD,CAKD,OAAO,GACJ,EAAiB,EAAgC,EAAE,GAAK,CACvD,IAAM,EAAgB,EACpB,EAAQ,SAAW,EACnB,EACA,MACD,CAgBD,OAAO,EAdF,EAcqB,CACxB,OAAQ,EACR,OARkB,EAAmB,CACrC,OAAQ,EAAc,QACtB,QAAS,EACT,QAAS,EACV,CAIoB,CACnB,QAAS,EACT,aAAc,EACf,CAlB2B,CACxB,QAAS,EACT,OAAQ,EACR,aAAc,EACf,CAAC,EAgBN,CAAC,EAAe,EAAQ,EAAiB,EAAmB,CAC7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessages.cjs","names":["useGT"],"sources":["../../src/hooks/useMessages.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { decodeOptions } from 'gt-i18n';\nimport { useGT } from './useGT';\nimport type {
|
|
1
|
+
{"version":3,"file":"useMessages.cjs","names":["useGT"],"sources":["../../src/hooks/useMessages.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { decodeOptions } from 'gt-i18n';\nimport { useGT } from './useGT';\nimport type {\n GTTranslationOptions,\n MFunctionType,\n RegisteredMessage,\n} from 'gt-i18n/types';\nimport { isEncodedTranslationOptions } from 'gt-i18n/internal';\n\n// ===== Hook ===== //\n\nexport function useMessages(_messages?: RegisteredMessage[]): MFunctionType {\n const gt = useGT(_messages);\n\n return useCallback(\n <T extends string | null | undefined>(\n encodedMsg: T,\n options: GTTranslationOptions = {}\n ): T extends string ? string : T => {\n if (encodedMsg == null) {\n return encodedMsg as T extends string ? string : T;\n }\n\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n if (isEncodedTranslationOptions(decodedOptions)) {\n return gt(decodedOptions.$_source, decodedOptions) as T extends string\n ? string\n : T;\n }\n\n return gt(encodedMsg, options) as T extends string ? string : T;\n },\n [gt]\n );\n}\n"],"mappings":"sJAYA,SAAgB,EAAY,EAAgD,CAC1E,IAAM,EAAKA,EAAAA,MAAM,EAAU,CAE3B,OAAA,EAAA,EAAA,cAEI,EACA,EAAgC,EAAE,GACA,CAClC,GAAI,GAAc,KAChB,OAAO,EAGT,IAAM,GAAA,EAAA,EAAA,eAA+B,EAAW,EAAI,EAAE,CAOtD,OANA,EAAA,EAAA,6BAAgC,EAAe,CACtC,EAAG,EAAe,SAAU,EAAe,CAK7C,EAAG,EAAY,EAAQ,EAEhC,CAAC,EAAG,CACL"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MFunctionType } from "gt-i18n/types";
|
|
1
|
+
import { MFunctionType, RegisteredMessage } from "gt-i18n/types";
|
|
3
2
|
|
|
4
3
|
//#region src/hooks/useMessages.d.ts
|
|
5
|
-
declare function useMessages(_messages?:
|
|
4
|
+
declare function useMessages(_messages?: RegisteredMessage[]): MFunctionType;
|
|
6
5
|
//#endregion
|
|
7
6
|
export { useMessages };
|
|
8
7
|
//# sourceMappingURL=useMessages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessages.d.ts","names":[],"sources":["../../src/hooks/useMessages.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useMessages.d.ts","names":[],"sources":["../../src/hooks/useMessages.ts"],"mappings":";;;iBAYgB,WAAA,CAAY,SAAA,GAAY,iBAAA,KAAsB,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessages.mjs","names":[],"sources":["../../src/hooks/useMessages.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { decodeOptions } from 'gt-i18n';\nimport { useGT } from './useGT';\nimport type {
|
|
1
|
+
{"version":3,"file":"useMessages.mjs","names":[],"sources":["../../src/hooks/useMessages.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { decodeOptions } from 'gt-i18n';\nimport { useGT } from './useGT';\nimport type {\n GTTranslationOptions,\n MFunctionType,\n RegisteredMessage,\n} from 'gt-i18n/types';\nimport { isEncodedTranslationOptions } from 'gt-i18n/internal';\n\n// ===== Hook ===== //\n\nexport function useMessages(_messages?: RegisteredMessage[]): MFunctionType {\n const gt = useGT(_messages);\n\n return useCallback(\n <T extends string | null | undefined>(\n encodedMsg: T,\n options: GTTranslationOptions = {}\n ): T extends string ? string : T => {\n if (encodedMsg == null) {\n return encodedMsg as T extends string ? string : T;\n }\n\n const decodedOptions = decodeOptions(encodedMsg) ?? {};\n if (isEncodedTranslationOptions(decodedOptions)) {\n return gt(decodedOptions.$_source, decodedOptions) as T extends string\n ? string\n : T;\n }\n\n return gt(encodedMsg, options) as T extends string ? string : T;\n },\n [gt]\n );\n}\n"],"mappings":"+KAYA,SAAgB,EAAY,EAAgD,CAC1E,IAAM,EAAK,EAAM,EAAU,CAE3B,OAAO,GAEH,EACA,EAAgC,EAAE,GACA,CAClC,GAAI,GAAc,KAChB,OAAO,EAGT,IAAM,EAAiB,EAAc,EAAW,EAAI,EAAE,CAOtD,OANI,EAA4B,EAAe,CACtC,EAAG,EAAe,SAAU,EAAe,CAK7C,EAAG,EAAY,EAAQ,EAEhC,CAAC,EAAG,CACL"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../i18n-cache/singleton-operations.cjs`),t=require(`./utils/subscriptions.cjs`),n=require(`./utils/translations.cjs`),r=require(`./utils/dictionaries.cjs`);let i=require(`gt-i18n/internal`),a=require(`generaltranslation/internal`);function o(e){if(e instanceof Error)return`${e.name}|${e.message}`;if(typeof e==`object`&&e)try{return`object|${JSON.stringify(e)}`}catch{return`object|${String(e)}`}return`${typeof e}|${String(e)}`}var s=class{translateListeners=new Set;dictionaryEntryListeners=new Set;dictionaryObjectListeners=new Set;loggedRuntimeTranslationErrors=new Set;constructor(){}updateTranslations=t=>{e.getReactI18nCache().updateTranslations(t)};updateDictionaries=t=>{e.getReactI18nCache().updateDictionaries(t)};translate=async t=>e.getReactI18nCache().lookupTranslationWithFallback(t.locale,t.
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../i18n-cache/singleton-operations.cjs`),t=require(`./utils/subscriptions.cjs`),n=require(`./utils/translations.cjs`),r=require(`./utils/dictionaries.cjs`);let i=require(`gt-i18n/internal`),a=require(`generaltranslation/internal`);function o(e){if(e instanceof Error)return`${e.name}|${e.message}`;if(typeof e==`object`&&e)try{return`object|${JSON.stringify(e)}`}catch{return`object|${String(e)}`}return`${typeof e}|${String(e)}`}var s=class{translateListeners=new Set;dictionaryEntryListeners=new Set;dictionaryObjectListeners=new Set;loggedRuntimeTranslationErrors=new Set;constructor(){}updateTranslations=t=>{e.getReactI18nCache().updateTranslations(t)};updateDictionaries=t=>{e.getReactI18nCache().updateDictionaries(t)};translate=async t=>e.getReactI18nCache().lookupTranslationWithFallback(t.locale,t.content,t.options).then(()=>{this.emitTranslateEvent(t)}).catch(e=>this.logRuntimeTranslationError(e));translateDictionaryEntry=t=>{e.getReactI18nCache().lookupDictionaryWithFallback(t.locale,t.id).then(()=>{this.emitDictionaryEvent(t)}).catch(e=>this.logRuntimeTranslationError(e))};translateDictionaryObject=t=>{e.getReactI18nCache().lookupDictionaryObjWithFallback(t.locale,t.id).then(()=>{this.emitDictionaryEvent(t)}).catch(e=>this.logRuntimeTranslationError(e))};logRuntimeTranslationError(e){let t=(0,a.formatDiagnosticErrorDetails)(e),n=o(e);if(!this.loggedRuntimeTranslationErrors.has(n)){if(this.loggedRuntimeTranslationErrors.add(n),this.loggedRuntimeTranslationErrors.size>100){let e=this.loggedRuntimeTranslationErrors.values().next().value;e!==void 0&&this.loggedRuntimeTranslationErrors.delete(e)}console.error((0,a.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`A runtime translation request failed.`,wayOut:`Rendering falls back to untranslated content.`,details:t}))}}subscribeToTranslate=(e,n)=>{let r=(0,i.getTranslateListenerKey)(e);return t.subscribeToSet(this.translateListeners,e=>{(0,i.getTranslateListenerKey)(e)===r&&n()})};subscribeToTranslationEvents=e=>t.subscribeToSet(this.translateListeners,e);subscribeToDictionaryEntryEvents=e=>t.subscribeToSet(this.dictionaryEntryListeners,e);subscribeToDictionaryObjectEvents=e=>t.subscribeToSet(this.dictionaryObjectListeners,e);getTranslateSnapshot=(t,r={})=>n.lookupTranslation(r,t)??e.getReactI18nCache().lookupTranslation(t.locale,t.content,t.options);getDictionaryEntrySnapshot=(t,n={})=>r.lookupDictionaryEntry(n,t)??e.getReactI18nCache().lookupDictionary(t.locale,t.id);getDictionaryObjectSnapshot=(t,n={})=>r.lookupDictionaryObject(n,t)??e.getReactI18nCache().lookupDictionaryObj(t.locale,t.id);emitTranslateEvent(e){this.translateListeners.forEach(t=>t(e))}emitDictionaryEvent(e){this.dictionaryEntryListeners.forEach(t=>t(e)),this.dictionaryObjectListeners.forEach(t=>{t(e)})}};exports.I18nStore=s;
|
|
2
2
|
//# sourceMappingURL=I18nStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18nStore.cjs","names":["getReactI18nCache","subscribeToSet","lookupTranslation","lookupDictionaryEntry","lookupDictionaryObject"],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Content>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Content>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.
|
|
1
|
+
{"version":3,"file":"I18nStore.cjs","names":["getReactI18nCache","subscribeToSet","lookupTranslation","lookupDictionaryEntry","lookupDictionaryObject"],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Content>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Content>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.content,\n lookup.options\n )\n .then(() => {\n this.emitTranslateEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n /**\n * Runtime translation runs fire-and-forget, so a rejected request (for\n * example a 401 from an invalid dev API key) is logged here instead of\n * escaping as an unhandled rejection that kills the dev server during SSR.\n * Identical failures log once.\n */\n private logRuntimeTranslationError(error: unknown): void {\n const details = formatDiagnosticErrorDetails(error);\n const dedupeKey = getRuntimeTranslationErrorDedupeKey(error);\n if (this.loggedRuntimeTranslationErrors.has(dedupeKey)) return;\n this.loggedRuntimeTranslationErrors.add(dedupeKey);\n if (\n this.loggedRuntimeTranslationErrors.size >\n MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS\n ) {\n const oldest = this.loggedRuntimeTranslationErrors.values().next().value;\n if (oldest !== undefined) {\n this.loggedRuntimeTranslationErrors.delete(oldest);\n }\n }\n console.error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'A runtime translation request failed.',\n wayOut: 'Rendering falls back to untranslated content.',\n details,\n })\n );\n }\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToTranslate = <T extends Content>(\n lookup: TranslateLookup<T>,\n listener: StoreListener\n ): Unsubscribe => {\n const lookupKey = getTranslateListenerKey(lookup);\n const wrappedListener: TranslateEventListener = (lookup) => {\n if (getTranslateListenerKey(lookup) === lookupKey) {\n listener();\n }\n };\n return subscribeToSet(this.translateListeners, wrappedListener);\n };\n\n subscribeToTranslationEvents = (\n listener: TranslateEventListener\n ): Unsubscribe => {\n return subscribeToSet(this.translateListeners, listener);\n };\n\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getTranslateSnapshot = <T extends Content>(\n lookup: TranslateLookup<T>,\n translationsSnapshot: Record<Locale, Record<Hash, Content>> = {}\n ): TranslateSnapshot<T> => {\n return (\n lookupTranslation(translationsSnapshot, lookup) ??\n getReactI18nCache().lookupTranslation<T>(\n lookup.locale,\n lookup.content,\n lookup.options\n )\n );\n };\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionaryObj(lookup.locale, lookup.id)\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitTranslateEvent(event: TranslateLookup): void {\n this.translateListeners.forEach((listener) => listener(event));\n }\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"qSA8BA,SAAS,EAAoC,EAAwB,CACnE,GAAI,aAAiB,MACnB,MAAO,GAAG,EAAM,KAAK,GAAG,EAAM,UAEhC,GAAsB,OAAO,GAAU,UAAnC,EACF,GAAI,CACF,MAAO,UAAU,KAAK,UAAU,EAAM,QAChC,CACN,MAAO,UAAU,OAAO,EAAM,GAGlC,MAAO,GAAG,OAAO,EAAM,GAAG,OAAO,EAAM,GAYzC,IAAa,EAAb,KAAuB,CAGrB,mBAA6B,IAAI,IACjC,yBAAmC,IAAI,IACvC,0BAAoC,IAAI,IACxC,+BAAyC,IAAI,IAK7C,aAAc,EAId,mBACE,GACS,CACT,EAAA,mBAAmB,CAAC,mBAAmB,EAAa,EAGtD,mBAAsB,GAAmD,CACvE,EAAA,mBAAmB,CAAC,mBAAmB,EAAa,EAKtD,UAAY,KACV,IAEOA,EAAAA,mBAAmB,CACvB,8BACC,EAAO,OACP,EAAO,QACP,EAAO,QACR,CACA,SAAW,CACV,KAAK,mBAAmB,EAAO,EAC/B,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,CAG7D,yBAA4B,GAAmC,CAC7D,EAAA,mBAAmB,CAChB,6BAA6B,EAAO,OAAQ,EAAO,GAAG,CACtD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAG7D,0BAA6B,GAAmC,CAC9D,EAAA,mBAAmB,CAChB,gCAAgC,EAAO,OAAQ,EAAO,GAAG,CACzD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAS7D,2BAAmC,EAAsB,CACvD,IAAM,GAAA,EAAA,EAAA,8BAAuC,EAAM,CAC7C,EAAY,EAAoC,EAAM,CACxD,SAAK,+BAA+B,IAAI,EAAU,CAEtD,IADA,KAAK,+BAA+B,IAAI,EAAU,CAEhD,KAAK,+BAA+B,KACpC,IACA,CACA,IAAM,EAAS,KAAK,+BAA+B,QAAQ,CAAC,MAAM,CAAC,MAC/D,IAAW,IAAA,IACb,KAAK,+BAA+B,OAAO,EAAO,CAGtD,QAAQ,OAAA,EAAA,EAAA,yBACkB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,wCACd,OAAQ,gDACR,UACD,CAAC,CACH,EASH,sBACE,EACA,IACgB,CAChB,IAAM,GAAA,EAAA,EAAA,yBAAoC,EAAO,CAMjD,OAAOC,EAAAA,eAAe,KAAK,mBALsB,GAAW,EAC1D,EAAA,EAAA,yBAA4B,EAAO,GAAK,GACtC,GAAU,EAGiD,EAGjE,6BACE,GAEOA,EAAAA,eAAe,KAAK,mBAAoB,EAAS,CAG1D,iCACE,GAEOA,EAAAA,eAAe,KAAK,yBAA0B,EAAS,CAGhE,kCACE,GAEOA,EAAAA,eAAe,KAAK,0BAA2B,EAAS,CAKjE,sBACE,EACA,EAA8D,EAAE,GAG9DC,EAAAA,kBAAkB,EAAsB,EAAO,EAC/CF,EAAAA,mBAAmB,CAAC,kBAClB,EAAO,OACP,EAAO,QACP,EAAO,QACR,CAIL,4BACE,EACA,EAAmD,EAAE,GAGnDG,EAAAA,sBAAsB,EAAsB,EAAO,EACnDH,EAAAA,mBAAmB,CAAC,iBAAiB,EAAO,OAAQ,EAAO,GAAG,CAIlE,6BACE,EACA,EAAmD,EAAE,GAGnDI,EAAAA,uBAAuB,EAAsB,EAAO,EACpDJ,EAAAA,mBAAmB,CAAC,oBAAoB,EAAO,OAAQ,EAAO,GAAG,CAMrE,mBAA2B,EAA8B,CACvD,KAAK,mBAAmB,QAAS,GAAa,EAAS,EAAM,CAAC,CAGhE,oBAA4B,EAA+B,CACzD,KAAK,yBAAyB,QAAS,GAAa,EAAS,EAAM,CAAC,CACpE,KAAK,0BAA0B,QAAS,GAAa,CACnD,EAAS,EAAM,EACf"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getReactI18nCache as e}from"../i18n-cache/singleton-operations.mjs";import{subscribeToSet as t}from"./utils/subscriptions.mjs";import{lookupTranslation as n}from"./utils/translations.mjs";import{lookupDictionaryEntry as r,lookupDictionaryObject as i}from"./utils/dictionaries.mjs";import{getTranslateListenerKey as a}from"gt-i18n/internal";import{createDiagnosticMessage as o,formatDiagnosticErrorDetails as s}from"generaltranslation/internal";function c(e){if(e instanceof Error)return`${e.name}|${e.message}`;if(typeof e==`object`&&e)try{return`object|${JSON.stringify(e)}`}catch{return`object|${String(e)}`}return`${typeof e}|${String(e)}`}var l=class{translateListeners=new Set;dictionaryEntryListeners=new Set;dictionaryObjectListeners=new Set;loggedRuntimeTranslationErrors=new Set;constructor(){}updateTranslations=t=>{e().updateTranslations(t)};updateDictionaries=t=>{e().updateDictionaries(t)};translate=async t=>e().lookupTranslationWithFallback(t.locale,t.
|
|
1
|
+
import{getReactI18nCache as e}from"../i18n-cache/singleton-operations.mjs";import{subscribeToSet as t}from"./utils/subscriptions.mjs";import{lookupTranslation as n}from"./utils/translations.mjs";import{lookupDictionaryEntry as r,lookupDictionaryObject as i}from"./utils/dictionaries.mjs";import{getTranslateListenerKey as a}from"gt-i18n/internal";import{createDiagnosticMessage as o,formatDiagnosticErrorDetails as s}from"generaltranslation/internal";function c(e){if(e instanceof Error)return`${e.name}|${e.message}`;if(typeof e==`object`&&e)try{return`object|${JSON.stringify(e)}`}catch{return`object|${String(e)}`}return`${typeof e}|${String(e)}`}var l=class{translateListeners=new Set;dictionaryEntryListeners=new Set;dictionaryObjectListeners=new Set;loggedRuntimeTranslationErrors=new Set;constructor(){}updateTranslations=t=>{e().updateTranslations(t)};updateDictionaries=t=>{e().updateDictionaries(t)};translate=async t=>e().lookupTranslationWithFallback(t.locale,t.content,t.options).then(()=>{this.emitTranslateEvent(t)}).catch(e=>this.logRuntimeTranslationError(e));translateDictionaryEntry=t=>{e().lookupDictionaryWithFallback(t.locale,t.id).then(()=>{this.emitDictionaryEvent(t)}).catch(e=>this.logRuntimeTranslationError(e))};translateDictionaryObject=t=>{e().lookupDictionaryObjWithFallback(t.locale,t.id).then(()=>{this.emitDictionaryEvent(t)}).catch(e=>this.logRuntimeTranslationError(e))};logRuntimeTranslationError(e){let t=s(e),n=c(e);if(!this.loggedRuntimeTranslationErrors.has(n)){if(this.loggedRuntimeTranslationErrors.add(n),this.loggedRuntimeTranslationErrors.size>100){let e=this.loggedRuntimeTranslationErrors.values().next().value;e!==void 0&&this.loggedRuntimeTranslationErrors.delete(e)}console.error(o({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`A runtime translation request failed.`,wayOut:`Rendering falls back to untranslated content.`,details:t}))}}subscribeToTranslate=(e,n)=>{let r=a(e);return t(this.translateListeners,e=>{a(e)===r&&n()})};subscribeToTranslationEvents=e=>t(this.translateListeners,e);subscribeToDictionaryEntryEvents=e=>t(this.dictionaryEntryListeners,e);subscribeToDictionaryObjectEvents=e=>t(this.dictionaryObjectListeners,e);getTranslateSnapshot=(t,r={})=>n(r,t)??e().lookupTranslation(t.locale,t.content,t.options);getDictionaryEntrySnapshot=(t,n={})=>r(n,t)??e().lookupDictionary(t.locale,t.id);getDictionaryObjectSnapshot=(t,n={})=>i(n,t)??e().lookupDictionaryObj(t.locale,t.id);emitTranslateEvent(e){this.translateListeners.forEach(t=>t(e))}emitDictionaryEvent(e){this.dictionaryEntryListeners.forEach(t=>t(e)),this.dictionaryObjectListeners.forEach(t=>{t(e)})}};export{l as I18nStore};
|
|
2
2
|
//# sourceMappingURL=I18nStore.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18nStore.mjs","names":[],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Content>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Content>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.
|
|
1
|
+
{"version":3,"file":"I18nStore.mjs","names":[],"sources":["../../src/i18n-store/I18nStore.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n} from 'generaltranslation/internal';\nimport { getTranslateListenerKey } from 'gt-i18n/internal';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n TranslateEventListener,\n TranslateLookup,\n TranslateSnapshot,\n Unsubscribe,\n} from './storeTypes';\nimport type { Dictionary } from 'gt-i18n/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport { subscribeToSet } from './utils/subscriptions';\nimport { Hash, Locale } from 'gt-i18n/internal/types';\nimport { getReactI18nCache } from '../i18n-cache/singleton-operations';\nimport { lookupTranslation } from './utils/translations';\nimport {\n lookupDictionaryEntry,\n lookupDictionaryObject,\n} from './utils/dictionaries';\n\nexport type DictionaryStoreListener = (event: DictionaryLookup) => void;\n\nconst MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS = 100;\n\nfunction getRuntimeTranslationErrorDedupeKey(error: unknown): string {\n if (error instanceof Error) {\n return `${error.name}|${error.message}`;\n }\n if (error !== null && typeof error === 'object') {\n try {\n return `object|${JSON.stringify(error)}`;\n } catch {\n return `object|${String(error)}`;\n }\n }\n return `${typeof error}|${String(error)}`;\n}\n\n/**\n * I18nStore gives us the ability to perform client-side updates to translations.\n * Primarily useful for dev hot reload.\n *\n * This is the stateful primitive behind lookup subscriptions and runtime\n * translation requests. It intentionally does not know whether lookups are\n * being served from SPA singletons or SRA provider snapshots; that policy lives\n * in LookupAdapter, not in this store.\n */\nexport class I18nStore {\n // ----- Listener Sets ----- //\n\n private translateListeners = new Set<TranslateEventListener>();\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private loggedRuntimeTranslationErrors = new Set<string>();\n\n /**\n * I18nCache must be already initialized\n */\n constructor() {}\n\n // ========== Translation Updates ========== //\n\n updateTranslations = (\n translations: Record<Locale, Record<Hash, Content>>\n ): void => {\n getReactI18nCache().updateTranslations(translations);\n };\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n getReactI18nCache().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translate = async <T extends Content>(\n lookup: TranslateLookup<T>\n ): Promise<void> => {\n return getReactI18nCache()\n .lookupTranslationWithFallback(\n lookup.locale,\n lookup.content,\n lookup.options\n )\n .then(() => {\n this.emitTranslateEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getReactI18nCache()\n .lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n /**\n * Runtime translation runs fire-and-forget, so a rejected request (for\n * example a 401 from an invalid dev API key) is logged here instead of\n * escaping as an unhandled rejection that kills the dev server during SSR.\n * Identical failures log once.\n */\n private logRuntimeTranslationError(error: unknown): void {\n const details = formatDiagnosticErrorDetails(error);\n const dedupeKey = getRuntimeTranslationErrorDedupeKey(error);\n if (this.loggedRuntimeTranslationErrors.has(dedupeKey)) return;\n this.loggedRuntimeTranslationErrors.add(dedupeKey);\n if (\n this.loggedRuntimeTranslationErrors.size >\n MAX_LOGGED_RUNTIME_TRANSLATION_ERRORS\n ) {\n const oldest = this.loggedRuntimeTranslationErrors.values().next().value;\n if (oldest !== undefined) {\n this.loggedRuntimeTranslationErrors.delete(oldest);\n }\n }\n console.error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'A runtime translation request failed.',\n wayOut: 'Rendering falls back to untranslated content.',\n details,\n })\n );\n }\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToTranslate = <T extends Content>(\n lookup: TranslateLookup<T>,\n listener: StoreListener\n ): Unsubscribe => {\n const lookupKey = getTranslateListenerKey(lookup);\n const wrappedListener: TranslateEventListener = (lookup) => {\n if (getTranslateListenerKey(lookup) === lookupKey) {\n listener();\n }\n };\n return subscribeToSet(this.translateListeners, wrappedListener);\n };\n\n subscribeToTranslationEvents = (\n listener: TranslateEventListener\n ): Unsubscribe => {\n return subscribeToSet(this.translateListeners, listener);\n };\n\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getTranslateSnapshot = <T extends Content>(\n lookup: TranslateLookup<T>,\n translationsSnapshot: Record<Locale, Record<Hash, Content>> = {}\n ): TranslateSnapshot<T> => {\n return (\n lookupTranslation(translationsSnapshot, lookup) ??\n getReactI18nCache().lookupTranslation<T>(\n lookup.locale,\n lookup.content,\n lookup.options\n )\n );\n };\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary> = {}\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getReactI18nCache().lookupDictionaryObj(lookup.locale, lookup.id)\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitTranslateEvent(event: TranslateLookup): void {\n this.translateListeners.forEach((listener) => listener(event));\n }\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"mcA8BA,SAAS,EAAoC,EAAwB,CACnE,GAAI,aAAiB,MACnB,MAAO,GAAG,EAAM,KAAK,GAAG,EAAM,UAEhC,GAAsB,OAAO,GAAU,UAAnC,EACF,GAAI,CACF,MAAO,UAAU,KAAK,UAAU,EAAM,QAChC,CACN,MAAO,UAAU,OAAO,EAAM,GAGlC,MAAO,GAAG,OAAO,EAAM,GAAG,OAAO,EAAM,GAYzC,IAAa,EAAb,KAAuB,CAGrB,mBAA6B,IAAI,IACjC,yBAAmC,IAAI,IACvC,0BAAoC,IAAI,IACxC,+BAAyC,IAAI,IAK7C,aAAc,EAId,mBACE,GACS,CACT,GAAmB,CAAC,mBAAmB,EAAa,EAGtD,mBAAsB,GAAmD,CACvE,GAAmB,CAAC,mBAAmB,EAAa,EAKtD,UAAY,KACV,IAEO,GAAmB,CACvB,8BACC,EAAO,OACP,EAAO,QACP,EAAO,QACR,CACA,SAAW,CACV,KAAK,mBAAmB,EAAO,EAC/B,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,CAG7D,yBAA4B,GAAmC,CAC7D,GAAmB,CAChB,6BAA6B,EAAO,OAAQ,EAAO,GAAG,CACtD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAG7D,0BAA6B,GAAmC,CAC9D,GAAmB,CAChB,gCAAgC,EAAO,OAAQ,EAAO,GAAG,CACzD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAS7D,2BAAmC,EAAsB,CACvD,IAAM,EAAU,EAA6B,EAAM,CAC7C,EAAY,EAAoC,EAAM,CACxD,SAAK,+BAA+B,IAAI,EAAU,CAEtD,IADA,KAAK,+BAA+B,IAAI,EAAU,CAEhD,KAAK,+BAA+B,KACpC,IACA,CACA,IAAM,EAAS,KAAK,+BAA+B,QAAQ,CAAC,MAAM,CAAC,MAC/D,IAAW,IAAA,IACb,KAAK,+BAA+B,OAAO,EAAO,CAGtD,QAAQ,MACN,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,wCACd,OAAQ,gDACR,UACD,CAAC,CACH,EASH,sBACE,EACA,IACgB,CAChB,IAAM,EAAY,EAAwB,EAAO,CAMjD,OAAO,EAAe,KAAK,mBALsB,GAAW,CACtD,EAAwB,EAAO,GAAK,GACtC,GAAU,EAGiD,EAGjE,6BACE,GAEO,EAAe,KAAK,mBAAoB,EAAS,CAG1D,iCACE,GAEO,EAAe,KAAK,yBAA0B,EAAS,CAGhE,kCACE,GAEO,EAAe,KAAK,0BAA2B,EAAS,CAKjE,sBACE,EACA,EAA8D,EAAE,GAG9D,EAAkB,EAAsB,EAAO,EAC/C,GAAmB,CAAC,kBAClB,EAAO,OACP,EAAO,QACP,EAAO,QACR,CAIL,4BACE,EACA,EAAmD,EAAE,GAGnD,EAAsB,EAAsB,EAAO,EACnD,GAAmB,CAAC,iBAAiB,EAAO,OAAQ,EAAO,GAAG,CAIlE,6BACE,EACA,EAAmD,EAAE,GAGnD,EAAuB,EAAsB,EAAO,EACpD,GAAmB,CAAC,oBAAoB,EAAO,OAAQ,EAAO,GAAG,CAMrE,mBAA2B,EAA8B,CACvD,KAAK,mBAAmB,QAAS,GAAa,EAAS,EAAM,CAAC,CAGhE,oBAA4B,EAA+B,CACzD,KAAK,yBAAyB,QAAS,GAAa,EAAS,EAAM,CAAC,CACpE,KAAK,0BAA0B,QAAS,GAAa,CACnD,EAAS,EAAM,EACf"}
|
|
@@ -8,7 +8,7 @@ type StoreListener = () => void;
|
|
|
8
8
|
type TranslateEventListener = (lookup: TranslateLookup) => void;
|
|
9
9
|
type TranslateLookup<T extends Content = Content> = {
|
|
10
10
|
locale: string;
|
|
11
|
-
|
|
11
|
+
content: T;
|
|
12
12
|
options: LookupOptions;
|
|
13
13
|
};
|
|
14
14
|
type DictionaryLookup = {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);let e=require(`gt-i18n/internal`);function t(t,n){let r=n.options.$_hash??(0,e.
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);let e=require(`gt-i18n/internal`);function t(t,n){let r=n.options.$_hash??(0,e.hashContent)(n.content,n.options);return t?.[n.locale]?.[r]}exports.lookupTranslation=t;
|
|
2
2
|
//# sourceMappingURL=translations.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations.cjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"translations.cjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import { hashContent } from 'gt-i18n/internal';\nimport type { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { TranslateLookup, TranslateSnapshot } from '../storeTypes';\n\nexport function lookupTranslation<T extends Content>(\n translationsSnapshot: Record<Locale, Record<Hash, Content>> | undefined,\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const hash =\n lookup.options.$_hash ?? hashContent(lookup.content, lookup.options);\n return translationsSnapshot?.[lookup.locale]?.[hash] as TranslateSnapshot<T>;\n}\n"],"mappings":"kFAKA,SAAgB,EACd,EACA,EACsB,CACtB,IAAM,EACJ,EAAO,QAAQ,SAAA,EAAA,EAAA,aAAsB,EAAO,QAAS,EAAO,QAAQ,CACtE,OAAO,IAAuB,EAAO,UAAU"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{hashContent as e}from"gt-i18n/internal";function t(t,n){let r=n.options.$_hash??e(n.content,n.options);return t?.[n.locale]?.[r]}export{t as lookupTranslation};
|
|
2
2
|
//# sourceMappingURL=translations.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations.mjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"translations.mjs","names":[],"sources":["../../../src/i18n-store/utils/translations.ts"],"sourcesContent":["import { hashContent } from 'gt-i18n/internal';\nimport type { Hash, Locale } from 'gt-i18n/internal/types';\nimport type { Content } from '@generaltranslation/format/types';\nimport type { TranslateLookup, TranslateSnapshot } from '../storeTypes';\n\nexport function lookupTranslation<T extends Content>(\n translationsSnapshot: Record<Locale, Record<Hash, Content>> | undefined,\n lookup: TranslateLookup<T>\n): TranslateSnapshot<T> {\n const hash =\n lookup.options.$_hash ?? hashContent(lookup.content, lookup.options);\n return translationsSnapshot?.[lookup.locale]?.[hash] as TranslateSnapshot<T>;\n}\n"],"mappings":"+CAKA,SAAgB,EACd,EACA,EACsB,CACtB,IAAM,EACJ,EAAO,QAAQ,QAAU,EAAY,EAAO,QAAS,EAAO,QAAQ,CACtE,OAAO,IAAuB,EAAO,UAAU"}
|
package/dist/unstable/useGT.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/condition-store.cjs`),t=require(`../hooks/utils.cjs`),n=require(`../hooks/external-store/useTrackedTranslationResolver.cjs`);let r=require(`react`),i=require(`gt-i18n/unstable/internal`);function a(){let{locale:a,shouldTranslate:o}=t.useTranslationConditions(),s=e.useEnableI18n(),c=n.useTrackedTranslationResolver(void 0,a,o);return(0,r.useMemo)(()=>(0,i.createGT)({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/condition-store.cjs`),t=require(`../hooks/utils.cjs`),n=require(`../hooks/external-store/useTrackedTranslationResolver.cjs`);let r=require(`react`),i=require(`gt-i18n/unstable/internal`);function a(){let{locale:a,shouldTranslate:o}=t.useTranslationConditions(),s=e.useEnableI18n(),c=n.useTrackedTranslationResolver(void 0,a,o);return(0,r.useMemo)(()=>(0,i.createGT)({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,content:e,options:t})}),[a,s,c])}exports.useGT=a;
|
|
2
2
|
//# sourceMappingURL=useGT.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.cjs","names":["useTranslationConditions","useEnableI18n","useTrackedTranslationResolver"],"sources":["../../src/unstable/useGT.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { GT } from 'gt-i18n/unstable';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns a GT bound to the render locale. Like the legacy useGT(), it reads\n * the provider's translations snapshot, then the I18nCache, and in dev hot\n * reload sends misses for runtime translation and re-renders when they\n * arrive. Other misses render the source.\n *\n * @example\n * const gt = useGT();\n * gt`Hello, ${{ name }}!`;\n */\nexport function useGT(): GT {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createGT({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (
|
|
1
|
+
{"version":3,"file":"useGT.cjs","names":["useTranslationConditions","useEnableI18n","useTrackedTranslationResolver"],"sources":["../../src/unstable/useGT.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { GT } from 'gt-i18n/unstable';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns a GT bound to the render locale. Like the legacy useGT(), it reads\n * the provider's translations snapshot, then the I18nCache, and in dev hot\n * reload sends misses for runtime translation and re-renders when they\n * arrive. Other misses render the source.\n *\n * @example\n * const gt = useGT();\n * gt`Hello, ${{ name }}!`;\n */\nexport function useGT(): GT {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createGT({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (tree, options) =>\n resolveTranslation({\n locale: options.$locale,\n content: tree,\n options,\n }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"kQAiBA,SAAgB,GAAY,CAC1B,GAAM,CAAE,SAAQ,mBAAoBA,EAAAA,0BAA0B,CACxD,EAAaC,EAAAA,eAAe,CAC5B,EAAqBC,EAAAA,8BACzB,IAAA,GACA,EACA,EACD,CACD,OAAA,EAAA,EAAA,cAAA,EAAA,EAAA,UAEa,CACP,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAM,IACxB,EAAmB,CACjB,OAAQ,EAAQ,QAChB,QAAS,EACT,UACD,CAAC,CACL,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
package/dist/unstable/useGT.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useEnableI18n as e}from"../hooks/condition-store.mjs";import{useTranslationConditions as t}from"../hooks/utils.mjs";import{useTrackedTranslationResolver as n}from"../hooks/external-store/useTrackedTranslationResolver.mjs";import{useMemo as r}from"react";import{createGT as i}from"gt-i18n/unstable/internal";function a(){let{locale:a,shouldTranslate:o}=t(),s=e(),c=n(void 0,a,o);return r(()=>i({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,
|
|
1
|
+
import{useEnableI18n as e}from"../hooks/condition-store.mjs";import{useTranslationConditions as t}from"../hooks/utils.mjs";import{useTrackedTranslationResolver as n}from"../hooks/external-store/useTrackedTranslationResolver.mjs";import{useMemo as r}from"react";import{createGT as i}from"gt-i18n/unstable/internal";function a(){let{locale:a,shouldTranslate:o}=t(),s=e(),c=n(void 0,a,o);return r(()=>i({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,content:e,options:t})}),[a,s,c])}export{a as useGT};
|
|
2
2
|
//# sourceMappingURL=useGT.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.mjs","names":[],"sources":["../../src/unstable/useGT.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { GT } from 'gt-i18n/unstable';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns a GT bound to the render locale. Like the legacy useGT(), it reads\n * the provider's translations snapshot, then the I18nCache, and in dev hot\n * reload sends misses for runtime translation and re-renders when they\n * arrive. Other misses render the source.\n *\n * @example\n * const gt = useGT();\n * gt`Hello, ${{ name }}!`;\n */\nexport function useGT(): GT {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createGT({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (
|
|
1
|
+
{"version":3,"file":"useGT.mjs","names":[],"sources":["../../src/unstable/useGT.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { GT } from 'gt-i18n/unstable';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns a GT bound to the render locale. Like the legacy useGT(), it reads\n * the provider's translations snapshot, then the I18nCache, and in dev hot\n * reload sends misses for runtime translation and re-renders when they\n * arrive. Other misses render the source.\n *\n * @example\n * const gt = useGT();\n * gt`Hello, ${{ name }}!`;\n */\nexport function useGT(): GT {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createGT({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (tree, options) =>\n resolveTranslation({\n locale: options.$locale,\n content: tree,\n options,\n }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"0TAiBA,SAAgB,GAAY,CAC1B,GAAM,CAAE,SAAQ,mBAAoB,GAA0B,CACxD,EAAa,GAAe,CAC5B,EAAqB,EACzB,IAAA,GACA,EACA,EACD,CACD,OAAO,MAEH,EAAS,CACP,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAM,IACxB,EAAmB,CACjB,OAAQ,EAAQ,QAChB,QAAS,EACT,UACD,CAAC,CACL,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/condition-store.cjs`),t=require(`../hooks/utils.cjs`),n=require(`../hooks/external-store/useTrackedTranslationResolver.cjs`);let r=require(`react`),i=require(`gt-i18n/unstable/internal`);function a(){let{locale:a,shouldTranslate:o}=t.useTranslationConditions(),s=e.useEnableI18n(),c=n.useTrackedTranslationResolver(void 0,a,o);return(0,r.useMemo)(()=>(0,i.createMessages)({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/condition-store.cjs`),t=require(`../hooks/utils.cjs`),n=require(`../hooks/external-store/useTrackedTranslationResolver.cjs`);let r=require(`react`),i=require(`gt-i18n/unstable/internal`);function a(){let{locale:a,shouldTranslate:o}=t.useTranslationConditions(),s=e.useEnableI18n(),c=n.useTrackedTranslationResolver(void 0,a,o);return(0,r.useMemo)(()=>(0,i.createMessages)({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,content:e,options:t})}),[a,s,c])}exports.useMessages=a;
|
|
2
2
|
//# sourceMappingURL=useMessages.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessages.cjs","names":["useTranslationConditions","useEnableI18n","useTrackedTranslationResolver"],"sources":["../../src/unstable/useMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { M } from 'gt-i18n/unstable';\nimport { createMessages } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns an m bound to the render locale, which renders messages from msg().\n * Like useGT(), it reads the provider's translations snapshot, then the\n * I18nCache, and in dev hot reload sends misses for runtime translation.\n *\n * @example\n * const m = useMessages();\n * m(msg`Hello, ${{ name }}!`);\n */\nexport function useMessages(): M {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createMessages({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (
|
|
1
|
+
{"version":3,"file":"useMessages.cjs","names":["useTranslationConditions","useEnableI18n","useTrackedTranslationResolver"],"sources":["../../src/unstable/useMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { M } from 'gt-i18n/unstable';\nimport { createMessages } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns an m bound to the render locale, which renders messages from msg().\n * Like useGT(), it reads the provider's translations snapshot, then the\n * I18nCache, and in dev hot reload sends misses for runtime translation.\n *\n * @example\n * const m = useMessages();\n * m(msg`Hello, ${{ name }}!`);\n */\nexport function useMessages(): M {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createMessages({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (tree, options) =>\n resolveTranslation({\n locale: options.$locale,\n content: tree,\n options,\n }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"kQAgBA,SAAgB,GAAiB,CAC/B,GAAM,CAAE,SAAQ,mBAAoBA,EAAAA,0BAA0B,CACxD,EAAaC,EAAAA,eAAe,CAC5B,EAAqBC,EAAAA,8BACzB,IAAA,GACA,EACA,EACD,CACD,OAAA,EAAA,EAAA,cAAA,EAAA,EAAA,gBAEmB,CACb,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAM,IACxB,EAAmB,CACjB,OAAQ,EAAQ,QAChB,QAAS,EACT,UACD,CAAC,CACL,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useEnableI18n as e}from"../hooks/condition-store.mjs";import{useTranslationConditions as t}from"../hooks/utils.mjs";import{useTrackedTranslationResolver as n}from"../hooks/external-store/useTrackedTranslationResolver.mjs";import{useMemo as r}from"react";import{createMessages as i}from"gt-i18n/unstable/internal";function a(){let{locale:a,shouldTranslate:o}=t(),s=e(),c=n(void 0,a,o);return r(()=>i({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,
|
|
1
|
+
import{useEnableI18n as e}from"../hooks/condition-store.mjs";import{useTranslationConditions as t}from"../hooks/utils.mjs";import{useTrackedTranslationResolver as n}from"../hooks/external-store/useTrackedTranslationResolver.mjs";import{useMemo as r}from"react";import{createMessages as i}from"gt-i18n/unstable/internal";function a(){let{locale:a,shouldTranslate:o}=t(),s=e(),c=n(void 0,a,o);return r(()=>i({getLocale:()=>a,getEnableI18n:()=>s,lookupTranslation:(e,t)=>c({locale:t.$locale,content:e,options:t})}),[a,s,c])}export{a as useMessages};
|
|
2
2
|
//# sourceMappingURL=useMessages.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessages.mjs","names":[],"sources":["../../src/unstable/useMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { M } from 'gt-i18n/unstable';\nimport { createMessages } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns an m bound to the render locale, which renders messages from msg().\n * Like useGT(), it reads the provider's translations snapshot, then the\n * I18nCache, and in dev hot reload sends misses for runtime translation.\n *\n * @example\n * const m = useMessages();\n * m(msg`Hello, ${{ name }}!`);\n */\nexport function useMessages(): M {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createMessages({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (
|
|
1
|
+
{"version":3,"file":"useMessages.mjs","names":[],"sources":["../../src/unstable/useMessages.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { M } from 'gt-i18n/unstable';\nimport { createMessages } from 'gt-i18n/unstable/internal';\nimport { useEnableI18n } from '../hooks/condition-store';\nimport { useTrackedTranslationResolver } from '../hooks/external-store/useTrackedTranslationResolver';\nimport { useTranslationConditions } from '../hooks/utils';\n\n/**\n * Returns an m bound to the render locale, which renders messages from msg().\n * Like useGT(), it reads the provider's translations snapshot, then the\n * I18nCache, and in dev hot reload sends misses for runtime translation.\n *\n * @example\n * const m = useMessages();\n * m(msg`Hello, ${{ name }}!`);\n */\nexport function useMessages(): M {\n const { locale, shouldTranslate } = useTranslationConditions();\n const enableI18n = useEnableI18n();\n const resolveTranslation = useTrackedTranslationResolver(\n undefined,\n locale,\n shouldTranslate\n );\n return useMemo(\n () =>\n createMessages({\n getLocale: () => locale,\n getEnableI18n: () => enableI18n,\n lookupTranslation: (tree, options) =>\n resolveTranslation({\n locale: options.$locale,\n content: tree,\n options,\n }),\n }),\n [locale, enableI18n, resolveTranslation]\n );\n}\n"],"mappings":"gUAgBA,SAAgB,GAAiB,CAC/B,GAAM,CAAE,SAAQ,mBAAoB,GAA0B,CACxD,EAAa,GAAe,CAC5B,EAAqB,EACzB,IAAA,GACA,EACA,EACD,CACD,OAAO,MAEH,EAAe,CACb,cAAiB,EACjB,kBAAqB,EACrB,mBAAoB,EAAM,IACxB,EAAmB,CACjB,OAAQ,EAAQ,QAChB,QAAS,EACT,UACD,CAAC,CACL,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);let e=require(`gt-i18n/internal`);function t(){let t=(0,e.getI18nConfig)();return typeof t.isIdTaggingEnabled==`function`&&t.isIdTaggingEnabled()}function n(...n){if(!t())return;let r=(0,e.
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);let e=require(`gt-i18n/internal`);function t(){let t=(0,e.getI18nConfig)();return typeof t.isIdTaggingEnabled==`function`&&t.isIdTaggingEnabled()}function n(...n){if(!t())return;let r=(0,e.hashContent)(...n);return n[1].$_hash=r,r}exports.idTaggingEnabled=t,exports.resolveTagHash=n;
|
|
2
2
|
//# sourceMappingURL=resolveTagHash.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTagHash.cjs","names":[],"sources":["../../../src/utils/translation/resolveTagHash.ts"],"sourcesContent":["import { getI18nConfig,
|
|
1
|
+
{"version":3,"file":"resolveTagHash.cjs","names":[],"sources":["../../../src/utils/translation/resolveTagHash.ts"],"sourcesContent":["import { getI18nConfig, hashContent } from 'gt-i18n/internal';\n\n// Capability-safe id-tagging gate. isIdTaggingEnabled lives on react-core's\n// ReactI18nConfig, but the config is a first-writer-wins singleton shared across\n// bundled package copies, so an OLDER copy — which has no isIdTaggingEnabled\n// method — can win initialization. Calling it unconditionally would throw a\n// TypeError on EVERY <T>/<Tx> render; treat a missing method as disabled.\nexport function idTaggingEnabled(): boolean {\n const config = getI18nConfig() as { isIdTaggingEnabled?: () => boolean };\n return (\n typeof config.isIdTaggingEnabled === 'function' &&\n config.isIdTaggingEnabled()\n );\n}\n\n// Single source of truth for the <T> id-tagging hash. Returns the translation\n// hash ONLY when id-tagging is enabled (otherwise `undefined` → the output is\n// rendered untouched, so apps not using the feature pay nothing).\n//\n// It also CACHES the result on `options.$_hash`. hashContent short-circuits to\n// `options.$_hash` when present, so every downstream hash of these same options\n// — the translation lookup (client store + RSC cache key both go through\n// hashContent) — reuses this value instead of hashing again. Net effect when\n// id-tagging is on: a single hash shared by tag + lookup, or ZERO extra hashing\n// when the compiler already injected `$_hash`. Called from prepareT (once,\n// BEFORE the lookup) so the lookup benefits from the cached value.\nexport function resolveTagHash(\n ...args: Parameters<typeof hashContent>\n): string | undefined {\n if (!idTaggingEnabled()) {\n return undefined;\n }\n const hash = hashContent(...args); // reuses args[1].$_hash when already set\n (args[1] as { $_hash?: string }).$_hash = hash; // cache for the lookup\n return hash;\n}\n"],"mappings":"kFAOA,SAAgB,GAA4B,CAC1C,IAAM,GAAA,EAAA,EAAA,gBAAwB,CAC9B,OACE,OAAO,EAAO,oBAAuB,YACrC,EAAO,oBAAoB,CAe/B,SAAgB,EACd,GAAG,EACiB,CACpB,GAAI,CAAC,GAAkB,CACrB,OAEF,IAAM,GAAA,EAAA,EAAA,aAAmB,GAAG,EAAK,CAEjC,MADC,GAAK,GAA2B,OAAS,EACnC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getI18nConfig as e,
|
|
1
|
+
import{getI18nConfig as e,hashContent as t}from"gt-i18n/internal";function n(){let t=e();return typeof t.isIdTaggingEnabled==`function`&&t.isIdTaggingEnabled()}function r(...e){if(!n())return;let r=t(...e);return e[1].$_hash=r,r}export{n as idTaggingEnabled,r as resolveTagHash};
|
|
2
2
|
//# sourceMappingURL=resolveTagHash.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTagHash.mjs","names":[],"sources":["../../../src/utils/translation/resolveTagHash.ts"],"sourcesContent":["import { getI18nConfig,
|
|
1
|
+
{"version":3,"file":"resolveTagHash.mjs","names":[],"sources":["../../../src/utils/translation/resolveTagHash.ts"],"sourcesContent":["import { getI18nConfig, hashContent } from 'gt-i18n/internal';\n\n// Capability-safe id-tagging gate. isIdTaggingEnabled lives on react-core's\n// ReactI18nConfig, but the config is a first-writer-wins singleton shared across\n// bundled package copies, so an OLDER copy — which has no isIdTaggingEnabled\n// method — can win initialization. Calling it unconditionally would throw a\n// TypeError on EVERY <T>/<Tx> render; treat a missing method as disabled.\nexport function idTaggingEnabled(): boolean {\n const config = getI18nConfig() as { isIdTaggingEnabled?: () => boolean };\n return (\n typeof config.isIdTaggingEnabled === 'function' &&\n config.isIdTaggingEnabled()\n );\n}\n\n// Single source of truth for the <T> id-tagging hash. Returns the translation\n// hash ONLY when id-tagging is enabled (otherwise `undefined` → the output is\n// rendered untouched, so apps not using the feature pay nothing).\n//\n// It also CACHES the result on `options.$_hash`. hashContent short-circuits to\n// `options.$_hash` when present, so every downstream hash of these same options\n// — the translation lookup (client store + RSC cache key both go through\n// hashContent) — reuses this value instead of hashing again. Net effect when\n// id-tagging is on: a single hash shared by tag + lookup, or ZERO extra hashing\n// when the compiler already injected `$_hash`. Called from prepareT (once,\n// BEFORE the lookup) so the lookup benefits from the cached value.\nexport function resolveTagHash(\n ...args: Parameters<typeof hashContent>\n): string | undefined {\n if (!idTaggingEnabled()) {\n return undefined;\n }\n const hash = hashContent(...args); // reuses args[1].$_hash when already set\n (args[1] as { $_hash?: string }).$_hash = hash; // cache for the lookup\n return hash;\n}\n"],"mappings":"kEAOA,SAAgB,GAA4B,CAC1C,IAAM,EAAS,GAAe,CAC9B,OACE,OAAO,EAAO,oBAAuB,YACrC,EAAO,oBAAoB,CAe/B,SAAgB,EACd,GAAG,EACiB,CACpB,GAAI,CAAC,GAAkB,CACrB,OAEF,IAAM,EAAO,EAAY,GAAG,EAAK,CAEjC,MADC,GAAK,GAA2B,OAAS,EACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generaltranslation/react-core",
|
|
3
|
-
"version": "12.0.0-samsara.
|
|
3
|
+
"version": "12.0.0-samsara.7",
|
|
4
4
|
"description": "A pure React library for internationalization",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"react": ">=18.0.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@generaltranslation/format": "1.0.0-samsara.
|
|
15
|
-
"generaltranslation": "10.0.0-samsara.
|
|
16
|
-
"gt-i18n": "2.0.0-samsara.
|
|
14
|
+
"@generaltranslation/format": "1.0.0-samsara.7",
|
|
15
|
+
"generaltranslation": "10.0.0-samsara.7",
|
|
16
|
+
"gt-i18n": "2.0.0-samsara.7"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Content } from "@generaltranslation/format/types";
|
|
2
|
-
import { TranslationMetadata } from "gt-i18n/internal/types";
|
|
3
|
-
|
|
4
|
-
//#region src/hooks/external-store/useTrackedTranslationResolver.d.ts
|
|
5
|
-
type Message = TranslationMetadata & {
|
|
6
|
-
message: string;
|
|
7
|
-
};
|
|
8
|
-
//#endregion
|
|
9
|
-
export { Message };
|
|
10
|
-
//# sourceMappingURL=useTrackedTranslationResolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTrackedTranslationResolver.d.ts","names":[],"sources":["../../../src/hooks/external-store/useTrackedTranslationResolver.ts"],"mappings":";;;;KA4BY,OAAA,GAAU,mBAAA;EACpB,OAAA;AAAA"}
|