@generaltranslation/react-core 11.0.0-odysseus.13 → 11.0.0-odysseus.15
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 +88 -0
- package/dist/components/branches/Plural.shared.cjs +1 -1
- package/dist/components/branches/Plural.shared.cjs.map +1 -1
- package/dist/components/branches/Plural.shared.mjs +1 -1
- package/dist/components/branches/Plural.shared.mjs.map +1 -1
- package/dist/components-rsc.cjs +1 -1
- package/dist/components-rsc.d.ts +2 -2
- package/dist/components-rsc.mjs +1 -1
- package/dist/condition-store/singleton-operations.cjs +1 -1
- package/dist/condition-store/singleton-operations.cjs.map +1 -1
- package/dist/condition-store/singleton-operations.d.ts +2 -7
- package/dist/condition-store/singleton-operations.d.ts.map +1 -1
- package/dist/condition-store/singleton-operations.mjs +1 -1
- package/dist/condition-store/singleton-operations.mjs.map +1 -1
- package/dist/context/context.cjs +1 -1
- package/dist/context/context.cjs.map +1 -1
- package/dist/context/context.mjs +1 -1
- package/dist/context/context.mjs.map +1 -1
- package/dist/functions/translation/t.cjs +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 +1 -1
- package/dist/functions/translation/t.mjs.map +1 -1
- package/dist/hooks/condition-store.cjs +1 -1
- package/dist/hooks/condition-store.cjs.map +1 -1
- package/dist/hooks/condition-store.mjs +1 -1
- package/dist/hooks/condition-store.mjs.map +1 -1
- package/dist/hooks/useGT.cjs +1 -1
- package/dist/hooks/useGT.cjs.map +1 -1
- package/dist/hooks/useGT.mjs +1 -1
- package/dist/hooks/useGT.mjs.map +1 -1
- package/dist/hooks/useInternalLocaleSelector.cjs +1 -1
- package/dist/hooks/useInternalLocaleSelector.cjs.map +1 -1
- package/dist/hooks/useInternalLocaleSelector.mjs +1 -1
- package/dist/hooks/useInternalLocaleSelector.mjs.map +1 -1
- package/dist/hooks/useInternalRegionSelector.cjs +1 -1
- package/dist/hooks/useInternalRegionSelector.cjs.map +1 -1
- package/dist/hooks/useInternalRegionSelector.mjs +1 -1
- package/dist/hooks/useInternalRegionSelector.mjs.map +1 -1
- package/dist/hooks/utils/getShouldTranslate.cjs +1 -1
- package/dist/hooks/utils/getShouldTranslate.cjs.map +1 -1
- package/dist/hooks/utils/getShouldTranslate.mjs +1 -1
- package/dist/hooks/utils/getShouldTranslate.mjs.map +1 -1
- package/dist/hooks/utils.d.ts +2 -2
- package/dist/hooks/utils.d.ts.map +1 -1
- package/dist/pure.cjs +1 -1
- package/dist/pure.d.ts +4 -5
- package/dist/pure.mjs +1 -1
- package/dist/setup/i18nConfig.cjs +1 -1
- package/dist/setup/i18nConfig.cjs.map +1 -1
- package/dist/setup/i18nConfig.d.ts +31 -3
- package/dist/setup/i18nConfig.d.ts.map +1 -1
- package/dist/setup/i18nConfig.mjs +1 -1
- package/dist/setup/i18nConfig.mjs.map +1 -1
- package/dist/setup/initializeGTSRA.cjs.map +1 -1
- package/dist/setup/initializeGTSRA.d.ts +2 -2
- package/dist/setup/initializeGTSRA.d.ts.map +1 -1
- package/dist/setup/initializeGTSRA.mjs.map +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.cjs +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.cjs.map +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.mjs +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.mjs.map +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.cjs +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.cjs.map +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.mjs +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.mjs.map +1 -1
- package/dist/utils/translation/prepareT.shared.cjs +1 -1
- package/dist/utils/translation/prepareT.shared.cjs.map +1 -1
- package/dist/utils/translation/prepareT.shared.mjs +1 -1
- package/dist/utils/translation/prepareT.shared.mjs.map +1 -1
- package/package.json +4 -15
- package/dist/cookies.cjs +0 -1
- package/dist/cookies.d.ts +0 -2
- package/dist/cookies.mjs +0 -1
- package/dist/utils/cookies.cjs +0 -2
- package/dist/utils/cookies.cjs.map +0 -1
- package/dist/utils/cookies.d.ts +0 -16
- package/dist/utils/cookies.d.ts.map +0 -1
- package/dist/utils/cookies.mjs +0 -2
- package/dist/utils/cookies.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @generaltranslation/react-core
|
|
2
2
|
|
|
3
|
+
## 11.0.0-odysseus.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 04f419d: Fix source interpolation for default-locale string helpers.
|
|
8
|
+
Clarify that `tx()` does not apply ICU formatting by default.
|
|
9
|
+
- 72e9e16: Split the runtime surface of the GT class (locale management, formatting, runtime translation) into a GTRuntime base class exported from the new `generaltranslation/runtime` entry point. The SDK runtime (gt-i18n's I18nConfig, gt-next middleware) now constructs GTRuntime, so production browser bundles no longer ship the project/file management API client (enqueueFiles, uploads, downloads, etc.). The GT class extends GTRuntime and keeps its full API for the CLI and other tooling. Also import getLocaleProperties from @generaltranslation/format directly in react-core so client bundles don't reach the full core entry.
|
|
10
|
+
- 195f009: fix: make singleton not-initialized errors consistent and descriptive, and stop error paths from masking the original failure when I18nConfig is also uninitialized
|
|
11
|
+
- Updated dependencies [72e9e16]
|
|
12
|
+
- Updated dependencies [42a440f]
|
|
13
|
+
- Updated dependencies [5adeede]
|
|
14
|
+
- Updated dependencies [c5364f9]
|
|
15
|
+
- Updated dependencies [2e85ebd]
|
|
16
|
+
- Updated dependencies [195f009]
|
|
17
|
+
- generaltranslation@9.0.0-odysseus.5
|
|
18
|
+
- gt-i18n@1.0.0-odysseus.8
|
|
19
|
+
- @generaltranslation/supported-locales@2.1.2-odysseus.5
|
|
20
|
+
|
|
21
|
+
## 11.0.0-odysseus.14
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 0cd7813: Store cookie names in I18nConfig so custom cookie names work before the condition store is initialized.
|
|
26
|
+
- `gt-i18n`: Removed the unused React locale cookie name from the shared GT config type.
|
|
27
|
+
- `@generaltranslation/react-core`: `ReactI18nConfig` now accepts `localeCookieName`, `regionCookieName`, and `enableI18nCookieName`, exposes getters that fall back to the default names, and exports the default storage names from the `pure` entrypoint.
|
|
28
|
+
- `gt-next`: Imports default cookie names from the React Core `pure` entrypoint instead of the removed React Core cookie constants subpath.
|
|
29
|
+
- `gt-react`: The browser condition store now resolves cookie names from `I18nConfig` instead of hardcoding the defaults, so custom cookie names passed to `initializeGT()` are honored for both reads and writes.
|
|
30
|
+
- `gt-react-native`: Native condition storage now resolves its store keys from `I18nConfig`, matching `gt-react` behavior.
|
|
31
|
+
- `gt-tanstack-start`: `parseLocale()` reads and writes the locale cookie using the configured cookie name instead of the default.
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [ab61565]
|
|
34
|
+
- Updated dependencies [0cd7813]
|
|
35
|
+
- gt-i18n@1.0.0-odysseus.7
|
|
36
|
+
|
|
3
37
|
## 11.0.0-odysseus.13
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
|
@@ -168,6 +202,60 @@
|
|
|
168
202
|
|
|
169
203
|
### Patch Changes
|
|
170
204
|
|
|
205
|
+
- Updated dependencies [[`cc4edc1`](https://github.com/generaltranslation/gt/commit/cc4edc1e40d9977125bf6d053fb7f8cdbdd40b05)]:
|
|
206
|
+
- @generaltranslation/supported-locales@2.1.0
|
|
207
|
+
- gt-i18n@0.9.4
|
|
208
|
+
|
|
209
|
+
## 1.8.25
|
|
210
|
+
|
|
211
|
+
### Patch Changes
|
|
212
|
+
|
|
213
|
+
- [#1786](https://github.com/generaltranslation/gt/pull/1786) [`6945a98`](https://github.com/generaltranslation/gt/commit/6945a9871ea260dd999dcb2246c48b21134721f6) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Add `requiresReview`
|
|
214
|
+
|
|
215
|
+
- Updated dependencies [[`6945a98`](https://github.com/generaltranslation/gt/commit/6945a9871ea260dd999dcb2246c48b21134721f6)]:
|
|
216
|
+
- generaltranslation@8.2.19
|
|
217
|
+
- gt-i18n@0.9.9
|
|
218
|
+
- @generaltranslation/supported-locales@2.1.5
|
|
219
|
+
|
|
220
|
+
## 1.8.24
|
|
221
|
+
|
|
222
|
+
### Patch Changes
|
|
223
|
+
|
|
224
|
+
- Updated dependencies [[`a2a3dd0`](https://github.com/generaltranslation/gt/commit/a2a3dd0bcdce9abe360c406a12fc6bb3bc3ca181)]:
|
|
225
|
+
- @generaltranslation/supported-locales@2.1.4
|
|
226
|
+
- gt-i18n@0.9.8
|
|
227
|
+
|
|
228
|
+
## 1.8.23
|
|
229
|
+
|
|
230
|
+
### Patch Changes
|
|
231
|
+
|
|
232
|
+
- Updated dependencies [[`9709a2f`](https://github.com/generaltranslation/gt/commit/9709a2f2b97b9d8239298e39bb31e57692bbffd8)]:
|
|
233
|
+
- generaltranslation@8.2.18
|
|
234
|
+
- gt-i18n@0.9.7
|
|
235
|
+
- @generaltranslation/supported-locales@2.1.3
|
|
236
|
+
|
|
237
|
+
## 1.8.22
|
|
238
|
+
|
|
239
|
+
### Patch Changes
|
|
240
|
+
|
|
241
|
+
- Updated dependencies [[`3197028`](https://github.com/generaltranslation/gt/commit/319702855a7b129f95217d41be9f2402680a2f01)]:
|
|
242
|
+
- generaltranslation@8.2.17
|
|
243
|
+
- gt-i18n@0.9.6
|
|
244
|
+
- @generaltranslation/supported-locales@2.1.2
|
|
245
|
+
|
|
246
|
+
## 1.8.21
|
|
247
|
+
|
|
248
|
+
### Patch Changes
|
|
249
|
+
|
|
250
|
+
- Updated dependencies [[`e041312`](https://github.com/generaltranslation/gt/commit/e04131263dd61e469db977bcc196dc1283e773d0)]:
|
|
251
|
+
- generaltranslation@8.2.16
|
|
252
|
+
- gt-i18n@0.9.5
|
|
253
|
+
- @generaltranslation/supported-locales@2.1.1
|
|
254
|
+
|
|
255
|
+
## 1.8.20
|
|
256
|
+
|
|
257
|
+
### Patch Changes
|
|
258
|
+
|
|
171
259
|
- Updated dependencies [[`cc4edc1`](https://github.com/generaltranslation/gt/commit/cc4edc1e40d9977125bf6d053fb7f8cdbdd40b05)]:
|
|
172
260
|
- @generaltranslation/supported-locales@2.1.0
|
|
173
261
|
- gt-i18n@0.9.4
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../../utils/plurals/getPluralBranch.cjs`),t=require(`../../hooks/utils/getFormatLocales.cjs`);function n({_enableI18n:n,_locale:r,children:i,n:a,locales:o=[],...s}){let c=t.getFormatLocales({locale:r,enableI18n:n,localesProp:o});return typeof a==`number
|
|
1
|
+
const e=require(`../../utils/plurals/getPluralBranch.cjs`),t=require(`../../hooks/utils/getFormatLocales.cjs`);function n({_enableI18n:n,_locale:r,children:i,n:a,locales:o=[],...s}){let c=t.getFormatLocales({locale:r,enableI18n:n,localesProp:o});return typeof a==`number`?e.getPluralBranch(a,c,s)??i:i}exports.renderPlural=n;
|
|
2
2
|
//# sourceMappingURL=Plural.shared.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plural.shared.cjs","names":["getFormatLocales","getPluralBranch"],"sources":["../../../src/components/branches/Plural.shared.ts"],"sourcesContent":["import { getPluralBranch } from '../../utils/plurals/getPluralBranch';\nimport type { ReactNode } from 'react';\nimport { getFormatLocales } from '../../hooks/utils/getFormatLocales';\n\n// Pure render logic shared by the hook-based and RSC implementations. This\n// module must stay free of hook/context imports so it can be reached from the\n// components-rsc entrypoint.\n\ntype PluralProps = {\n children?: ReactNode;\n n: number;\n locales?: string[];\n _locale?: string;\n _enableI18n?: boolean;\n [key: string]: ReactNode;\n};\n\ntype ResolvedPluralProps = PluralProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction renderPlural({\n _enableI18n,\n _locale,\n children,\n n,\n locales: localesProp = [],\n ...branches\n}: ResolvedPluralProps): ReactNode {\n const locales = getFormatLocales({\n locale: _locale,\n enableI18n: _enableI18n,\n localesProp,\n });\n if (typeof n !== 'number') {\n return children;\n }\n
|
|
1
|
+
{"version":3,"file":"Plural.shared.cjs","names":["getFormatLocales","getPluralBranch"],"sources":["../../../src/components/branches/Plural.shared.ts"],"sourcesContent":["import { getPluralBranch } from '../../utils/plurals/getPluralBranch';\nimport type { ReactNode } from 'react';\nimport { getFormatLocales } from '../../hooks/utils/getFormatLocales';\n\n// Pure render logic shared by the hook-based and RSC implementations. This\n// module must stay free of hook/context imports so it can be reached from the\n// components-rsc entrypoint.\n\ntype PluralProps = {\n children?: ReactNode;\n n: number;\n locales?: string[];\n _locale?: string;\n _enableI18n?: boolean;\n [key: string]: ReactNode;\n};\n\ntype ResolvedPluralProps = PluralProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction renderPlural({\n _enableI18n,\n _locale,\n children,\n n,\n locales: localesProp = [],\n ...branches\n}: ResolvedPluralProps): ReactNode {\n const locales = getFormatLocales({\n locale: _locale,\n enableI18n: _enableI18n,\n localesProp,\n });\n if (typeof n !== 'number') {\n return children;\n }\n const resolvedBranch = getPluralBranch(n, locales, branches);\n return resolvedBranch != null ? resolvedBranch : children;\n}\n\nexport { renderPlural };\nexport type { PluralProps, ResolvedPluralProps };\n"],"mappings":"+GAsBA,SAAS,EAAa,CACpB,cACA,UACA,WACA,IACA,QAAS,EAAc,EAAE,CACzB,GAAG,GAC8B,CACjC,IAAM,EAAUA,EAAAA,iBAAiB,CAC/B,OAAQ,EACR,WAAY,EACZ,cACD,CAAC,CAKF,OAJI,OAAO,GAAM,SAGMC,EAAAA,gBAAgB,EAAG,EAAS,EAC5C,EAA0C,EAHxC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getPluralBranch as e}from"../../utils/plurals/getPluralBranch.mjs";import{getFormatLocales as t}from"../../hooks/utils/getFormatLocales.mjs";function n({_enableI18n:n,_locale:r,children:i,n:a,locales:o=[],...s}){let c=t({locale:r,enableI18n:n,localesProp:o});return typeof a==`number
|
|
1
|
+
import{getPluralBranch as e}from"../../utils/plurals/getPluralBranch.mjs";import{getFormatLocales as t}from"../../hooks/utils/getFormatLocales.mjs";function n({_enableI18n:n,_locale:r,children:i,n:a,locales:o=[],...s}){let c=t({locale:r,enableI18n:n,localesProp:o});return typeof a==`number`?e(a,c,s)??i:i}export{n as renderPlural};
|
|
2
2
|
//# sourceMappingURL=Plural.shared.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plural.shared.mjs","names":[],"sources":["../../../src/components/branches/Plural.shared.ts"],"sourcesContent":["import { getPluralBranch } from '../../utils/plurals/getPluralBranch';\nimport type { ReactNode } from 'react';\nimport { getFormatLocales } from '../../hooks/utils/getFormatLocales';\n\n// Pure render logic shared by the hook-based and RSC implementations. This\n// module must stay free of hook/context imports so it can be reached from the\n// components-rsc entrypoint.\n\ntype PluralProps = {\n children?: ReactNode;\n n: number;\n locales?: string[];\n _locale?: string;\n _enableI18n?: boolean;\n [key: string]: ReactNode;\n};\n\ntype ResolvedPluralProps = PluralProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction renderPlural({\n _enableI18n,\n _locale,\n children,\n n,\n locales: localesProp = [],\n ...branches\n}: ResolvedPluralProps): ReactNode {\n const locales = getFormatLocales({\n locale: _locale,\n enableI18n: _enableI18n,\n localesProp,\n });\n if (typeof n !== 'number') {\n return children;\n }\n
|
|
1
|
+
{"version":3,"file":"Plural.shared.mjs","names":[],"sources":["../../../src/components/branches/Plural.shared.ts"],"sourcesContent":["import { getPluralBranch } from '../../utils/plurals/getPluralBranch';\nimport type { ReactNode } from 'react';\nimport { getFormatLocales } from '../../hooks/utils/getFormatLocales';\n\n// Pure render logic shared by the hook-based and RSC implementations. This\n// module must stay free of hook/context imports so it can be reached from the\n// components-rsc entrypoint.\n\ntype PluralProps = {\n children?: ReactNode;\n n: number;\n locales?: string[];\n _locale?: string;\n _enableI18n?: boolean;\n [key: string]: ReactNode;\n};\n\ntype ResolvedPluralProps = PluralProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction renderPlural({\n _enableI18n,\n _locale,\n children,\n n,\n locales: localesProp = [],\n ...branches\n}: ResolvedPluralProps): ReactNode {\n const locales = getFormatLocales({\n locale: _locale,\n enableI18n: _enableI18n,\n localesProp,\n });\n if (typeof n !== 'number') {\n return children;\n }\n const resolvedBranch = getPluralBranch(n, locales, branches);\n return resolvedBranch != null ? resolvedBranch : children;\n}\n\nexport { renderPlural };\nexport type { PluralProps, ResolvedPluralProps };\n"],"mappings":"oJAsBA,SAAS,EAAa,CACpB,cACA,UACA,WACA,IACA,QAAS,EAAc,EAAE,CACzB,GAAG,GAC8B,CACjC,IAAM,EAAU,EAAiB,CAC/B,OAAQ,EACR,WAAY,EACZ,cACD,CAAC,CAKF,OAJI,OAAO,GAAM,SAGM,EAAgB,EAAG,EAAS,EAC5C,EAA0C,EAHxC"}
|
package/dist/components-rsc.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./utils/plurals/getPluralBranch.cjs`),t=require(`./hooks/utils/getFormatLocales.cjs`),n=require(`./i18n-cache/singleton-operations.cjs`),r=require(`./functions/helpers/getTranslationsSnapshot.cjs`),i=require(`./condition-store/singleton-operations.cjs`),a=require(`./hooks/utils/getShouldTranslate.cjs`),o=require(`./functions/translation/t.cjs`),s=require(`./utils/rendering/createRenderVariable.cjs`),c=require(`./utils/rendering/createRenderPipeline.cjs`),l=require(`./setup/initializeGTSRA.cjs`),u=require(`./components/branches/Branch.cjs`),d=require(`./components/derivation/Derive.cjs`),f=require(`./components/variables/Var.cjs`),p=require(`./utils/translation/prepareT.shared.cjs`),m=require(`./components/branches/Plural.rsc.cjs`),h=require(`./components/variables/Currency.rsc.cjs`),g=require(`./components/variables/DateTime.rsc.cjs`),_=require(`./components/variables/Num.rsc.cjs`),v=require(`./components/variables/RelativeTime.rsc.cjs`),y=require(`./utils/rendering/renderPipeline.rsc.cjs`),b=require(`./components/translation/T.rsc.cjs`),x=require(`./components/translation/Tx.rsc.cjs`);exports.Branch=u.Branch,exports.Currency=h.RscCurrency,exports.DateTime=g.RscDateTime,exports.Derive=d.Derive,exports.GtInternalBranch=u.GtInternalBranch,exports.GtInternalCurrency=h.RscGtInternalCurrency,exports.GtInternalDateTime=g.RscGtInternalDateTime,exports.GtInternalDerive=d.GtInternalDerive,exports.GtInternalNum=_.RscGtInternalNum,exports.GtInternalPlural=m.RscGtInternalPlural,exports.GtInternalRelativeTime=v.RscGtInternalRelativeTime,exports.GtInternalVar=f.GtInternalVar,exports.Num=_.RscNum,exports.Plural=m.RscPlural,exports.RelativeTime=v.RscRelativeTime,exports.T=b.RscT,exports.Tx=x.RscTx,exports.Var=f.Var,exports.createRenderPipeline=c.createRenderPipeline,exports.createRenderVariable=s.createRenderVariable,exports.getFormatLocales=t.getFormatLocales,exports.getPluralBranch=e.getPluralBranch,exports.getReactI18nCache=n.getReactI18nCache,exports.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./utils/plurals/getPluralBranch.cjs`),t=require(`./hooks/utils/getFormatLocales.cjs`),n=require(`./i18n-cache/singleton-operations.cjs`),r=require(`./functions/helpers/getTranslationsSnapshot.cjs`),i=require(`./condition-store/singleton-operations.cjs`),a=require(`./hooks/utils/getShouldTranslate.cjs`),o=require(`./functions/translation/t.cjs`),s=require(`./utils/rendering/createRenderVariable.cjs`),c=require(`./utils/rendering/createRenderPipeline.cjs`),l=require(`./setup/initializeGTSRA.cjs`),u=require(`./components/branches/Branch.cjs`),d=require(`./components/derivation/Derive.cjs`),f=require(`./components/variables/Var.cjs`),p=require(`./utils/translation/prepareT.shared.cjs`),m=require(`./components/branches/Plural.rsc.cjs`),h=require(`./components/variables/Currency.rsc.cjs`),g=require(`./components/variables/DateTime.rsc.cjs`),_=require(`./components/variables/Num.rsc.cjs`),v=require(`./components/variables/RelativeTime.rsc.cjs`),y=require(`./utils/rendering/renderPipeline.rsc.cjs`),b=require(`./components/translation/T.rsc.cjs`),x=require(`./components/translation/Tx.rsc.cjs`);exports.Branch=u.Branch,exports.Currency=h.RscCurrency,exports.DateTime=g.RscDateTime,exports.Derive=d.Derive,exports.GtInternalBranch=u.GtInternalBranch,exports.GtInternalCurrency=h.RscGtInternalCurrency,exports.GtInternalDateTime=g.RscGtInternalDateTime,exports.GtInternalDerive=d.GtInternalDerive,exports.GtInternalNum=_.RscGtInternalNum,exports.GtInternalPlural=m.RscGtInternalPlural,exports.GtInternalRelativeTime=v.RscGtInternalRelativeTime,exports.GtInternalVar=f.GtInternalVar,exports.Num=_.RscNum,exports.Plural=m.RscPlural,exports.RelativeTime=v.RscRelativeTime,exports.T=b.RscT,exports.Tx=x.RscTx,exports.Var=f.Var,exports.createRenderPipeline=c.createRenderPipeline,exports.createRenderVariable=s.createRenderVariable,exports.getFormatLocales=t.getFormatLocales,exports.getPluralBranch=e.getPluralBranch,exports.getReactI18nCache=n.getReactI18nCache,exports.getReadonlyConditionStore=i.getConditionStore,exports.getShouldTranslate=a.getShouldTranslate,exports.getTranslationsSnapshot=r.getTranslationsSnapshot,exports.internalInitializeGTSRA=l.internalInitializeGTSRA,exports.prepareT=p.prepareT,exports.renderDefaultChildren=y.renderDefaultChildren,exports.renderPreparedT=y.renderPreparedT,exports.renderTranslatedChildren=y.renderTranslatedChildren,exports.renderVariable=y.renderVariable,exports.setReactI18nCache=n.setReactI18nCache,exports.t=o.t;
|
package/dist/components-rsc.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { createRenderVariable } from "./utils/rendering/createRenderVariable.js"
|
|
|
26
26
|
import { RenderPipeline, createRenderPipeline } from "./utils/rendering/createRenderPipeline.js";
|
|
27
27
|
import { getReactI18nCache, setReactI18nCache } from "./i18n-cache/singleton-operations.js";
|
|
28
28
|
import { internalInitializeGTSRA } from "./setup/initializeGTSRA.js";
|
|
29
|
-
import {
|
|
29
|
+
import { getConditionStore } from "./condition-store/singleton-operations.js";
|
|
30
30
|
import { getShouldTranslate } from "./hooks/utils/getShouldTranslate.js";
|
|
31
31
|
import { renderDefaultChildren, renderPreparedT, renderTranslatedChildren, renderVariable } from "./utils/rendering/renderPipeline.rsc.js";
|
|
32
|
-
export { Branch, RscCurrency as Currency, type CurrencyProps, RscDateTime as DateTime, type DateTimeProps, Derive, GtInternalBranch, RscGtInternalCurrency as GtInternalCurrency, RscGtInternalDateTime as GtInternalDateTime, GtInternalDerive, RscGtInternalNum as GtInternalNum, RscGtInternalPlural as GtInternalPlural, RscGtInternalRelativeTime as GtInternalRelativeTime, GtInternalVar, type JsxTranslationOptions, RscNum as Num, type NumProps, RscPlural as Plural, type PluralProps, type PreparedT, RscRelativeTime as RelativeTime, type RelativeTimeFormatOptions, type RelativeTimeProps, type RenderDefaultChildrenArgs, type RenderPipeline, type RenderPreparedTParams, type RenderTranslatedChildrenArgs, type RenderVariable, type ResolvedCurrencyProps, type ResolvedDateTimeProps, type ResolvedNumProps, type ResolvedPluralProps, type ResolvedRelativeTimeProps, RscT as T, RscTx as Tx, Var, createRenderPipeline, createRenderVariable, getFormatLocales, getPluralBranch, getReactI18nCache,
|
|
32
|
+
export { Branch, RscCurrency as Currency, type CurrencyProps, RscDateTime as DateTime, type DateTimeProps, Derive, GtInternalBranch, RscGtInternalCurrency as GtInternalCurrency, RscGtInternalDateTime as GtInternalDateTime, GtInternalDerive, RscGtInternalNum as GtInternalNum, RscGtInternalPlural as GtInternalPlural, RscGtInternalRelativeTime as GtInternalRelativeTime, GtInternalVar, type JsxTranslationOptions, RscNum as Num, type NumProps, RscPlural as Plural, type PluralProps, type PreparedT, RscRelativeTime as RelativeTime, type RelativeTimeFormatOptions, type RelativeTimeProps, type RenderDefaultChildrenArgs, type RenderPipeline, type RenderPreparedTParams, type RenderTranslatedChildrenArgs, type RenderVariable, type ResolvedCurrencyProps, type ResolvedDateTimeProps, type ResolvedNumProps, type ResolvedPluralProps, type ResolvedRelativeTimeProps, RscT as T, RscTx as Tx, Var, createRenderPipeline, createRenderVariable, getFormatLocales, getPluralBranch, getReactI18nCache, getConditionStore as getReadonlyConditionStore, getShouldTranslate, getTranslationsSnapshot, internalInitializeGTSRA, prepareT, renderDefaultChildren, renderPreparedT, renderTranslatedChildren, renderVariable, setReactI18nCache, t };
|
package/dist/components-rsc.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getPluralBranch as e}from"./utils/plurals/getPluralBranch.mjs";import{getFormatLocales as t}from"./hooks/utils/getFormatLocales.mjs";import{getReactI18nCache as n,setReactI18nCache as r}from"./i18n-cache/singleton-operations.mjs";import{getTranslationsSnapshot as i}from"./functions/helpers/getTranslationsSnapshot.mjs";import{
|
|
1
|
+
import{getPluralBranch as e}from"./utils/plurals/getPluralBranch.mjs";import{getFormatLocales as t}from"./hooks/utils/getFormatLocales.mjs";import{getReactI18nCache as n,setReactI18nCache as r}from"./i18n-cache/singleton-operations.mjs";import{getTranslationsSnapshot as i}from"./functions/helpers/getTranslationsSnapshot.mjs";import{getConditionStore as a}from"./condition-store/singleton-operations.mjs";import{getShouldTranslate as o}from"./hooks/utils/getShouldTranslate.mjs";import{t as s}from"./functions/translation/t.mjs";import{createRenderVariable as c}from"./utils/rendering/createRenderVariable.mjs";import{createRenderPipeline as l}from"./utils/rendering/createRenderPipeline.mjs";import{internalInitializeGTSRA as u}from"./setup/initializeGTSRA.mjs";import{Branch as d,GtInternalBranch as f}from"./components/branches/Branch.mjs";import{Derive as p,GtInternalDerive as m}from"./components/derivation/Derive.mjs";import{GtInternalVar as h,Var as g}from"./components/variables/Var.mjs";import{prepareT as _}from"./utils/translation/prepareT.shared.mjs";import{RscGtInternalPlural as v,RscPlural as y}from"./components/branches/Plural.rsc.mjs";import{RscCurrency as b,RscGtInternalCurrency as x}from"./components/variables/Currency.rsc.mjs";import{RscDateTime as S,RscGtInternalDateTime as C}from"./components/variables/DateTime.rsc.mjs";import{RscGtInternalNum as w,RscNum as T}from"./components/variables/Num.rsc.mjs";import{RscGtInternalRelativeTime as E,RscRelativeTime as D}from"./components/variables/RelativeTime.rsc.mjs";import{renderDefaultChildren as O,renderPreparedT as k,renderTranslatedChildren as A,renderVariable as j}from"./utils/rendering/renderPipeline.rsc.mjs";import{RscT as M}from"./components/translation/T.rsc.mjs";import{RscTx as N}from"./components/translation/Tx.rsc.mjs";export{d as Branch,b as Currency,S as DateTime,p as Derive,f as GtInternalBranch,x as GtInternalCurrency,C as GtInternalDateTime,m as GtInternalDerive,w as GtInternalNum,v as GtInternalPlural,E as GtInternalRelativeTime,h as GtInternalVar,T as Num,y as Plural,D as RelativeTime,M as T,N as Tx,g as Var,l as createRenderPipeline,c as createRenderVariable,t as getFormatLocales,e as getPluralBranch,n as getReactI18nCache,a as getReadonlyConditionStore,o as getShouldTranslate,i as getTranslationsSnapshot,u as internalInitializeGTSRA,_ as prepareT,O as renderDefaultChildren,k as renderPreparedT,A as renderTranslatedChildren,j as renderVariable,r as setReactI18nCache,s as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`generaltranslation/internal`);const{getConditionStore:t,setConditionStore:n,isConditionStoreInitialized:r}=(0,require(`gt-i18n/internal`).createConditionStoreSingleton)((0,e.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read GT runtime context before it has been initialized`,why:`The internal ConditionStore is unavailable`,fix:`Call initializeGT() during setup (gt-next runs this automatically) and add a <GTProvider> at the root of your component tree.`}));exports.getConditionStore=t,exports.isConditionStoreInitialized=r,exports.setConditionStore=n;
|
|
2
2
|
//# sourceMappingURL=singleton-operations.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singleton-operations.cjs","names":[
|
|
1
|
+
{"version":3,"file":"singleton-operations.cjs","names":[],"sources":["../../src/condition-store/singleton-operations.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createConditionStoreSingleton } from 'gt-i18n/internal';\nimport type { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GT runtime context before it has been initialized',\n why: 'The internal ConditionStore is unavailable',\n fix: 'Call initializeGT() during setup (gt-next runs this automatically) and add a <GTProvider> at the root of your component tree.',\n});\n\nconst { getConditionStore, setConditionStore, isConditionStoreInitialized } =\n createConditionStoreSingleton<ReadonlyConditionStoreInterface>(\n conditionStoreNotInitializedError\n );\n\nexport {\n getConditionStore as getReadonlyConditionStore,\n setConditionStore as setReadonlyConditionStore,\n isConditionStoreInitialized as isReadonlyConditionStoreInitialized,\n};\n"],"mappings":"0FAYA,KAAM,CAAE,oBAAmB,oBAAmB,gCAAA,6BAAA,CAAA,gCAAA,EAAA,EAAA,yBARoB,CAChE,OAAQ,iCACR,SAAU,QACV,aAAc,gEACd,IAAK,6CACL,IAAK,gIACN,CAIoC,CAClC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { ReadonlyConditionStoreInterface } from "gt-i18n/internal/types";
|
|
2
2
|
|
|
3
3
|
//#region src/condition-store/singleton-operations.d.ts
|
|
4
|
-
declare const setConditionStore: (next: ReadonlyConditionStoreInterface) => void, isConditionStoreInitialized: () => boolean;
|
|
5
|
-
/**
|
|
6
|
-
* Opinionated decision: add a safety wrapper around the condition store to be more forgiving in production
|
|
7
|
-
* TODO: perhaps this is how condition store should always be accessed
|
|
8
|
-
*/
|
|
9
|
-
declare function getReadonlyConditionStoreWithFallback(): ReadonlyConditionStoreInterface;
|
|
4
|
+
declare const getConditionStore: () => ReadonlyConditionStoreInterface, setConditionStore: (next: ReadonlyConditionStoreInterface) => void, isConditionStoreInitialized: () => boolean;
|
|
10
5
|
//#endregion
|
|
11
|
-
export {
|
|
6
|
+
export { getConditionStore, setConditionStore };
|
|
12
7
|
//# sourceMappingURL=singleton-operations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singleton-operations.d.ts","names":[],"sources":["../../src/condition-store/singleton-operations.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"singleton-operations.d.ts","names":[],"sources":["../../src/condition-store/singleton-operations.ts"],"mappings":";;;cAYQ,iBAAA,QAAiB,+BAAA,EAAE,iBAAA,GAAiB,IAAA,EAAA,+BAAA,WAAE,2BAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createDiagnosticMessage as e}from"generaltranslation/internal";import{createConditionStoreSingleton as t}from"gt-i18n/internal";const{getConditionStore:n,setConditionStore:r,isConditionStoreInitialized:i}=t(e({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read GT runtime context before it has been initialized`,why:`The internal ConditionStore is unavailable`,fix:`Call initializeGT() during setup (gt-next runs this automatically) and add a <GTProvider> at the root of your component tree.`}));export{n as getConditionStore,i as isConditionStoreInitialized,r as setConditionStore};
|
|
2
2
|
//# sourceMappingURL=singleton-operations.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singleton-operations.mjs","names":[
|
|
1
|
+
{"version":3,"file":"singleton-operations.mjs","names":[],"sources":["../../src/condition-store/singleton-operations.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createConditionStoreSingleton } from 'gt-i18n/internal';\nimport type { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\n\nconst conditionStoreNotInitializedError = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GT runtime context before it has been initialized',\n why: 'The internal ConditionStore is unavailable',\n fix: 'Call initializeGT() during setup (gt-next runs this automatically) and add a <GTProvider> at the root of your component tree.',\n});\n\nconst { getConditionStore, setConditionStore, isConditionStoreInitialized } =\n createConditionStoreSingleton<ReadonlyConditionStoreInterface>(\n conditionStoreNotInitializedError\n );\n\nexport {\n getConditionStore as getReadonlyConditionStore,\n setConditionStore as setReadonlyConditionStore,\n isConditionStoreInitialized as isReadonlyConditionStoreInitialized,\n};\n"],"mappings":"uIAYA,KAAM,CAAE,oBAAmB,oBAAmB,+BAC5C,EATwC,EAAwB,CAChE,OAAQ,iCACR,SAAU,QACV,aAAc,gEACd,IAAK,6CACL,IAAK,gIACN,CAIoC,CAClC"}
|
package/dist/context/context.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../setup/i18nConfig.cjs`);let t=require(`generaltranslation/internal`),n=require(`react`);const r=(0,require(`gt-i18n/internal`).createGlobalSingleton)({namespace:`reactCore`,key:`gtContext`,source:`@generaltranslation/react-core`,notInitialized:()
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../setup/i18nConfig.cjs`);let t=require(`generaltranslation/internal`),n=require(`react`);const r=(0,require(`gt-i18n/internal`).createGlobalSingleton)({namespace:`reactCore`,key:`gtContext`,source:`@generaltranslation/react-core`,notInitialized:()=>(0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read GTContext before it has been initialized`,why:`the internal GTContext singleton is unavailable`,fix:`Add a <GTProvider> at the root of your component tree.`})});function i(){return r.isInitialized()||r.set((0,n.createContext)(void 0)),r.get()}function a(){let t=(0,n.useContext)(i());if(t||e.getI18nConfig().getRenderStrategy()===`SPA`)return t;throw Error(o())}function o(){return(0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`GT runtime context could not be read`,why:`GTContext was accessed outside of a <GTProvider>`,fix:`Add a <GTProvider> at the root of your component tree.`})}exports.getGTContext=i,exports.useGTContext=a;
|
|
2
2
|
//# sourceMappingURL=context.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import {\n Dictionary,\n Hash,\n Locale,\n ReadonlyConditionStoreInterface,\n} from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Translation>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n /**\n * ConditionStore should always remain separate from i18nStore as\n * it manages how we perform lookups\n */\n conditionStore: ReadonlyConditionStoreInterface;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: ()
|
|
1
|
+
{"version":3,"file":"context.cjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import {\n Dictionary,\n Hash,\n Locale,\n ReadonlyConditionStoreInterface,\n} from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Translation>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n /**\n * ConditionStore should always remain separate from i18nStore as\n * it manages how we perform lookups\n */\n conditionStore: ReadonlyConditionStoreInterface;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GTContext before it has been initialized',\n why: 'the internal GTContext singleton is unavailable',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n }),\n});\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n // Lazily create the React context once and share it across instances.\n if (!gtContextSingleton.isInitialized()) {\n gtContextSingleton.set(createContext<GTContextType | undefined>(undefined));\n }\n return gtContextSingleton.get();\n}\n\nexport function useGTContext(): GTContextType | undefined {\n const context = useContext(getGTContext());\n if (context || getI18nConfig().getRenderStrategy() === 'SPA') {\n return context;\n }\n /**\n * TODO: in a separate PR, we should figure out how to make this more of a forgiving system\n */\n throw new Error(createMissingGTProviderError());\n}\n\nfunction createMissingGTProviderError(): string {\n return createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'GT runtime context could not be read',\n why: 'GTContext was accessed outside of a <GTProvider>',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n });\n}\n"],"mappings":"wJA6CA,MAAM,GAAA,6BAAA,CAAA,uBAEJ,CACA,UAAW,YACX,IAAK,YACL,OAAQ,iCACR,oBAAA,EAAA,EAAA,yBAC0B,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,uDACd,IAAK,kDACL,IAAK,yDACN,CAAC,CACL,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,KAAA,EAAA,EAAA,eAA6C,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,GAAA,EAAA,EAAA,YAAqB,GAAc,CAAC,CAC1C,GAAI,GAAWA,EAAAA,eAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAA,EAAA,EAAA,yBAA+B,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
|
package/dist/context/context.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getI18nConfig as e}from"../setup/i18nConfig.mjs";import{createDiagnosticMessage as t}from"generaltranslation/internal";import{createContext as n,useContext as r}from"react";import{createGlobalSingleton as i}from"gt-i18n/internal";const a=i({namespace:`reactCore`,key:`gtContext`,source:`@generaltranslation/react-core`,notInitialized:()
|
|
1
|
+
import{getI18nConfig as e}from"../setup/i18nConfig.mjs";import{createDiagnosticMessage as t}from"generaltranslation/internal";import{createContext as n,useContext as r}from"react";import{createGlobalSingleton as i}from"gt-i18n/internal";const a=i({namespace:`reactCore`,key:`gtContext`,source:`@generaltranslation/react-core`,notInitialized:()=>t({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read GTContext before it has been initialized`,why:`the internal GTContext singleton is unavailable`,fix:`Add a <GTProvider> at the root of your component tree.`})});function o(){return a.isInitialized()||a.set(n(void 0)),a.get()}function s(){let t=r(o());if(t||e().getRenderStrategy()===`SPA`)return t;throw Error(c())}function c(){return t({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`GT runtime context could not be read`,why:`GTContext was accessed outside of a <GTProvider>`,fix:`Add a <GTProvider> at the root of your component tree.`})}export{o as getGTContext,s as useGTContext};
|
|
2
2
|
//# sourceMappingURL=context.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import {\n Dictionary,\n Hash,\n Locale,\n ReadonlyConditionStoreInterface,\n} from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Translation>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n /**\n * ConditionStore should always remain separate from i18nStore as\n * it manages how we perform lookups\n */\n conditionStore: ReadonlyConditionStoreInterface;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: ()
|
|
1
|
+
{"version":3,"file":"context.mjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import {\n Dictionary,\n Hash,\n Locale,\n ReadonlyConditionStoreInterface,\n} from 'gt-i18n/internal/types';\nimport { Translation } from 'gt-i18n/types';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { createGlobalSingleton } from 'gt-i18n/internal';\nimport { createContext, useContext, type Context } from 'react';\nimport { I18nStore } from '../i18n-store/I18nStore';\nimport { getI18nConfig } from '../setup/i18nConfig';\nimport type {\n OnMissingTranslation,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from '../hooks/utils/missing-translation';\n\nexport type GTContextType = {\n /**\n * Source of truth for translations, streamed from server\n * In SPA mode, these won't be accessible and translations\n * can be accessed via useSyncExternalStore() directly\n */\n translationsSnapshot: Record<Locale, Record<Hash, Translation>>;\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * I18nStore allows us to sync state updates in ConditionStore and I18nCache\n * with renders\n */\n i18nStore: I18nStore;\n /**\n * ConditionStore should always remain separate from i18nStore as\n * it manages how we perform lookups\n */\n conditionStore: ReadonlyConditionStoreInterface;\n /**\n * Custom override behavior on missing translations\n * Used for server triggering tx hmr b/c no access to useEffect\n */\n onMissingTranslation?: OnMissingTranslation;\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst gtContextSingleton = createGlobalSingleton<\n Context<GTContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'gtContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read GTContext before it has been initialized',\n why: 'the internal GTContext singleton is unavailable',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n }),\n});\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n // Lazily create the React context once and share it across instances.\n if (!gtContextSingleton.isInitialized()) {\n gtContextSingleton.set(createContext<GTContextType | undefined>(undefined));\n }\n return gtContextSingleton.get();\n}\n\nexport function useGTContext(): GTContextType | undefined {\n const context = useContext(getGTContext());\n if (context || getI18nConfig().getRenderStrategy() === 'SPA') {\n return context;\n }\n /**\n * TODO: in a separate PR, we should figure out how to make this more of a forgiving system\n */\n throw new Error(createMissingGTProviderError());\n}\n\nfunction createMissingGTProviderError(): string {\n return createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'GT runtime context could not be read',\n why: 'GTContext was accessed outside of a <GTProvider>',\n fix: 'Add a <GTProvider> at the root of your component tree.',\n });\n}\n"],"mappings":"6OA6CA,MAAM,EAAqB,EAEzB,CACA,UAAW,YACX,IAAK,YACL,OAAQ,iCACR,mBACE,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,uDACd,IAAK,kDACL,IAAK,yDACN,CAAC,CACL,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,IAAI,EAAyC,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,EAAU,EAAW,GAAc,CAAC,CAC1C,GAAI,GAAWA,GAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAO,EAAwB,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-cache/singleton-operations.cjs`),t=require(`../../setup/i18nConfig.cjs`),n=require(`../../condition-store/singleton-operations.cjs`),r=require(`../../hooks/utils/getShouldTranslate.cjs`);let i=require(`generaltranslation/internal`),a=require(`gt-i18n/internal`);const o=(e,...t)=>{if(d(e),typeof e==`string`){let n=t.at(0)
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-cache/singleton-operations.cjs`),t=require(`../../setup/i18nConfig.cjs`),n=require(`../../condition-store/singleton-operations.cjs`),r=require(`../../hooks/utils/getShouldTranslate.cjs`);let i=require(`generaltranslation/internal`),a=require(`gt-i18n/internal`);const o=(e,...t)=>{if(d(e),typeof e==`string`){let n=t.at(0),r=n?.$locale??f();return s(r,e,(0,a.createLookupOptions)(r,n??{},`ICU`))}return c(e,t)};function s(n,i,o={}){let s=e.getReactI18nCache(),c=t.getI18nConfig().getDefaultLocale();if(!r.getShouldTranslate())return(0,a.interpolateMessage)({options:o,source:i,sourceLocale:c});let l=(0,a.createLookupOptions)(n,o,`ICU`);return(0,a.interpolateMessage)({source:i,target:s.lookupTranslation(l.$locale,i,l),options:l,sourceLocale:c})}function c(t,n){let r=f(),i=u(t,n),a=e.getReactI18nCache().lookupTranslation(r,i,{$format:`STRING`});if(a)return a;let{message:o,variables:c}=l(t,n);return s(r,o,c)}function l(e,t){let n=[],r={},i=0;for(let a=0;a<e.length;a++)if(n.push(e[a]),a<t.length){let e=i.toString();n.push(`{${e}}`),r[e]=t[a],i++}return{message:n.join(``),variables:r}}function u(e,t){return e.map((e,n)=>e+(t[n]??``)).join(``)}function d(e){let r=t.getI18nConfig().getRenderStrategy()===`server-render`,o=!n.isConditionStoreInitialized();if(!r||!o)return;let s=typeof e==`string`?e:e.join(``),c=(0,i.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Using the t() function at the module level is forbidden in server-rendered applications.`,fix:`Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.`,wayOut:(0,a.getRuntimeEnvironment)()===`development`?void 0:`Falling back to defaultLocale value.`,details:`Message: "${s}"`});if((0,a.getRuntimeEnvironment)()===`development`)throw Error(c);console.error(c)}function f(){return n.getConditionStore().getLocale()}exports.t=o;
|
|
2
2
|
//# sourceMappingURL=t.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.cjs","names":["getReactI18nCache","getI18nConfig","getShouldTranslate","isReadonlyConditionStoreInitialized","
|
|
1
|
+
{"version":3,"file":"t.cjs","names":["getReactI18nCache","getI18nConfig","getShouldTranslate","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions, LookupOptionsFor } from 'gt-i18n/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\nfunction enforceSSRRules(messageOrStrings: string | TemplateStringsArray) {\n const ssrEnabled = getI18nConfig().getRenderStrategy() === 'server-render';\n const moduleLevel = !isReadonlyConditionStoreInitialized();\n if (!ssrEnabled || !moduleLevel) return;\n\n const message =\n typeof messageOrStrings === 'string'\n ? messageOrStrings\n : messageOrStrings.join('');\n const runtimeEnvironment = getRuntimeEnvironment();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Using the t() function at the module level is forbidden in server-rendered applications.',\n fix: 'Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : 'Falling back to defaultLocale value.',\n details: `Message: \"${message}\"`,\n });\n if (getRuntimeEnvironment() === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n}\n\nfunction getLocale(): string {\n return getReadonlyConditionStore().getLocale();\n}\n\n/**\n * Overloaded type for the `t` function.\n * - Tagged template: t`Hello, ${name}` (transformed by the compiler plugin at build time)\n * - Function call: t(\"Hello, {name}\", { name: \"John\" })\n *\n * {@link TemplateSyncResolutionFunction}\n * {@link SyncResolutionFunction}\n */\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\n/**\n * Type for the `t` function when used as a tagged template literal.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The translated message.\n */\ntype TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n"],"mappings":"kVAgCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,GAAA,EAAA,EAAA,qBACoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAYA,EAAAA,mBAAmB,CAC/B,EAAgBC,EAAAA,eAAe,CAAC,kBAAkB,CACxD,GAAI,CAACC,EAAAA,oBAAoB,CACvB,OAAA,EAAA,EAAA,oBAA0B,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,GAAA,EAAA,EAAA,qBAAoC,EAAQ,EAAS,MAAM,CAMjE,OAAA,EAAA,EAAA,oBAA0B,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADYF,EAAAA,mBAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,SAAS,EAAgB,EAAiD,CACxE,IAAM,EAAaC,EAAAA,eAAe,CAAC,mBAAmB,GAAK,gBACrD,EAAc,CAACE,EAAAA,6BAAqC,CAC1D,GAAI,CAAC,GAAc,CAAC,EAAa,OAEjC,IAAM,EACJ,OAAO,GAAqB,SACxB,EACA,EAAiB,KAAK,GAAG,CAEzB,GAAA,EAAA,EAAA,yBAAuC,CAC3C,OAAQ,iCACR,SAAU,QACV,aACE,2FACF,IAAK,8NACL,QAAA,EAAA,EAAA,wBACoB,GAAK,cACnB,IAAA,GACA,uCACN,QAAS,aAAa,EAAQ,GAC/B,CAAC,CACF,IAAA,EAAA,EAAA,wBAA2B,GAAK,cAC9B,MAAU,MAAM,EAAa,CAE7B,QAAQ,MAAM,EAAa,CAI/B,SAAS,GAAoB,CAC3B,OAAOC,EAAAA,mBAA2B,CAAC,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.d.ts","names":[],"sources":["../../../src/functions/translation/t.ts"],"mappings":";;;;AAgCA;;;;;
|
|
1
|
+
{"version":3,"file":"t.d.ts","names":[],"sources":["../../../src/functions/translation/t.ts"],"mappings":";;;;AAgCA;;;;;AAmDC;;;;;;;;;cAnDY,CAAA,EAAG,sCAAA;;;;;;;;;UA+LN,sCAAA;EAAA,CACP,OAAA,EAAS,oBAAA,KAAyB,MAAA;EAAA,CAClC,OAAA,UAAiB,OAAA,GAAU,oBAAA;AAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getReactI18nCache as e}from"../../i18n-cache/singleton-operations.mjs";import{getI18nConfig as t}from"../../setup/i18nConfig.mjs";import{
|
|
1
|
+
import{getReactI18nCache as e}from"../../i18n-cache/singleton-operations.mjs";import{getI18nConfig as t}from"../../setup/i18nConfig.mjs";import{getConditionStore as n,isConditionStoreInitialized as r}from"../../condition-store/singleton-operations.mjs";import{getShouldTranslate as i}from"../../hooks/utils/getShouldTranslate.mjs";import{createDiagnosticMessage as a}from"generaltranslation/internal";import{createLookupOptions as o,getRuntimeEnvironment as s,interpolateMessage as c}from"gt-i18n/internal";const l=(e,...t)=>{if(m(e),typeof e==`string`){let n=t.at(0),r=n?.$locale??h();return u(r,e,o(r,n??{},`ICU`))}return d(e,t)};function u(n,r,a={}){let s=e(),l=t().getDefaultLocale();if(!i())return c({options:a,source:r,sourceLocale:l});let u=o(n,a,`ICU`);return c({source:r,target:s.lookupTranslation(u.$locale,r,u),options:u,sourceLocale:l})}function d(t,n){let r=h(),i=p(t,n),a=e().lookupTranslation(r,i,{$format:`STRING`});if(a)return a;let{message:o,variables:s}=f(t,n);return u(r,o,s)}function f(e,t){let n=[],r={},i=0;for(let a=0;a<e.length;a++)if(n.push(e[a]),a<t.length){let e=i.toString();n.push(`{${e}}`),r[e]=t[a],i++}return{message:n.join(``),variables:r}}function p(e,t){return e.map((e,n)=>e+(t[n]??``)).join(``)}function m(e){let n=t().getRenderStrategy()===`server-render`,i=!r();if(!n||!i)return;let o=typeof e==`string`?e:e.join(``),c=a({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Using the t() function at the module level is forbidden in server-rendered applications.`,fix:`Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.`,wayOut:s()===`development`?void 0:`Falling back to defaultLocale value.`,details:`Message: "${o}"`});if(s()===`development`)throw Error(c);console.error(c)}function h(){return n().getLocale()}export{l as t};
|
|
2
2
|
//# sourceMappingURL=t.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.mjs","names":["getI18nConfig","isReadonlyConditionStoreInitialized"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions, LookupOptionsFor } from 'gt-i18n/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n
|
|
1
|
+
{"version":3,"file":"t.mjs","names":["getI18nConfig","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions, LookupOptionsFor } from 'gt-i18n/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\nfunction enforceSSRRules(messageOrStrings: string | TemplateStringsArray) {\n const ssrEnabled = getI18nConfig().getRenderStrategy() === 'server-render';\n const moduleLevel = !isReadonlyConditionStoreInitialized();\n if (!ssrEnabled || !moduleLevel) return;\n\n const message =\n typeof messageOrStrings === 'string'\n ? messageOrStrings\n : messageOrStrings.join('');\n const runtimeEnvironment = getRuntimeEnvironment();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Using the t() function at the module level is forbidden in server-rendered applications.',\n fix: 'Either move the t() invocation into a request-time scope or register the string with the msg() function and translate with an m() function. Ensure that you have added the <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : 'Falling back to defaultLocale value.',\n details: `Message: \"${message}\"`,\n });\n if (getRuntimeEnvironment() === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n}\n\nfunction getLocale(): string {\n return getReadonlyConditionStore().getLocale();\n}\n\n/**\n * Overloaded type for the `t` function.\n * - Tagged template: t`Hello, ${name}` (transformed by the compiler plugin at build time)\n * - Function call: t(\"Hello, {name}\", { name: \"John\" })\n *\n * {@link TemplateSyncResolutionFunction}\n * {@link SyncResolutionFunction}\n */\ninterface StringOrTemplateSyncResolutionFunction {\n (strings: TemplateStringsArray, ...values: unknown[]): string;\n (message: string, options?: GTTranslationOptions): string;\n}\n\n/**\n * Type for the `t` function when used as a tagged template literal.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The translated message.\n */\ntype TemplateSyncResolutionFunction = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n) => string;\n"],"mappings":"2fAgCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,EACA,EAAoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAY,GAAmB,CAC/B,EAAgBA,GAAe,CAAC,kBAAkB,CACxD,GAAI,CAAC,GAAoB,CACvB,OAAO,EAAmB,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,EAAgB,EAAoB,EAAQ,EAAS,MAAM,CAMjE,OAAO,EAAmB,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADY,GAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,SAAS,EAAgB,EAAiD,CACxE,IAAM,EAAaA,GAAe,CAAC,mBAAmB,GAAK,gBACrD,EAAc,CAACC,GAAqC,CAC1D,GAAI,CAAC,GAAc,CAAC,EAAa,OAEjC,IAAM,EACJ,OAAO,GAAqB,SACxB,EACA,EAAiB,KAAK,GAAG,CAEzB,EAAe,EAAwB,CAC3C,OAAQ,iCACR,SAAU,QACV,aACE,2FACF,IAAK,8NACL,OAPyB,GAQL,GAAK,cACnB,IAAA,GACA,uCACN,QAAS,aAAa,EAAQ,GAC/B,CAAC,CACF,GAAI,GAAuB,GAAK,cAC9B,MAAU,MAAM,EAAa,CAE7B,QAAQ,MAAM,EAAa,CAI/B,SAAS,GAAoB,CAC3B,OAAOC,GAA2B,CAAC,WAAW"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../condition-store/singleton-operations.cjs`),t=require(`../context/context.cjs`);function n(){return t.useGTContext()?.conditionStore??e.
|
|
1
|
+
const e=require(`../condition-store/singleton-operations.cjs`),t=require(`../context/context.cjs`);function n(){return t.useGTContext()?.conditionStore??e.getConditionStore()}function r(){return n().getLocale()}function i(){return n().getRegion()}function a(){return n().getEnableI18n()}exports.useConditionStore=n,exports.useEnableI18n=a,exports.useLocale=r,exports.useRegion=i;
|
|
2
2
|
//# sourceMappingURL=condition-store.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition-store.cjs","names":["useGTContext","
|
|
1
|
+
{"version":3,"file":"condition-store.cjs","names":["useGTContext","getReadonlyConditionStore"],"sources":["../../src/hooks/condition-store.ts"],"sourcesContent":["import { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport { getReadonlyConditionStore } from '../condition-store/singleton-operations';\nimport { useGTContext } from '../context/context';\n\n/**\n * NOTE: useSetLocale() and useSetEnableI18n() are not implemented in @generaltranslation/react-core\n * Some server environments are read only, so we cannot implement these hooks.\n */\n\nexport function useConditionStore(): ReadonlyConditionStoreInterface {\n const context = useGTContext();\n return context?.conditionStore ?? getReadonlyConditionStore();\n}\n\n/**\n * Returns the current locale.\n */\nexport function useLocale(): string {\n return useConditionStore().getLocale();\n}\n\n/**\n * Returns the current region, or undefined if no region is set.\n */\nexport function useRegion(): string | undefined {\n return useConditionStore().getRegion();\n}\n\n/**\n * Returns the current enableI18n flag.\n */\nexport function useEnableI18n(): boolean {\n return useConditionStore().getEnableI18n();\n}\n"],"mappings":"mGASA,SAAgB,GAAqD,CAEnE,OADgBA,EAAAA,cACF,EAAE,gBAAkBC,EAAAA,mBAA2B,CAM/D,SAAgB,GAAoB,CAClC,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAgC,CAC9C,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAyB,CACvC,OAAO,GAAmB,CAAC,eAAe"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getConditionStore as e}from"../condition-store/singleton-operations.mjs";import{useGTContext as t}from"../context/context.mjs";function n(){return t()?.conditionStore??e()}function r(){return n().getLocale()}function i(){return n().getRegion()}function a(){return n().getEnableI18n()}export{n as useConditionStore,a as useEnableI18n,r as useLocale,i as useRegion};
|
|
2
2
|
//# sourceMappingURL=condition-store.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition-store.mjs","names":[],"sources":["../../src/hooks/condition-store.ts"],"sourcesContent":["import { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport {
|
|
1
|
+
{"version":3,"file":"condition-store.mjs","names":["getReadonlyConditionStore"],"sources":["../../src/hooks/condition-store.ts"],"sourcesContent":["import { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport { getReadonlyConditionStore } from '../condition-store/singleton-operations';\nimport { useGTContext } from '../context/context';\n\n/**\n * NOTE: useSetLocale() and useSetEnableI18n() are not implemented in @generaltranslation/react-core\n * Some server environments are read only, so we cannot implement these hooks.\n */\n\nexport function useConditionStore(): ReadonlyConditionStoreInterface {\n const context = useGTContext();\n return context?.conditionStore ?? getReadonlyConditionStore();\n}\n\n/**\n * Returns the current locale.\n */\nexport function useLocale(): string {\n return useConditionStore().getLocale();\n}\n\n/**\n * Returns the current region, or undefined if no region is set.\n */\nexport function useRegion(): string | undefined {\n return useConditionStore().getRegion();\n}\n\n/**\n * Returns the current enableI18n flag.\n */\nexport function useEnableI18n(): boolean {\n return useConditionStore().getEnableI18n();\n}\n"],"mappings":"sIASA,SAAgB,GAAqD,CAEnE,OADgB,GACF,EAAE,gBAAkBA,GAA2B,CAM/D,SAAgB,GAAoB,CAClC,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAgC,CAC9C,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAyB,CACvC,OAAO,GAAmB,CAAC,eAAe"}
|
package/dist/hooks/useGT.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./condition-store.cjs`),t=require(`./i18n-config.cjs`),n=require(`./utils.cjs`),r=require(`./external-store/useTrackedTranslationResolver.cjs`);let i=require(`react`),a=require(`gt-i18n/internal`);function o(o){let s=e.useLocale(),c=t.useDefaultLocale(),l=n.useShouldTranslate(),u=r.useTrackedTranslationResolver(o);return(0,i.useCallback)((e,t={})=>{
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./condition-store.cjs`),t=require(`./i18n-config.cjs`),n=require(`./utils.cjs`),r=require(`./external-store/useTrackedTranslationResolver.cjs`);let i=require(`react`),a=require(`gt-i18n/internal`);function o(o){let s=e.useLocale(),c=t.useDefaultLocale(),l=n.useShouldTranslate(),u=r.useTrackedTranslationResolver(o);return(0,i.useCallback)((e,t={})=>{let n=(0,a.createLookupOptions)(t.$locale??s,t,`ICU`);return l?(0,a.interpolateMessage)({source:e,target:u({locale:n.$locale,message:e,options:n}),options:n,sourceLocale:c}):(0,a.interpolateMessage)({options:n,source:e,sourceLocale:c})},[c,s,l,u])}exports.useGT=o;
|
|
2
2
|
//# sourceMappingURL=useGT.cjs.map
|
package/dist/hooks/useGT.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.cjs","names":["useLocale","useDefaultLocale","useShouldTranslate","useTrackedTranslationResolver"],"sources":["../../src/hooks/useGT.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { createLookupOptions, interpolateMessage } from 'gt-i18n/internal';\nimport { useLocale } from './condition-store';\nimport { useShouldTranslate } from './utils';\nimport type { GTFunctionType, GTTranslationOptions } from 'gt-i18n/types';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport { useDefaultLocale } from './i18n-config';\nimport {\n type Message,\n useTrackedTranslationResolver,\n} from './external-store/useTrackedTranslationResolver';\n\n// ===== Hook ===== //\n\nexport function useGT(_messages?: Message[]): GTFunctionType {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const resolveTranslation = useTrackedTranslationResolver(_messages);\n\n /**\n * gt() string translation callback\n */\n return useCallback(\n (message: string, options: GTTranslationOptions = {}) => {\n if (!shouldTranslate) {\n return interpolateMessage({\n options,\n source: message,\n sourceLocale: defaultLocale,\n });\n }\n\n const
|
|
1
|
+
{"version":3,"file":"useGT.cjs","names":["useLocale","useDefaultLocale","useShouldTranslate","useTrackedTranslationResolver"],"sources":["../../src/hooks/useGT.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { createLookupOptions, interpolateMessage } from 'gt-i18n/internal';\nimport { useLocale } from './condition-store';\nimport { useShouldTranslate } from './utils';\nimport type { GTFunctionType, GTTranslationOptions } from 'gt-i18n/types';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport { useDefaultLocale } from './i18n-config';\nimport {\n type Message,\n useTrackedTranslationResolver,\n} from './external-store/useTrackedTranslationResolver';\n\n// ===== Hook ===== //\n\nexport function useGT(_messages?: Message[]): GTFunctionType {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const resolveTranslation = useTrackedTranslationResolver(_messages);\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 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":"mQAcA,SAAgB,EAAM,EAAuC,CAC3D,IAAM,EAASA,EAAAA,WAAW,CACpB,EAAgBC,EAAAA,kBAAkB,CAClC,EAAkBC,EAAAA,oBAAoB,CACtC,EAAqBC,EAAAA,8BAA8B,EAAU,CAKnE,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,UACA,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.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useLocale as e}from"./condition-store.mjs";import{useDefaultLocale as t}from"./i18n-config.mjs";import{useShouldTranslate as n}from"./utils.mjs";import{useTrackedTranslationResolver as r}from"./external-store/useTrackedTranslationResolver.mjs";import{useCallback as i}from"react";import{createLookupOptions as a,interpolateMessage as o}from"gt-i18n/internal";function s(s){let c=e(),l=t(),u=n(),d=r(s);return i((e,t={})=>{
|
|
1
|
+
import{useLocale as e}from"./condition-store.mjs";import{useDefaultLocale as t}from"./i18n-config.mjs";import{useShouldTranslate as n}from"./utils.mjs";import{useTrackedTranslationResolver as r}from"./external-store/useTrackedTranslationResolver.mjs";import{useCallback as i}from"react";import{createLookupOptions as a,interpolateMessage as o}from"gt-i18n/internal";function s(s){let c=e(),l=t(),u=n(),d=r(s);return i((e,t={})=>{let n=a(t.$locale??c,t,`ICU`);return o(u?{source:e,target:d({locale:n.$locale,message:e,options:n}),options:n,sourceLocale:l}:{options:n,source:e,sourceLocale:l})},[l,c,u,d])}export{s 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 { useLocale } from './condition-store';\nimport { useShouldTranslate } from './utils';\nimport type { GTFunctionType, GTTranslationOptions } from 'gt-i18n/types';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport { useDefaultLocale } from './i18n-config';\nimport {\n type Message,\n useTrackedTranslationResolver,\n} from './external-store/useTrackedTranslationResolver';\n\n// ===== Hook ===== //\n\nexport function useGT(_messages?: Message[]): GTFunctionType {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const resolveTranslation = useTrackedTranslationResolver(_messages);\n\n /**\n * gt() string translation callback\n */\n return useCallback(\n (message: string, options: GTTranslationOptions = {}) => {\n if (!shouldTranslate) {\n return interpolateMessage({\n options,\n source: message,\n sourceLocale: defaultLocale,\n });\n }\n\n const
|
|
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 { useLocale } from './condition-store';\nimport { useShouldTranslate } from './utils';\nimport type { GTFunctionType, GTTranslationOptions } from 'gt-i18n/types';\nimport type { StringFormat } from '@generaltranslation/format/types';\nimport { useDefaultLocale } from './i18n-config';\nimport {\n type Message,\n useTrackedTranslationResolver,\n} from './external-store/useTrackedTranslationResolver';\n\n// ===== Hook ===== //\n\nexport function useGT(_messages?: Message[]): GTFunctionType {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const resolveTranslation = useTrackedTranslationResolver(_messages);\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 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":"8WAcA,SAAgB,EAAM,EAAuC,CAC3D,IAAM,EAAS,GAAW,CACpB,EAAgB,GAAkB,CAClC,EAAkB,GAAoB,CACtC,EAAqB,EAA8B,EAAU,CAKnE,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,UACA,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,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./condition-store.cjs`),t=require(`./i18n-config.cjs`);let n=require(`react`),r=require(
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./condition-store.cjs`),t=require(`./i18n-config.cjs`);let n=require(`react`),r=require(`@generaltranslation/format`);function i(i){let a=t.useLocales(),o=t.useCustomMapping(),s=e.useLocale(),c=(0,n.useMemo)(()=>{if(!a||a.length===0)return[];let e=new Intl.Collator;return[...a].sort((t,n)=>e.compare((0,r.getLocaleProperties)(t,s,o).nativeNameWithRegionCode,(0,r.getLocaleProperties)(n,s,o).nativeNameWithRegionCode))},[a,s,o]),l=(0,n.useCallback)(e=>(0,r.getLocaleProperties)(e,e,o),[s,o]);return{locale:s,locales:i||c,getLocaleProperties:l}}exports.useInternalLocaleSelector=i;
|
|
2
2
|
//# sourceMappingURL=useInternalLocaleSelector.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInternalLocaleSelector.cjs","names":["useLocales","useCustomMapping","useLocale"],"sources":["../../src/hooks/useInternalLocaleSelector.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport type { LocaleProperties } from '@generaltranslation/format/types';\nimport { useCustomMapping, useLocales } from './i18n-config';\nimport { useLocale } from './condition-store';\nimport { getLocaleProperties } from 'generaltranslation';\n\n// Explicit return type so the inferred type stays portable for downstream\n// packages (e.g. gt-react-native), otherwise the getLocaleProperties callback\n// pulls in generaltranslation's bundled, non-nameable type (TS2742).\nexport type InternalLocaleSelectorResult = {\n locale: string;\n locales: string[];\n getLocaleProperties: (locale: string) => LocaleProperties;\n};\n\nexport function useInternalLocaleSelector(\n locales?: string[]\n): InternalLocaleSelectorResult {\n // Retrieve the locale, locales, and setLocale function\n const contextLocales = useLocales();\n const customMapping = useCustomMapping();\n const locale = useLocale();\n\n // sort\n const sortedLocales = useMemo(() => {\n if (!contextLocales || contextLocales.length === 0) {\n return [];\n }\n const collator = new Intl.Collator();\n return [...contextLocales].sort((a, b) =>\n collator.compare(\n getLocaleProperties(a, locale, customMapping).nativeNameWithRegionCode,\n getLocaleProperties(b, locale, customMapping).nativeNameWithRegionCode\n )\n );\n }, [contextLocales, locale, customMapping]);\n\n // create getLocaleProperties callback\n const getLocalePropertiesCallback = useCallback(\n (locale: string) => {\n return getLocaleProperties(locale, locale, customMapping);\n },\n [locale, customMapping]\n );\n\n return {\n locale,\n locales: locales ? locales : sortedLocales,\n getLocaleProperties: getLocalePropertiesCallback,\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInternalLocaleSelector.cjs","names":["useLocales","useCustomMapping","useLocale"],"sources":["../../src/hooks/useInternalLocaleSelector.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport type { LocaleProperties } from '@generaltranslation/format/types';\nimport { useCustomMapping, useLocales } from './i18n-config';\nimport { useLocale } from './condition-store';\nimport { getLocaleProperties } from '@generaltranslation/format';\n\n// Explicit return type so the inferred type stays portable for downstream\n// packages (e.g. gt-react-native), otherwise the getLocaleProperties callback\n// pulls in generaltranslation's bundled, non-nameable type (TS2742).\nexport type InternalLocaleSelectorResult = {\n locale: string;\n locales: string[];\n getLocaleProperties: (locale: string) => LocaleProperties;\n};\n\nexport function useInternalLocaleSelector(\n locales?: string[]\n): InternalLocaleSelectorResult {\n // Retrieve the locale, locales, and setLocale function\n const contextLocales = useLocales();\n const customMapping = useCustomMapping();\n const locale = useLocale();\n\n // sort\n const sortedLocales = useMemo(() => {\n if (!contextLocales || contextLocales.length === 0) {\n return [];\n }\n const collator = new Intl.Collator();\n return [...contextLocales].sort((a, b) =>\n collator.compare(\n getLocaleProperties(a, locale, customMapping).nativeNameWithRegionCode,\n getLocaleProperties(b, locale, customMapping).nativeNameWithRegionCode\n )\n );\n }, [contextLocales, locale, customMapping]);\n\n // create getLocaleProperties callback\n const getLocalePropertiesCallback = useCallback(\n (locale: string) => {\n return getLocaleProperties(locale, locale, customMapping);\n },\n [locale, customMapping]\n );\n\n return {\n locale,\n locales: locales ? locales : sortedLocales,\n getLocaleProperties: getLocalePropertiesCallback,\n };\n}\n"],"mappings":"oLAeA,SAAgB,EACd,EAC8B,CAE9B,IAAM,EAAiBA,EAAAA,YAAY,CAC7B,EAAgBC,EAAAA,kBAAkB,CAClC,EAASC,EAAAA,WAAW,CAGpB,GAAA,EAAA,EAAA,aAA8B,CAClC,GAAI,CAAC,GAAkB,EAAe,SAAW,EAC/C,MAAO,EAAE,CAEX,IAAM,EAAW,IAAI,KAAK,SAC1B,MAAO,CAAC,GAAG,EAAe,CAAC,MAAM,EAAG,IAClC,EAAS,SAAA,EAAA,EAAA,qBACa,EAAG,EAAQ,EAAc,CAAC,0BAAA,EAAA,EAAA,qBAC1B,EAAG,EAAQ,EAAc,CAAC,yBAC/C,CACF,EACA,CAAC,EAAgB,EAAQ,EAAc,CAAC,CAGrC,GAAA,EAAA,EAAA,aACH,IACC,EAAA,EAAA,qBAA2B,EAAQ,EAAQ,EAAc,CAE3D,CAAC,EAAQ,EAAc,CACxB,CAED,MAAO,CACL,SACA,QAAS,GAAoB,EAC7B,oBAAqB,EACtB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useLocale as e}from"./condition-store.mjs";import{useCustomMapping as t,useLocales as n}from"./i18n-config.mjs";import{useCallback as r,useMemo as i}from"react";import{getLocaleProperties as a}from"generaltranslation";function o(o){let s=n(),c=t(),l=e(),u=i(()=>{if(!s||s.length===0)return[];let e=new Intl.Collator;return[...s].sort((t,n)=>e.compare(a(t,l,c).nativeNameWithRegionCode,a(n,l,c).nativeNameWithRegionCode))},[s,l,c]),d=r(e=>a(e,e,c),[l,c]);return{locale:l,locales:o||u,getLocaleProperties:d}}export{o as useInternalLocaleSelector};
|
|
1
|
+
import{useLocale as e}from"./condition-store.mjs";import{useCustomMapping as t,useLocales as n}from"./i18n-config.mjs";import{useCallback as r,useMemo as i}from"react";import{getLocaleProperties as a}from"@generaltranslation/format";function o(o){let s=n(),c=t(),l=e(),u=i(()=>{if(!s||s.length===0)return[];let e=new Intl.Collator;return[...s].sort((t,n)=>e.compare(a(t,l,c).nativeNameWithRegionCode,a(n,l,c).nativeNameWithRegionCode))},[s,l,c]),d=r(e=>a(e,e,c),[l,c]);return{locale:l,locales:o||u,getLocaleProperties:d}}export{o as useInternalLocaleSelector};
|
|
2
2
|
//# sourceMappingURL=useInternalLocaleSelector.mjs.map
|