@generaltranslation/react-core 12.0.0-samsara.0 → 12.0.0-samsara.2
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 +54 -0
- package/dist/context/InternalGTProvider.cjs.map +1 -1
- package/dist/context/InternalGTProvider.d.ts +3 -2
- package/dist/context/InternalGTProvider.d.ts.map +1 -1
- package/dist/context/InternalGTProvider.mjs.map +1 -1
- package/dist/context/context.cjs.map +1 -1
- package/dist/context/context.mjs.map +1 -1
- package/dist/functions/helpers/getTranslationsSnapshot.cjs.map +1 -1
- package/dist/functions/helpers/getTranslationsSnapshot.d.ts +2 -2
- package/dist/functions/helpers/getTranslationsSnapshot.d.ts.map +1 -1
- package/dist/functions/helpers/getTranslationsSnapshot.mjs.map +1 -1
- package/dist/functions/translation/t.cjs.map +1 -1
- package/dist/functions/translation/t.d.ts.map +1 -1
- package/dist/functions/translation/t.mjs.map +1 -1
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs +1 -1
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs.map +1 -1
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs +1 -1
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs.map +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs.map +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs.map +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs.map +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.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.d.ts +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.mjs +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
- package/dist/hooks/external-store.cjs.map +1 -1
- package/dist/hooks/external-store.mjs.map +1 -1
- package/dist/hooks/useTranslations.cjs +1 -1
- package/dist/hooks/useTranslations.cjs.map +1 -1
- package/dist/hooks/useTranslations.d.ts.map +1 -1
- package/dist/hooks/useTranslations.mjs +1 -1
- package/dist/hooks/useTranslations.mjs.map +1 -1
- package/dist/hooks/utils/missing-translation.cjs +1 -1
- package/dist/hooks/utils/missing-translation.cjs.map +1 -1
- package/dist/hooks/utils/missing-translation.d.ts +2 -2
- package/dist/hooks/utils/missing-translation.d.ts.map +1 -1
- package/dist/hooks/utils/missing-translation.mjs +1 -1
- package/dist/hooks/utils/missing-translation.mjs.map +1 -1
- package/dist/i18n-cache/ReactI18nCache.cjs.map +1 -1
- package/dist/i18n-cache/ReactI18nCache.d.ts +2 -2
- package/dist/i18n-cache/ReactI18nCache.d.ts.map +1 -1
- package/dist/i18n-cache/ReactI18nCache.mjs.map +1 -1
- package/dist/i18n-cache/singleton-operations.cjs.map +1 -1
- package/dist/i18n-cache/singleton-operations.mjs.map +1 -1
- package/dist/i18n-store/I18nStore.cjs.map +1 -1
- package/dist/i18n-store/I18nStore.d.ts +6 -5
- package/dist/i18n-store/I18nStore.d.ts.map +1 -1
- package/dist/i18n-store/I18nStore.mjs.map +1 -1
- package/dist/i18n-store/storeTypes.d.ts +4 -3
- package/dist/i18n-store/storeTypes.d.ts.map +1 -1
- package/dist/i18n-store/useI18nStore.cjs.map +1 -1
- package/dist/i18n-store/useI18nStore.mjs.map +1 -1
- package/dist/i18n-store/utils/translations.cjs.map +1 -1
- package/dist/i18n-store/utils/translations.mjs.map +1 -1
- package/dist/unstable/t.cjs +2 -0
- package/dist/unstable/t.cjs.map +1 -0
- package/dist/unstable/t.d.ts +16 -0
- package/dist/unstable/t.d.ts.map +1 -0
- package/dist/unstable/t.mjs +2 -0
- package/dist/unstable/t.mjs.map +1 -0
- package/dist/unstable/useGT.cjs +2 -0
- package/dist/unstable/useGT.cjs.map +1 -0
- package/dist/unstable/useGT.d.ts +17 -0
- package/dist/unstable/useGT.d.ts.map +1 -0
- package/dist/unstable/useGT.mjs +2 -0
- package/dist/unstable/useGT.mjs.map +1 -0
- package/dist/unstable/useMessages.cjs +2 -0
- package/dist/unstable/useMessages.cjs.map +1 -0
- package/dist/unstable/useMessages.d.ts +16 -0
- package/dist/unstable/useMessages.d.ts.map +1 -0
- package/dist/unstable/useMessages.mjs +2 -0
- package/dist/unstable/useMessages.mjs.map +1 -0
- package/dist/unstable.cjs +1 -0
- package/dist/unstable.d.mts +1 -0
- package/dist/unstable.d.ts +5 -0
- package/dist/unstable.mjs +1 -0
- package/package.json +14 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GT } from "gt-i18n/unstable";
|
|
2
|
+
|
|
3
|
+
//#region src/unstable/t.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Translates a message tree with the current locale. Client-rendered (SPA)
|
|
6
|
+
* apps only, where it also works at module level; server-rendered apps use
|
|
7
|
+
* useGT() or getGT().
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* t`Hello, ${{ name }}!`;
|
|
11
|
+
* t({ context: 'button' })`Save`;
|
|
12
|
+
*/
|
|
13
|
+
declare const t: GT;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { t };
|
|
16
|
+
//# sourceMappingURL=t.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t.d.ts","names":[],"sources":["../../src/unstable/t.ts"],"mappings":";;;;;AAqDA;;;;;;;cAAa,CAAA,EAUP,EAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getI18nConfig as e}from"../setup/i18nConfig.mjs";import{getConditionStore as t}from"../condition-store/singleton-operations.mjs";import{getRuntimeEnvironment as n}from"gt-i18n/internal";import{createDiagnosticMessage as r}from"generaltranslation/internal";import{createGT as i}from"gt-i18n/unstable/internal";const a=()=>e().getRenderStrategy()===`SPA`,o=i({getLocale:()=>t().getLocale(),getEnableI18n:()=>a()&&t().getEnableI18n()});function s(e){let t=n()===`development`,i=r({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`t from /unstable is only available in client-rendered (SPA) apps`,fix:`In components, use useGT(); on the server, use getGT()`,wayOut:t?void 0:`The source message was rendered`,details:`Message: "${e.join(``)}"`});if(t)throw Error(i);console.error(i)}function c(e,t,n){return a()||s(t),e(t,...n)}const l=((e,...t)=>{if(Array.isArray(e))return c(o,e,t);let n=o(e);return(e,...t)=>c(n,e,t)});export{l as t};
|
|
2
|
+
//# sourceMappingURL=t.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t.mjs","names":["getI18nConfig","getReadonlyConditionStore"],"sources":["../../src/unstable/t.ts"],"sourcesContent":["import type { GT, GTOptions } from 'gt-i18n/unstable';\nimport { getRuntimeEnvironment } from 'gt-i18n/internal';\nimport { createGT } from 'gt-i18n/unstable/internal';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { getReadonlyConditionStore } from '../condition-store/singleton-operations';\nimport { getI18nConfig } from '../setup/i18nConfig';\n\ntype LooseTag = (strings: TemplateStringsArray, ...holes: unknown[]) => string;\n\n// Only a client-rendered app knows its locale and has its catalog loaded\n// wherever t runs, module level included. Server renders use useGT() or\n// getGT(), which load the request locale first.\nconst isSpa = () => getI18nConfig().getRenderStrategy() === 'SPA';\n\nconst gt = /* @__PURE__ */ createGT({\n getLocale: () => getReadonlyConditionStore().getLocale(),\n // Outside an SPA, t renders the source once the misuse is reported.\n getEnableI18n: () => isSpa() && getReadonlyConditionStore().getEnableI18n(),\n}) as unknown as LooseTag & ((options: GTOptions) => LooseTag);\n\nfunction reportServerRenderedUse(strings: TemplateStringsArray): void {\n const development = getRuntimeEnvironment() === 'development';\n const message = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 't from /unstable is only available in client-rendered (SPA) apps',\n fix: 'In components, use useGT(); on the server, use getGT()',\n wayOut: development ? undefined : 'The source message was rendered',\n details: `Message: \"${strings.join('')}\"`,\n });\n if (development) throw new Error(message);\n console.error(message);\n}\n\nfunction translate(\n tag: LooseTag,\n strings: TemplateStringsArray,\n holes: unknown[]\n): string {\n if (!isSpa()) reportServerRenderedUse(strings);\n return tag(strings, ...holes);\n}\n\n/**\n * Translates a message tree with the current locale. Client-rendered (SPA)\n * apps only, where it also works at module level; server-rendered apps use\n * useGT() or getGT().\n *\n * @example\n * t`Hello, ${{ name }}!`;\n * t({ context: 'button' })`Save`;\n */\nexport const t = ((\n first: TemplateStringsArray | GTOptions,\n ...holes: unknown[]\n) => {\n if (Array.isArray(first)) {\n return translate(gt, first as unknown as TemplateStringsArray, holes);\n }\n const tag = gt(first as GTOptions);\n return (strings: TemplateStringsArray, ...nested: unknown[]) =>\n translate(tag, strings, nested);\n}) as GT;\n"],"mappings":"4TAYA,MAAM,MAAcA,GAAe,CAAC,mBAAmB,GAAK,MAEtD,EAAqB,EAAS,CAClC,cAAiBC,GAA2B,CAAC,WAAW,CAExD,kBAAqB,GAAO,EAAIA,GAA2B,CAAC,eAAe,CAC5E,CAAC,CAEF,SAAS,EAAwB,EAAqC,CACpE,IAAM,EAAc,GAAuB,GAAK,cAC1C,EAAU,EAAwB,CACtC,OAAQ,iCACR,SAAU,QACV,aACE,mEACF,IAAK,yDACL,OAAQ,EAAc,IAAA,GAAY,kCAClC,QAAS,aAAa,EAAQ,KAAK,GAAG,CAAC,GACxC,CAAC,CACF,GAAI,EAAa,MAAU,MAAM,EAAQ,CACzC,QAAQ,MAAM,EAAQ,CAGxB,SAAS,EACP,EACA,EACA,EACQ,CAER,OADK,GAAO,EAAE,EAAwB,EAAQ,CACvC,EAAI,EAAS,GAAG,EAAM,CAY/B,MAAa,IACX,EACA,GAAG,IACA,CACH,GAAI,MAAM,QAAQ,EAAM,CACtB,OAAO,EAAU,EAAI,EAA0C,EAAM,CAEvE,IAAM,EAAM,EAAG,EAAmB,CAClC,OAAQ,EAA+B,GAAG,IACxC,EAAU,EAAK,EAAS,EAAO"}
|
|
@@ -0,0 +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,message:e,options:t})}),[a,s,c])}exports.useGT=a;
|
|
2
|
+
//# sourceMappingURL=useGT.cjs.map
|
|
@@ -0,0 +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: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\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,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GT } from "gt-i18n/unstable";
|
|
2
|
+
|
|
3
|
+
//#region src/unstable/useGT.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns a GT bound to the render locale. Like the legacy useGT(), it reads
|
|
6
|
+
* the provider's translations snapshot, then the I18nCache, and in dev hot
|
|
7
|
+
* reload sends misses for runtime translation and re-renders when they
|
|
8
|
+
* arrive. Other misses render the source.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const gt = useGT();
|
|
12
|
+
* gt`Hello, ${{ name }}!`;
|
|
13
|
+
*/
|
|
14
|
+
declare function useGT(): GT;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { useGT };
|
|
17
|
+
//# sourceMappingURL=useGT.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGT.d.ts","names":[],"sources":["../../src/unstable/useGT.ts"],"mappings":";;;;;AAiBA;;;;;;;;iBAAgB,KAAA,CAAA,GAAS,EAAA"}
|
|
@@ -0,0 +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,message:e,options:t})}),[a,s,c])}export{a as useGT};
|
|
2
|
+
//# sourceMappingURL=useGT.mjs.map
|
|
@@ -0,0 +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: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\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,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
|
@@ -0,0 +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,message:e,options:t})}),[a,s,c])}exports.useMessages=a;
|
|
2
|
+
//# sourceMappingURL=useMessages.cjs.map
|
|
@@ -0,0 +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: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\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,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { M } from "gt-i18n/unstable";
|
|
2
|
+
|
|
3
|
+
//#region src/unstable/useMessages.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns an m bound to the render locale, which renders messages from msg().
|
|
6
|
+
* Like useGT(), it reads the provider's translations snapshot, then the
|
|
7
|
+
* I18nCache, and in dev hot reload sends misses for runtime translation.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const m = useMessages();
|
|
11
|
+
* m(msg`Hello, ${{ name }}!`);
|
|
12
|
+
*/
|
|
13
|
+
declare function useMessages(): M;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { useMessages };
|
|
16
|
+
//# sourceMappingURL=useMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessages.d.ts","names":[],"sources":["../../src/unstable/useMessages.ts"],"mappings":";;;;;AAgBA;;;;;;;iBAAgB,WAAA,CAAA,GAAe,CAAA"}
|
|
@@ -0,0 +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,message:e,options:t})}),[a,s,c])}export{a as useMessages};
|
|
2
|
+
//# sourceMappingURL=useMessages.mjs.map
|
|
@@ -0,0 +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: (message, options) =>\n resolveTranslation({ locale: options.$locale, message, options }),\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,EAAS,IAC3B,EAAmB,CAAE,OAAQ,EAAQ,QAAS,UAAS,UAAS,CAAC,CACpE,CAAC,CACJ,CAAC,EAAQ,EAAY,EAAmB,CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./unstable/t.cjs`),t=require(`./unstable/useGT.cjs`),n=require(`./unstable/useMessages.cjs`);let r=require(`gt-i18n/unstable`);Object.defineProperty(exports,`date`,{enumerable:!0,get:function(){return r.date}}),Object.defineProperty(exports,`derive`,{enumerable:!0,get:function(){return r.derive}}),Object.defineProperty(exports,`mFallback`,{enumerable:!0,get:function(){return r.mFallback}}),Object.defineProperty(exports,`msg`,{enumerable:!0,get:function(){return r.msg}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return r.n}}),Object.defineProperty(exports,`number`,{enumerable:!0,get:function(){return r.number}}),Object.defineProperty(exports,`part`,{enumerable:!0,get:function(){return r.part}}),Object.defineProperty(exports,`plural`,{enumerable:!0,get:function(){return r.plural}}),Object.defineProperty(exports,`select`,{enumerable:!0,get:function(){return r.select}}),Object.defineProperty(exports,`selectordinal`,{enumerable:!0,get:function(){return r.selectordinal}}),exports.t=e.t,exports.useGT=t.useGT,exports.useMessages=n.useMessages;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './unstable.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { t } from "./unstable/t.js";
|
|
2
|
+
import { useGT } from "./unstable/useGT.js";
|
|
3
|
+
import { useMessages } from "./unstable/useMessages.js";
|
|
4
|
+
import { Fragment, GT, GTOptions, M, Msg, Placeholder, date, derive, mFallback, msg, n, number, part, plural, select, selectordinal } from "gt-i18n/unstable";
|
|
5
|
+
export { type Fragment, type GT, type GTOptions, type M, type Msg, type Placeholder, date, derive, mFallback, msg, n, number, part, plural, select, selectordinal, t, useGT, useMessages };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./unstable/t.mjs";import{useGT as t}from"./unstable/useGT.mjs";import{useMessages as n}from"./unstable/useMessages.mjs";import{date as r,derive as i,mFallback as a,msg as o,n as s,number as c,part as l,plural as u,select as d,selectordinal as f}from"gt-i18n/unstable";export{r as date,i as derive,a as mFallback,o as msg,s as n,c as number,l as part,u as plural,d as select,f as selectordinal,e as t,t as useGT,n as useMessages};
|
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.2",
|
|
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.3",
|
|
15
|
+
"generaltranslation": "10.0.0-samsara.2",
|
|
16
|
+
"gt-i18n": "2.0.0-samsara.2"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -71,6 +71,16 @@
|
|
|
71
71
|
"types": "./dist/components-rsc.d.mts",
|
|
72
72
|
"default": "./dist/components-rsc.mjs"
|
|
73
73
|
}
|
|
74
|
+
},
|
|
75
|
+
"./unstable": {
|
|
76
|
+
"require": {
|
|
77
|
+
"types": "./dist/unstable.d.ts",
|
|
78
|
+
"default": "./dist/unstable.cjs"
|
|
79
|
+
},
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/unstable.d.mts",
|
|
82
|
+
"default": "./dist/unstable.mjs"
|
|
83
|
+
}
|
|
74
84
|
}
|
|
75
85
|
},
|
|
76
86
|
"keywords": [
|