@generaltranslation/react-core 11.0.0-odysseus.14 → 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.
Files changed (57) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/components/branches/Plural.shared.cjs +1 -1
  3. package/dist/components/branches/Plural.shared.cjs.map +1 -1
  4. package/dist/components/branches/Plural.shared.mjs +1 -1
  5. package/dist/components/branches/Plural.shared.mjs.map +1 -1
  6. package/dist/components-rsc.cjs +1 -1
  7. package/dist/components-rsc.d.ts +2 -2
  8. package/dist/components-rsc.mjs +1 -1
  9. package/dist/condition-store/singleton-operations.cjs +1 -1
  10. package/dist/condition-store/singleton-operations.cjs.map +1 -1
  11. package/dist/condition-store/singleton-operations.d.ts +2 -7
  12. package/dist/condition-store/singleton-operations.d.ts.map +1 -1
  13. package/dist/condition-store/singleton-operations.mjs +1 -1
  14. package/dist/condition-store/singleton-operations.mjs.map +1 -1
  15. package/dist/context/context.cjs +1 -1
  16. package/dist/context/context.cjs.map +1 -1
  17. package/dist/context/context.mjs +1 -1
  18. package/dist/context/context.mjs.map +1 -1
  19. package/dist/functions/translation/t.cjs +1 -1
  20. package/dist/functions/translation/t.cjs.map +1 -1
  21. package/dist/functions/translation/t.d.ts.map +1 -1
  22. package/dist/functions/translation/t.mjs +1 -1
  23. package/dist/functions/translation/t.mjs.map +1 -1
  24. package/dist/hooks/condition-store.cjs +1 -1
  25. package/dist/hooks/condition-store.cjs.map +1 -1
  26. package/dist/hooks/condition-store.mjs +1 -1
  27. package/dist/hooks/condition-store.mjs.map +1 -1
  28. package/dist/hooks/useGT.cjs +1 -1
  29. package/dist/hooks/useGT.cjs.map +1 -1
  30. package/dist/hooks/useGT.mjs +1 -1
  31. package/dist/hooks/useGT.mjs.map +1 -1
  32. package/dist/hooks/useInternalLocaleSelector.cjs +1 -1
  33. package/dist/hooks/useInternalLocaleSelector.cjs.map +1 -1
  34. package/dist/hooks/useInternalLocaleSelector.mjs +1 -1
  35. package/dist/hooks/useInternalLocaleSelector.mjs.map +1 -1
  36. package/dist/hooks/useInternalRegionSelector.cjs +1 -1
  37. package/dist/hooks/useInternalRegionSelector.cjs.map +1 -1
  38. package/dist/hooks/useInternalRegionSelector.mjs +1 -1
  39. package/dist/hooks/useInternalRegionSelector.mjs.map +1 -1
  40. package/dist/hooks/utils/getShouldTranslate.cjs +1 -1
  41. package/dist/hooks/utils/getShouldTranslate.cjs.map +1 -1
  42. package/dist/hooks/utils/getShouldTranslate.mjs +1 -1
  43. package/dist/hooks/utils/getShouldTranslate.mjs.map +1 -1
  44. package/dist/hooks/utils.d.ts +2 -2
  45. package/dist/hooks/utils.d.ts.map +1 -1
  46. package/dist/pure.cjs +1 -1
  47. package/dist/pure.d.ts +2 -2
  48. package/dist/pure.mjs +1 -1
  49. package/dist/utils/rendering/renderDefaultChildren.shared.cjs +1 -1
  50. package/dist/utils/rendering/renderDefaultChildren.shared.cjs.map +1 -1
  51. package/dist/utils/rendering/renderDefaultChildren.shared.mjs +1 -1
  52. package/dist/utils/rendering/renderDefaultChildren.shared.mjs.map +1 -1
  53. package/dist/utils/rendering/renderTranslatedChildren.shared.cjs +1 -1
  54. package/dist/utils/rendering/renderTranslatedChildren.shared.cjs.map +1 -1
  55. package/dist/utils/rendering/renderTranslatedChildren.shared.mjs +1 -1
  56. package/dist/utils/rendering/renderTranslatedChildren.shared.mjs.map +1 -1
  57. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
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
+
3
21
  ## 11.0.0-odysseus.14
4
22
 
5
23
  ### Patch Changes
@@ -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`&&e.getPluralBranch(a,c,s)||i}exports.renderPlural=n;
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 return getPluralBranch(n, locales, branches) || 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,CAIF,OAHI,OAAO,GAAM,UAGVC,EAAAA,gBAAgB,EAAG,EAAS,EAAS,EAFnC"}
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`&&e(a,c,s)||i}export{n as renderPlural};
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 return getPluralBranch(n, locales, branches) || 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,CAIF,OAHI,OAAO,GAAM,UAGV,EAAgB,EAAG,EAAS,EAAS,EAFnC"}
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"}
@@ -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.getReadonlyConditionStoreWithFallback=i.getReadonlyConditionStoreWithFallback,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;
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;
@@ -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 { getReadonlyConditionStoreWithFallback } from "./condition-store/singleton-operations.js";
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, getReadonlyConditionStoreWithFallback, getShouldTranslate, getTranslationsSnapshot, internalInitializeGTSRA, prepareT, renderDefaultChildren, renderPreparedT, renderTranslatedChildren, renderVariable, setReactI18nCache, t };
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 };
@@ -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{getReadonlyConditionStoreWithFallback 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 getReadonlyConditionStoreWithFallback,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
+ 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`);const e=require(`../setup/i18nConfig.cjs`);let t=require(`generaltranslation/internal`),n=require(`gt-i18n/internal`);const{getConditionStore:r,setConditionStore:i,isConditionStoreInitialized:a}=(0,n.createConditionStoreSingleton)((0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read GT runtime context before it has been initialized`,why:`The internal ConditionStore is unavailable`}));function o(){try{return r()}catch(r){let i=(0,n.getRuntimeEnvironment)(),a=e.getI18nConfig().getRenderStrategy(),o=(0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot access ConditionStore before it is initialized.`,details:(0,t.formatDiagnosticErrorDetails)(r),fix:a===`SPA`?`Initialize GT before reading GT runtime context.`:`Add a <GTProvider> at the root of your component tree.`,wayOut:i===`development`?void 0:a===`SPA`?`Request-specific values will fall back to the default configuration.`:`Request-specific values will fall back to the default configuration. This may cause hydration mismatches.`});if(i===`development`)throw Error(o);return console.error(o),{getLocale:()=>t.libraryDefaultLocale,getRegion:()=>void 0,getEnableI18n:()=>!0,setLocale:()=>{},setRegion:()=>{},setEnableI18n:()=>{}}}}exports.getReadonlyConditionStoreWithFallback=o,exports.isConditionStoreInitialized=a,exports.setConditionStore=i;
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":["getI18nConfig","libraryDefaultLocale"],"sources":["../../src/condition-store/singleton-operations.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n libraryDefaultLocale,\n} from 'generaltranslation/internal';\nimport {\n createConditionStoreSingleton,\n getRuntimeEnvironment,\n} from 'gt-i18n/internal';\nimport type { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../setup/i18nConfig';\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});\n\nconst { getConditionStore, setConditionStore, isConditionStoreInitialized } =\n createConditionStoreSingleton<ReadonlyConditionStoreInterface>(\n conditionStoreNotInitializedError\n );\n\n/**\n * Opinionated decision: add a safety wrapper around the condition store to be more forgiving in production\n * TODO: perhaps this is how condition store should always be accessed\n */\nfunction getReadonlyConditionStoreWithFallback(): ReadonlyConditionStoreInterface {\n try {\n return getConditionStore();\n } catch (error) {\n // Error handling\n const runtimeEnvironment = getRuntimeEnvironment();\n const renderStrategy = getI18nConfig().getRenderStrategy();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot access ConditionStore before it is initialized.',\n details: formatDiagnosticErrorDetails(error),\n fix:\n renderStrategy === 'SPA'\n ? 'Initialize GT before reading GT runtime context.'\n : 'Add a <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : renderStrategy === 'SPA'\n ? 'Request-specific values will fall back to the default configuration.'\n : 'Request-specific values will fall back to the default configuration. This may cause hydration mismatches.',\n });\n\n if (runtimeEnvironment === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n\n // Fallback to default configuration (important: do not set globally)\n return {\n getLocale: () => libraryDefaultLocale,\n getRegion: () => undefined,\n getEnableI18n: () => true,\n setLocale: () => {},\n setRegion: () => {},\n setEnableI18n: () => {},\n };\n }\n}\n\nexport {\n getReadonlyConditionStoreWithFallback,\n setConditionStore as setReadonlyConditionStore,\n isConditionStoreInitialized as isReadonlyConditionStoreInitialized,\n};\n"],"mappings":"mKAmBA,KAAM,CAAE,oBAAmB,oBAAmB,gCAAA,EAAA,EAAA,gCAAA,EAAA,EAAA,yBAPoB,CAChE,OAAQ,iCACR,SAAU,QACV,aAAc,gEACd,IAAK,6CACN,CAIoC,CAClC,CAMH,SAAS,GAAyE,CAChF,GAAI,CACF,OAAO,GAAmB,OACnB,EAAO,CAEd,IAAM,GAAA,EAAA,EAAA,wBAA4C,CAC5C,EAAiBA,EAAAA,eAAe,CAAC,mBAAmB,CACpD,GAAA,EAAA,EAAA,yBAAuC,CAC3C,OAAQ,iCACR,SAAU,QACV,aAAc,yDACd,SAAA,EAAA,EAAA,8BAAsC,EAAM,CAC5C,IACE,IAAmB,MACf,mDACA,yDACN,OACE,IAAuB,cACnB,IAAA,GACA,IAAmB,MACjB,uEACA,4GACT,CAAC,CAEF,GAAI,IAAuB,cACzB,MAAU,MAAM,EAAa,CAM/B,OAJE,QAAQ,MAAM,EAAa,CAItB,CACL,cAAiBC,EAAAA,qBACjB,cAAiB,IAAA,GACjB,kBAAqB,GACrB,cAAiB,GACjB,cAAiB,GACjB,kBAAqB,GACtB"}
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 { getReadonlyConditionStoreWithFallback, setConditionStore };
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":";;;cAmB2B,iBAAA,GAAiB,IAAA,EAAA,+BAAA,WAAE,2BAAA;;AAVgC;;;iBAmBrE,qCAAA,CAAA,GAAyC,+BAAA"}
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{getI18nConfig as e}from"../setup/i18nConfig.mjs";import{createDiagnosticMessage as t,formatDiagnosticErrorDetails as n,libraryDefaultLocale as r}from"generaltranslation/internal";import{createConditionStoreSingleton as i,getRuntimeEnvironment as a}from"gt-i18n/internal";const{getConditionStore:o,setConditionStore:s,isConditionStoreInitialized:c}=i(t({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read GT runtime context before it has been initialized`,why:`The internal ConditionStore is unavailable`}));function l(){try{return o()}catch(i){let o=a(),s=e().getRenderStrategy(),c=t({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot access ConditionStore before it is initialized.`,details:n(i),fix:s===`SPA`?`Initialize GT before reading GT runtime context.`:`Add a <GTProvider> at the root of your component tree.`,wayOut:o===`development`?void 0:s===`SPA`?`Request-specific values will fall back to the default configuration.`:`Request-specific values will fall back to the default configuration. This may cause hydration mismatches.`});if(o===`development`)throw Error(c);return console.error(c),{getLocale:()=>r,getRegion:()=>void 0,getEnableI18n:()=>!0,setLocale:()=>{},setRegion:()=>{},setEnableI18n:()=>{}}}}export{l as getReadonlyConditionStoreWithFallback,c as isConditionStoreInitialized,s as setConditionStore};
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":["getI18nConfig"],"sources":["../../src/condition-store/singleton-operations.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n formatDiagnosticErrorDetails,\n libraryDefaultLocale,\n} from 'generaltranslation/internal';\nimport {\n createConditionStoreSingleton,\n getRuntimeEnvironment,\n} from 'gt-i18n/internal';\nimport type { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../setup/i18nConfig';\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});\n\nconst { getConditionStore, setConditionStore, isConditionStoreInitialized } =\n createConditionStoreSingleton<ReadonlyConditionStoreInterface>(\n conditionStoreNotInitializedError\n );\n\n/**\n * Opinionated decision: add a safety wrapper around the condition store to be more forgiving in production\n * TODO: perhaps this is how condition store should always be accessed\n */\nfunction getReadonlyConditionStoreWithFallback(): ReadonlyConditionStoreInterface {\n try {\n return getConditionStore();\n } catch (error) {\n // Error handling\n const runtimeEnvironment = getRuntimeEnvironment();\n const renderStrategy = getI18nConfig().getRenderStrategy();\n const errorMessage = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot access ConditionStore before it is initialized.',\n details: formatDiagnosticErrorDetails(error),\n fix:\n renderStrategy === 'SPA'\n ? 'Initialize GT before reading GT runtime context.'\n : 'Add a <GTProvider> at the root of your component tree.',\n wayOut:\n runtimeEnvironment === 'development'\n ? undefined\n : renderStrategy === 'SPA'\n ? 'Request-specific values will fall back to the default configuration.'\n : 'Request-specific values will fall back to the default configuration. This may cause hydration mismatches.',\n });\n\n if (runtimeEnvironment === 'development') {\n throw new Error(errorMessage);\n } else {\n console.error(errorMessage);\n }\n\n // Fallback to default configuration (important: do not set globally)\n return {\n getLocale: () => libraryDefaultLocale,\n getRegion: () => undefined,\n getEnableI18n: () => true,\n setLocale: () => {},\n setRegion: () => {},\n setEnableI18n: () => {},\n };\n }\n}\n\nexport {\n getReadonlyConditionStoreWithFallback,\n setConditionStore as setReadonlyConditionStore,\n isConditionStoreInitialized as isReadonlyConditionStoreInitialized,\n};\n"],"mappings":"sRAmBA,KAAM,CAAE,oBAAmB,oBAAmB,+BAC5C,EARwC,EAAwB,CAChE,OAAQ,iCACR,SAAU,QACV,aAAc,gEACd,IAAK,6CACN,CAIoC,CAClC,CAMH,SAAS,GAAyE,CAChF,GAAI,CACF,OAAO,GAAmB,OACnB,EAAO,CAEd,IAAM,EAAqB,GAAuB,CAC5C,EAAiBA,GAAe,CAAC,mBAAmB,CACpD,EAAe,EAAwB,CAC3C,OAAQ,iCACR,SAAU,QACV,aAAc,yDACd,QAAS,EAA6B,EAAM,CAC5C,IACE,IAAmB,MACf,mDACA,yDACN,OACE,IAAuB,cACnB,IAAA,GACA,IAAmB,MACjB,uEACA,4GACT,CAAC,CAEF,GAAI,IAAuB,cACzB,MAAU,MAAM,EAAa,CAM/B,OAJE,QAAQ,MAAM,EAAa,CAItB,CACL,cAAiB,EACjB,cAAiB,IAAA,GACjB,kBAAqB,GACrB,cAAiB,GACjB,cAAiB,GACjB,kBAAqB,GACtB"}
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"}
@@ -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:()=>`GTContext has not been initialized.`});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;
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: () => 'GTContext has not been initialized.',\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,mBAAsB,sCACvB,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,KAAA,EAAA,EAAA,eAA6C,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,GAAA,EAAA,EAAA,YAAqB,GAAc,CAAC,CAC1C,GAAI,GAAWA,EAAAA,eAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAA,EAAA,EAAA,yBAA+B,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
1
+ {"version":3,"file":"context.cjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import {\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"}
@@ -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:()=>`GTContext has not been initialized.`});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};
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: () => 'GTContext has not been initialized.',\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,mBAAsB,sCACvB,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,IAAI,EAAyC,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,EAAU,EAAW,GAAc,CAAC,CAC1C,GAAI,GAAWA,GAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAO,EAAwB,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
1
+ {"version":3,"file":"context.mjs","names":["getI18nConfig"],"sources":["../../src/context/context.ts"],"sourcesContent":["import {\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);return s(n?.$locale??f(),e,n)}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.getReadonlyConditionStoreWithFallback().getLocale()}exports.t=o;
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","getReadonlyConditionStoreWithFallback"],"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 getReadonlyConditionStoreWithFallback,\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(locale, messageOrStrings, options);\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 getReadonlyConditionStoreWithFallback().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,CAE5B,OAAO,EADQ,GAAS,SAAW,GAAW,CACV,EAAkB,EAAQ,CAIhE,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,uCAAuC,CAAC,WAAW"}
1
+ {"version":3,"file":"t.cjs","names":["getReactI18nCache","getI18nConfig","getShouldTranslate","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions, 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;;;;;AA+CC;;;;;;;;;cA/CY,CAAA,EAAG,sCAAA;;;;;;;;;UA2LN,sCAAA;EAAA,CACP,OAAA,EAAS,oBAAA,KAAyB,MAAA;EAAA,CAClC,OAAA,UAAiB,OAAA,GAAU,oBAAA;AAAA"}
1
+ {"version":3,"file":"t.d.ts","names":[],"sources":["../../../src/functions/translation/t.ts"],"mappings":";;;;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{getReadonlyConditionStoreWithFallback 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);return u(n?.$locale??h(),e,n)}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};
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 getReadonlyConditionStoreWithFallback,\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(locale, messageOrStrings, options);\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 getReadonlyConditionStoreWithFallback().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":"+gBAgCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CAE5B,OAAO,EADQ,GAAS,SAAW,GAAW,CACV,EAAkB,EAAQ,CAIhE,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,OAAO,GAAuC,CAAC,WAAW"}
1
+ {"version":3,"file":"t.mjs","names":["getI18nConfig","isReadonlyConditionStoreInitialized","getReadonlyConditionStore"],"sources":["../../../src/functions/translation/t.ts"],"sourcesContent":["import {\n createLookupOptions,\n getRuntimeEnvironment,\n interpolateMessage,\n} from 'gt-i18n/internal';\nimport type { GTTranslationOptions, 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.getReadonlyConditionStoreWithFallback()}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;
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","getReadonlyConditionStoreWithFallback"],"sources":["../../src/hooks/condition-store.ts"],"sourcesContent":["import { ReadonlyConditionStoreInterface } from 'gt-i18n/internal/types';\nimport { getReadonlyConditionStoreWithFallback } 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 ?? getReadonlyConditionStoreWithFallback();\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,uCAAuC,CAM3E,SAAgB,GAAoB,CAClC,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAgC,CAC9C,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAyB,CACvC,OAAO,GAAmB,CAAC,eAAe"}
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{getReadonlyConditionStoreWithFallback 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};
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 { getReadonlyConditionStoreWithFallback } 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 ?? getReadonlyConditionStoreWithFallback();\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":"0JASA,SAAgB,GAAqD,CAEnE,OADgB,GACF,EAAE,gBAAkB,GAAuC,CAM3E,SAAgB,GAAoB,CAClC,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAgC,CAC9C,OAAO,GAAmB,CAAC,WAAW,CAMxC,SAAgB,GAAyB,CACvC,OAAO,GAAmB,CAAC,eAAe"}
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"}
@@ -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={})=>{if(!l)return(0,a.interpolateMessage)({options:t,source:e,sourceLocale:c});let n=(0,a.createLookupOptions)(t.$locale??s,t,`ICU`);return(0,a.interpolateMessage)({source:e,target:u({locale:n.$locale,message:e,options:n}),options:n,sourceLocale:c})},[c,s,l,u])}exports.useGT=o;
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
@@ -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 lookupOptions = createLookupOptions<StringFormat>(\n options.$locale ?? locale,\n options,\n 'ICU'\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,GAAI,CAAC,EACH,OAAA,EAAA,EAAA,oBAA0B,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,GAAA,EAAA,EAAA,qBACJ,EAAQ,SAAW,EACnB,EACA,MACD,CAOD,OAAA,EAAA,EAAA,oBAA0B,CACxB,OAAQ,EACR,OARkB,EAAmB,CACrC,OAAQ,EAAc,QACtB,UACA,QAAS,EACV,CAIoB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,EAEJ,CAAC,EAAe,EAAQ,EAAiB,EAAmB,CAC7D"}
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"}
@@ -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={})=>{if(!u)return o({options:t,source:e,sourceLocale:l});let n=a(t.$locale??c,t,`ICU`);return o({source:e,target:d({locale:n.$locale,message:e,options:n}),options:n,sourceLocale:l})},[l,c,u,d])}export{s as useGT};
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
@@ -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 lookupOptions = createLookupOptions<StringFormat>(\n options.$locale ?? locale,\n options,\n 'ICU'\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,GAAI,CAAC,EACH,OAAO,EAAmB,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,EAAgB,EACpB,EAAQ,SAAW,EACnB,EACA,MACD,CAOD,OAAO,EAAmB,CACxB,OAAQ,EACR,OARkB,EAAmB,CACrC,OAAQ,EAAc,QACtB,UACA,QAAS,EACV,CAIoB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,EAEJ,CAAC,EAAe,EAAQ,EAAiB,EAAmB,CAC7D"}
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(`generaltranslation`);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;
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":"4KAeA,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
+ {"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
@@ -1 +1 @@
1
- {"version":3,"file":"useInternalLocaleSelector.mjs","names":[],"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":"iOAeA,SAAgB,EACd,EAC8B,CAE9B,IAAM,EAAiB,GAAY,CAC7B,EAAgB,GAAkB,CAClC,EAAS,GAAW,CAGpB,EAAgB,MAAc,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,QACP,EAAoB,EAAG,EAAQ,EAAc,CAAC,yBAC9C,EAAoB,EAAG,EAAQ,EAAc,CAAC,yBAC/C,CACF,EACA,CAAC,EAAgB,EAAQ,EAAc,CAAC,CAGrC,EAA8B,EACjC,GACQ,EAAoB,EAAQ,EAAQ,EAAc,CAE3D,CAAC,EAAQ,EAAc,CACxB,CAED,MAAO,CACL,SACA,QAAS,GAAoB,EAC7B,oBAAqB,EACtB"}
1
+ {"version":3,"file":"useInternalLocaleSelector.mjs","names":[],"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":"yOAeA,SAAgB,EACd,EAC8B,CAE9B,IAAM,EAAiB,GAAY,CAC7B,EAAgB,GAAkB,CAClC,EAAS,GAAW,CAGpB,EAAgB,MAAc,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,QACP,EAAoB,EAAG,EAAQ,EAAc,CAAC,yBAC9C,EAAoB,EAAG,EAAQ,EAAc,CAAC,yBAC/C,CACF,EACA,CAAC,EAAgB,EAAQ,EAAc,CAAC,CAGrC,EAA8B,EACjC,GACQ,EAAoB,EAAQ,EAAQ,EAAc,CAE3D,CAAC,EAAQ,EAAc,CACxB,CAED,MAAO,CACL,SACA,QAAS,GAAoB,EAC7B,oBAAqB,EACtB"}
@@ -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(`gt-i18n/internal`),i=require(`generaltranslation`);function a({regions:a,customMapping:o,prioritizeCurrentLocaleRegion:s=!0,sortRegionsAlphabetically:c=!0}={}){let l=t.useLocales(),u=t.useCustomMapping(),d=e.useLocale(),f=e.useRegion(),{regionCode:p}=(0,i.getLocaleProperties)(d,d,u),[m,h]=(0,n.useMemo)(()=>{let e=(0,r.getI18nConfig)().getGTClass(d),t=new Map(l.map(e=>{let t=(0,i.getLocaleProperties)(e,d,u);return[t.regionCode,t]})),n=a?[...a]:Array.from(t?.keys()||[p]),f=new Map(n.map(n=>[n,{locale:t?.get(n)?.code||d,...e.getRegionProperties(n),...typeof o?.[n]==`string`?{name:o?.[n]}:o?.[n]}]));if(c&&n.sort((e,t)=>new Intl.Collator().compare(f.get(e).name,f.get(t).name)),s){let e=n.indexOf(p);e>0&&(n.splice(e,1),n.unshift(p))}return[n,f]},[a,o,d,p,l,u,s,c]);return{region:f,regions:m,regionData:h,locale:d,localeRegion:p}}exports.useInternalRegionSelector=a;
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./condition-store.cjs`),t=require(`./i18n-config.cjs`);let n=require(`react`),r=require(`gt-i18n/internal`),i=require(`@generaltranslation/format`);function a({regions:a,customMapping:o,prioritizeCurrentLocaleRegion:s=!0,sortRegionsAlphabetically:c=!0}={}){let l=t.useLocales(),u=t.useCustomMapping(),d=e.useLocale(),f=e.useRegion(),{regionCode:p}=(0,i.getLocaleProperties)(d,d,u),[m,h]=(0,n.useMemo)(()=>{let e=(0,r.getI18nConfig)().getGTClass(d),t=new Map(l.map(e=>{let t=(0,i.getLocaleProperties)(e,d,u);return[t.regionCode,t]})),n=a?[...a]:Array.from(t?.keys()||[p]),f=new Map(n.map(n=>[n,{locale:t?.get(n)?.code||d,...e.getRegionProperties(n),...typeof o?.[n]==`string`?{name:o?.[n]}:o?.[n]}]));if(c&&n.sort((e,t)=>new Intl.Collator().compare(f.get(e).name,f.get(t).name)),s){let e=n.indexOf(p);e>0&&(n.splice(e,1),n.unshift(p))}return[n,f]},[a,o,d,p,l,u,s,c]);return{region:f,regions:m,regionData:h,locale:d,localeRegion:p}}exports.useInternalRegionSelector=a;
2
2
  //# sourceMappingURL=useInternalRegionSelector.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInternalRegionSelector.cjs","names":["useLocales","useCustomMapping","useLocale","useRegion"],"sources":["../../src/hooks/useInternalRegionSelector.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useCustomMapping, useLocales } from './i18n-config';\nimport { useLocale, useRegion } from './condition-store';\nimport { getLocaleProperties } from 'generaltranslation';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\nexport type RegionData = {\n code: string;\n name: string;\n emoji: string;\n locale: string;\n};\n\nexport type InternalRegionSelectorOptions = {\n regions?: string[];\n customMapping?: {\n [region: string]:\n | string\n | { name?: string; emoji?: string; locale?: string };\n };\n prioritizeCurrentLocaleRegion?: boolean;\n sortRegionsAlphabetically?: boolean;\n};\n\nexport type InternalRegionSelectorResult = {\n region: string | undefined;\n regions: string[];\n regionData: Map<string, RegionData>;\n locale: string;\n localeRegion: string;\n};\n\n/**\n * Internal logic for region selection in applications supporting multiple regions.\n *\n * Returns the current region, an ordered list of available regions (inferred\n * from the supported locales when not provided), and a map of region codes to\n * their display data (name, emoji, associated locale).\n */\nexport function useInternalRegionSelector({\n regions: _regions,\n customMapping,\n prioritizeCurrentLocaleRegion = true,\n sortRegionsAlphabetically = true,\n}: InternalRegionSelectorOptions = {}): InternalRegionSelectorResult {\n // Retrieve the locale, locales, and region\n const contextLocales = useLocales();\n const localeCustomMapping = useCustomMapping();\n const locale = useLocale();\n const region = useRegion();\n const { regionCode: localeRegion } = getLocaleProperties(\n locale,\n locale,\n localeCustomMapping\n );\n\n const [\n regions, // ordered list of ISO 3166 region codes\n regionData, // map of ISO 3166 region codes to region display data, potentially not ordered\n ] = useMemo<[string[], Map<string, RegionData>]>(() => {\n const gt = getI18nConfig().getGTClass(locale);\n const regionToLocaleMap = new Map(\n contextLocales.map((l) => {\n const lp = getLocaleProperties(l, locale, localeCustomMapping); // has to be directly called so sourceLocale can be in the user's current locale\n return [lp.regionCode, lp];\n })\n );\n\n const regions = _regions\n ? [..._regions]\n : Array.from(regionToLocaleMap?.keys() || [localeRegion]);\n\n const regionData = new Map<string, RegionData>(\n regions.map((r: string) => {\n return [\n r,\n {\n locale: regionToLocaleMap?.get(r)?.code || locale,\n ...gt.getRegionProperties(r),\n ...(typeof customMapping?.[r] === 'string'\n ? { name: customMapping?.[r] }\n : customMapping?.[r]),\n },\n ];\n })\n );\n\n if (sortRegionsAlphabetically) {\n regions.sort((a, b) =>\n new Intl.Collator().compare(\n regionData.get(a)!.name,\n regionData.get(b)!.name\n )\n );\n }\n\n if (prioritizeCurrentLocaleRegion) {\n const localeRegionIndex = regions.indexOf(localeRegion);\n if (localeRegionIndex > 0) {\n // 0 because no action is needed if it's already at the start\n regions.splice(localeRegionIndex, 1);\n regions.unshift(localeRegion);\n }\n }\n\n return [regions, regionData];\n }, [\n _regions,\n customMapping,\n locale,\n localeRegion,\n contextLocales,\n localeCustomMapping,\n prioritizeCurrentLocaleRegion,\n sortRegionsAlphabetically,\n ]);\n\n return {\n region,\n regions,\n regionData,\n locale,\n localeRegion,\n };\n}\n"],"mappings":"0MAuCA,SAAgB,EAA0B,CACxC,QAAS,EACT,gBACA,gCAAgC,GAChC,4BAA4B,IACK,EAAE,CAAgC,CAEnE,IAAM,EAAiBA,EAAAA,YAAY,CAC7B,EAAsBC,EAAAA,kBAAkB,CACxC,EAASC,EAAAA,WAAW,CACpB,EAASC,EAAAA,WAAW,CACpB,CAAE,WAAY,IAAA,EAAA,EAAA,qBAClB,EACA,EACA,EACD,CAEK,CACJ,EACA,IAAA,EAAA,EAAA,aACqD,CACrD,IAAM,GAAA,EAAA,EAAA,gBAAoB,CAAC,WAAW,EAAO,CACvC,EAAoB,IAAI,IAC5B,EAAe,IAAK,GAAM,CACxB,IAAM,GAAA,EAAA,EAAA,qBAAyB,EAAG,EAAQ,EAAoB,CAC9D,MAAO,CAAC,EAAG,WAAY,EAAG,EAC1B,CACH,CAEK,EAAU,EACZ,CAAC,GAAG,EAAS,CACb,MAAM,KAAK,GAAmB,MAAM,EAAI,CAAC,EAAa,CAAC,CAErD,EAAa,IAAI,IACrB,EAAQ,IAAK,GACJ,CACL,EACA,CACE,OAAQ,GAAmB,IAAI,EAAE,EAAE,MAAQ,EAC3C,GAAG,EAAG,oBAAoB,EAAE,CAC5B,GAAI,OAAO,IAAgB,IAAO,SAC9B,CAAE,KAAM,IAAgB,GAAI,CAC5B,IAAgB,GACrB,CACF,CACD,CACH,CAWD,GATI,GACF,EAAQ,MAAM,EAAG,IACf,IAAI,KAAK,UAAU,CAAC,QAClB,EAAW,IAAI,EAAE,CAAE,KACnB,EAAW,IAAI,EAAE,CAAE,KACpB,CACF,CAGC,EAA+B,CACjC,IAAM,EAAoB,EAAQ,QAAQ,EAAa,CACnD,EAAoB,IAEtB,EAAQ,OAAO,EAAmB,EAAE,CACpC,EAAQ,QAAQ,EAAa,EAIjC,MAAO,CAAC,EAAS,EAAW,EAC3B,CACD,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CAAC,CAEF,MAAO,CACL,SACA,UACA,aACA,SACA,eACD"}
1
+ {"version":3,"file":"useInternalRegionSelector.cjs","names":["useLocales","useCustomMapping","useLocale","useRegion"],"sources":["../../src/hooks/useInternalRegionSelector.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useCustomMapping, useLocales } from './i18n-config';\nimport { useLocale, useRegion } from './condition-store';\nimport { getLocaleProperties } from '@generaltranslation/format';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\nexport type RegionData = {\n code: string;\n name: string;\n emoji: string;\n locale: string;\n};\n\nexport type InternalRegionSelectorOptions = {\n regions?: string[];\n customMapping?: {\n [region: string]:\n | string\n | { name?: string; emoji?: string; locale?: string };\n };\n prioritizeCurrentLocaleRegion?: boolean;\n sortRegionsAlphabetically?: boolean;\n};\n\nexport type InternalRegionSelectorResult = {\n region: string | undefined;\n regions: string[];\n regionData: Map<string, RegionData>;\n locale: string;\n localeRegion: string;\n};\n\n/**\n * Internal logic for region selection in applications supporting multiple regions.\n *\n * Returns the current region, an ordered list of available regions (inferred\n * from the supported locales when not provided), and a map of region codes to\n * their display data (name, emoji, associated locale).\n */\nexport function useInternalRegionSelector({\n regions: _regions,\n customMapping,\n prioritizeCurrentLocaleRegion = true,\n sortRegionsAlphabetically = true,\n}: InternalRegionSelectorOptions = {}): InternalRegionSelectorResult {\n // Retrieve the locale, locales, and region\n const contextLocales = useLocales();\n const localeCustomMapping = useCustomMapping();\n const locale = useLocale();\n const region = useRegion();\n const { regionCode: localeRegion } = getLocaleProperties(\n locale,\n locale,\n localeCustomMapping\n );\n\n const [\n regions, // ordered list of ISO 3166 region codes\n regionData, // map of ISO 3166 region codes to region display data, potentially not ordered\n ] = useMemo<[string[], Map<string, RegionData>]>(() => {\n const gt = getI18nConfig().getGTClass(locale);\n const regionToLocaleMap = new Map(\n contextLocales.map((l) => {\n const lp = getLocaleProperties(l, locale, localeCustomMapping); // has to be directly called so sourceLocale can be in the user's current locale\n return [lp.regionCode, lp];\n })\n );\n\n const regions = _regions\n ? [..._regions]\n : Array.from(regionToLocaleMap?.keys() || [localeRegion]);\n\n const regionData = new Map<string, RegionData>(\n regions.map((r: string) => {\n return [\n r,\n {\n locale: regionToLocaleMap?.get(r)?.code || locale,\n ...gt.getRegionProperties(r),\n ...(typeof customMapping?.[r] === 'string'\n ? { name: customMapping?.[r] }\n : customMapping?.[r]),\n },\n ];\n })\n );\n\n if (sortRegionsAlphabetically) {\n regions.sort((a, b) =>\n new Intl.Collator().compare(\n regionData.get(a)!.name,\n regionData.get(b)!.name\n )\n );\n }\n\n if (prioritizeCurrentLocaleRegion) {\n const localeRegionIndex = regions.indexOf(localeRegion);\n if (localeRegionIndex > 0) {\n // 0 because no action is needed if it's already at the start\n regions.splice(localeRegionIndex, 1);\n regions.unshift(localeRegion);\n }\n }\n\n return [regions, regionData];\n }, [\n _regions,\n customMapping,\n locale,\n localeRegion,\n contextLocales,\n localeCustomMapping,\n prioritizeCurrentLocaleRegion,\n sortRegionsAlphabetically,\n ]);\n\n return {\n region,\n regions,\n regionData,\n locale,\n localeRegion,\n };\n}\n"],"mappings":"kNAuCA,SAAgB,EAA0B,CACxC,QAAS,EACT,gBACA,gCAAgC,GAChC,4BAA4B,IACK,EAAE,CAAgC,CAEnE,IAAM,EAAiBA,EAAAA,YAAY,CAC7B,EAAsBC,EAAAA,kBAAkB,CACxC,EAASC,EAAAA,WAAW,CACpB,EAASC,EAAAA,WAAW,CACpB,CAAE,WAAY,IAAA,EAAA,EAAA,qBAClB,EACA,EACA,EACD,CAEK,CACJ,EACA,IAAA,EAAA,EAAA,aACqD,CACrD,IAAM,GAAA,EAAA,EAAA,gBAAoB,CAAC,WAAW,EAAO,CACvC,EAAoB,IAAI,IAC5B,EAAe,IAAK,GAAM,CACxB,IAAM,GAAA,EAAA,EAAA,qBAAyB,EAAG,EAAQ,EAAoB,CAC9D,MAAO,CAAC,EAAG,WAAY,EAAG,EAC1B,CACH,CAEK,EAAU,EACZ,CAAC,GAAG,EAAS,CACb,MAAM,KAAK,GAAmB,MAAM,EAAI,CAAC,EAAa,CAAC,CAErD,EAAa,IAAI,IACrB,EAAQ,IAAK,GACJ,CACL,EACA,CACE,OAAQ,GAAmB,IAAI,EAAE,EAAE,MAAQ,EAC3C,GAAG,EAAG,oBAAoB,EAAE,CAC5B,GAAI,OAAO,IAAgB,IAAO,SAC9B,CAAE,KAAM,IAAgB,GAAI,CAC5B,IAAgB,GACrB,CACF,CACD,CACH,CAWD,GATI,GACF,EAAQ,MAAM,EAAG,IACf,IAAI,KAAK,UAAU,CAAC,QAClB,EAAW,IAAI,EAAE,CAAE,KACnB,EAAW,IAAI,EAAE,CAAE,KACpB,CACF,CAGC,EAA+B,CACjC,IAAM,EAAoB,EAAQ,QAAQ,EAAa,CACnD,EAAoB,IAEtB,EAAQ,OAAO,EAAmB,EAAE,CACpC,EAAQ,QAAQ,EAAa,EAIjC,MAAO,CAAC,EAAS,EAAW,EAC3B,CACD,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CAAC,CAEF,MAAO,CACL,SACA,UACA,aACA,SACA,eACD"}
@@ -1,2 +1,2 @@
1
- import{useLocale as e,useRegion as t}from"./condition-store.mjs";import{useCustomMapping as n,useLocales as r}from"./i18n-config.mjs";import{useMemo as i}from"react";import{getI18nConfig as a}from"gt-i18n/internal";import{getLocaleProperties as o}from"generaltranslation";function s({regions:s,customMapping:c,prioritizeCurrentLocaleRegion:l=!0,sortRegionsAlphabetically:u=!0}={}){let d=r(),f=n(),p=e(),m=t(),{regionCode:h}=o(p,p,f),[g,_]=i(()=>{let e=a().getGTClass(p),t=new Map(d.map(e=>{let t=o(e,p,f);return[t.regionCode,t]})),n=s?[...s]:Array.from(t?.keys()||[h]),r=new Map(n.map(n=>[n,{locale:t?.get(n)?.code||p,...e.getRegionProperties(n),...typeof c?.[n]==`string`?{name:c?.[n]}:c?.[n]}]));if(u&&n.sort((e,t)=>new Intl.Collator().compare(r.get(e).name,r.get(t).name)),l){let e=n.indexOf(h);e>0&&(n.splice(e,1),n.unshift(h))}return[n,r]},[s,c,p,h,d,f,l,u]);return{region:m,regions:g,regionData:_,locale:p,localeRegion:h}}export{s as useInternalRegionSelector};
1
+ import{useLocale as e,useRegion as t}from"./condition-store.mjs";import{useCustomMapping as n,useLocales as r}from"./i18n-config.mjs";import{useMemo as i}from"react";import{getI18nConfig as a}from"gt-i18n/internal";import{getLocaleProperties as o}from"@generaltranslation/format";function s({regions:s,customMapping:c,prioritizeCurrentLocaleRegion:l=!0,sortRegionsAlphabetically:u=!0}={}){let d=r(),f=n(),p=e(),m=t(),{regionCode:h}=o(p,p,f),[g,_]=i(()=>{let e=a().getGTClass(p),t=new Map(d.map(e=>{let t=o(e,p,f);return[t.regionCode,t]})),n=s?[...s]:Array.from(t?.keys()||[h]),r=new Map(n.map(n=>[n,{locale:t?.get(n)?.code||p,...e.getRegionProperties(n),...typeof c?.[n]==`string`?{name:c?.[n]}:c?.[n]}]));if(u&&n.sort((e,t)=>new Intl.Collator().compare(r.get(e).name,r.get(t).name)),l){let e=n.indexOf(h);e>0&&(n.splice(e,1),n.unshift(h))}return[n,r]},[s,c,p,h,d,f,l,u]);return{region:m,regions:g,regionData:_,locale:p,localeRegion:h}}export{s as useInternalRegionSelector};
2
2
  //# sourceMappingURL=useInternalRegionSelector.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInternalRegionSelector.mjs","names":[],"sources":["../../src/hooks/useInternalRegionSelector.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useCustomMapping, useLocales } from './i18n-config';\nimport { useLocale, useRegion } from './condition-store';\nimport { getLocaleProperties } from 'generaltranslation';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\nexport type RegionData = {\n code: string;\n name: string;\n emoji: string;\n locale: string;\n};\n\nexport type InternalRegionSelectorOptions = {\n regions?: string[];\n customMapping?: {\n [region: string]:\n | string\n | { name?: string; emoji?: string; locale?: string };\n };\n prioritizeCurrentLocaleRegion?: boolean;\n sortRegionsAlphabetically?: boolean;\n};\n\nexport type InternalRegionSelectorResult = {\n region: string | undefined;\n regions: string[];\n regionData: Map<string, RegionData>;\n locale: string;\n localeRegion: string;\n};\n\n/**\n * Internal logic for region selection in applications supporting multiple regions.\n *\n * Returns the current region, an ordered list of available regions (inferred\n * from the supported locales when not provided), and a map of region codes to\n * their display data (name, emoji, associated locale).\n */\nexport function useInternalRegionSelector({\n regions: _regions,\n customMapping,\n prioritizeCurrentLocaleRegion = true,\n sortRegionsAlphabetically = true,\n}: InternalRegionSelectorOptions = {}): InternalRegionSelectorResult {\n // Retrieve the locale, locales, and region\n const contextLocales = useLocales();\n const localeCustomMapping = useCustomMapping();\n const locale = useLocale();\n const region = useRegion();\n const { regionCode: localeRegion } = getLocaleProperties(\n locale,\n locale,\n localeCustomMapping\n );\n\n const [\n regions, // ordered list of ISO 3166 region codes\n regionData, // map of ISO 3166 region codes to region display data, potentially not ordered\n ] = useMemo<[string[], Map<string, RegionData>]>(() => {\n const gt = getI18nConfig().getGTClass(locale);\n const regionToLocaleMap = new Map(\n contextLocales.map((l) => {\n const lp = getLocaleProperties(l, locale, localeCustomMapping); // has to be directly called so sourceLocale can be in the user's current locale\n return [lp.regionCode, lp];\n })\n );\n\n const regions = _regions\n ? [..._regions]\n : Array.from(regionToLocaleMap?.keys() || [localeRegion]);\n\n const regionData = new Map<string, RegionData>(\n regions.map((r: string) => {\n return [\n r,\n {\n locale: regionToLocaleMap?.get(r)?.code || locale,\n ...gt.getRegionProperties(r),\n ...(typeof customMapping?.[r] === 'string'\n ? { name: customMapping?.[r] }\n : customMapping?.[r]),\n },\n ];\n })\n );\n\n if (sortRegionsAlphabetically) {\n regions.sort((a, b) =>\n new Intl.Collator().compare(\n regionData.get(a)!.name,\n regionData.get(b)!.name\n )\n );\n }\n\n if (prioritizeCurrentLocaleRegion) {\n const localeRegionIndex = regions.indexOf(localeRegion);\n if (localeRegionIndex > 0) {\n // 0 because no action is needed if it's already at the start\n regions.splice(localeRegionIndex, 1);\n regions.unshift(localeRegion);\n }\n }\n\n return [regions, regionData];\n }, [\n _regions,\n customMapping,\n locale,\n localeRegion,\n contextLocales,\n localeCustomMapping,\n prioritizeCurrentLocaleRegion,\n sortRegionsAlphabetically,\n ]);\n\n return {\n region,\n regions,\n regionData,\n locale,\n localeRegion,\n };\n}\n"],"mappings":"gRAuCA,SAAgB,EAA0B,CACxC,QAAS,EACT,gBACA,gCAAgC,GAChC,4BAA4B,IACK,EAAE,CAAgC,CAEnE,IAAM,EAAiB,GAAY,CAC7B,EAAsB,GAAkB,CACxC,EAAS,GAAW,CACpB,EAAS,GAAW,CACpB,CAAE,WAAY,GAAiB,EACnC,EACA,EACA,EACD,CAEK,CACJ,EACA,GACE,MAAmD,CACrD,IAAM,EAAK,GAAe,CAAC,WAAW,EAAO,CACvC,EAAoB,IAAI,IAC5B,EAAe,IAAK,GAAM,CACxB,IAAM,EAAK,EAAoB,EAAG,EAAQ,EAAoB,CAC9D,MAAO,CAAC,EAAG,WAAY,EAAG,EAC1B,CACH,CAEK,EAAU,EACZ,CAAC,GAAG,EAAS,CACb,MAAM,KAAK,GAAmB,MAAM,EAAI,CAAC,EAAa,CAAC,CAErD,EAAa,IAAI,IACrB,EAAQ,IAAK,GACJ,CACL,EACA,CACE,OAAQ,GAAmB,IAAI,EAAE,EAAE,MAAQ,EAC3C,GAAG,EAAG,oBAAoB,EAAE,CAC5B,GAAI,OAAO,IAAgB,IAAO,SAC9B,CAAE,KAAM,IAAgB,GAAI,CAC5B,IAAgB,GACrB,CACF,CACD,CACH,CAWD,GATI,GACF,EAAQ,MAAM,EAAG,IACf,IAAI,KAAK,UAAU,CAAC,QAClB,EAAW,IAAI,EAAE,CAAE,KACnB,EAAW,IAAI,EAAE,CAAE,KACpB,CACF,CAGC,EAA+B,CACjC,IAAM,EAAoB,EAAQ,QAAQ,EAAa,CACnD,EAAoB,IAEtB,EAAQ,OAAO,EAAmB,EAAE,CACpC,EAAQ,QAAQ,EAAa,EAIjC,MAAO,CAAC,EAAS,EAAW,EAC3B,CACD,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CAAC,CAEF,MAAO,CACL,SACA,UACA,aACA,SACA,eACD"}
1
+ {"version":3,"file":"useInternalRegionSelector.mjs","names":[],"sources":["../../src/hooks/useInternalRegionSelector.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { useCustomMapping, useLocales } from './i18n-config';\nimport { useLocale, useRegion } from './condition-store';\nimport { getLocaleProperties } from '@generaltranslation/format';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\nexport type RegionData = {\n code: string;\n name: string;\n emoji: string;\n locale: string;\n};\n\nexport type InternalRegionSelectorOptions = {\n regions?: string[];\n customMapping?: {\n [region: string]:\n | string\n | { name?: string; emoji?: string; locale?: string };\n };\n prioritizeCurrentLocaleRegion?: boolean;\n sortRegionsAlphabetically?: boolean;\n};\n\nexport type InternalRegionSelectorResult = {\n region: string | undefined;\n regions: string[];\n regionData: Map<string, RegionData>;\n locale: string;\n localeRegion: string;\n};\n\n/**\n * Internal logic for region selection in applications supporting multiple regions.\n *\n * Returns the current region, an ordered list of available regions (inferred\n * from the supported locales when not provided), and a map of region codes to\n * their display data (name, emoji, associated locale).\n */\nexport function useInternalRegionSelector({\n regions: _regions,\n customMapping,\n prioritizeCurrentLocaleRegion = true,\n sortRegionsAlphabetically = true,\n}: InternalRegionSelectorOptions = {}): InternalRegionSelectorResult {\n // Retrieve the locale, locales, and region\n const contextLocales = useLocales();\n const localeCustomMapping = useCustomMapping();\n const locale = useLocale();\n const region = useRegion();\n const { regionCode: localeRegion } = getLocaleProperties(\n locale,\n locale,\n localeCustomMapping\n );\n\n const [\n regions, // ordered list of ISO 3166 region codes\n regionData, // map of ISO 3166 region codes to region display data, potentially not ordered\n ] = useMemo<[string[], Map<string, RegionData>]>(() => {\n const gt = getI18nConfig().getGTClass(locale);\n const regionToLocaleMap = new Map(\n contextLocales.map((l) => {\n const lp = getLocaleProperties(l, locale, localeCustomMapping); // has to be directly called so sourceLocale can be in the user's current locale\n return [lp.regionCode, lp];\n })\n );\n\n const regions = _regions\n ? [..._regions]\n : Array.from(regionToLocaleMap?.keys() || [localeRegion]);\n\n const regionData = new Map<string, RegionData>(\n regions.map((r: string) => {\n return [\n r,\n {\n locale: regionToLocaleMap?.get(r)?.code || locale,\n ...gt.getRegionProperties(r),\n ...(typeof customMapping?.[r] === 'string'\n ? { name: customMapping?.[r] }\n : customMapping?.[r]),\n },\n ];\n })\n );\n\n if (sortRegionsAlphabetically) {\n regions.sort((a, b) =>\n new Intl.Collator().compare(\n regionData.get(a)!.name,\n regionData.get(b)!.name\n )\n );\n }\n\n if (prioritizeCurrentLocaleRegion) {\n const localeRegionIndex = regions.indexOf(localeRegion);\n if (localeRegionIndex > 0) {\n // 0 because no action is needed if it's already at the start\n regions.splice(localeRegionIndex, 1);\n regions.unshift(localeRegion);\n }\n }\n\n return [regions, regionData];\n }, [\n _regions,\n customMapping,\n locale,\n localeRegion,\n contextLocales,\n localeCustomMapping,\n prioritizeCurrentLocaleRegion,\n sortRegionsAlphabetically,\n ]);\n\n return {\n region,\n regions,\n regionData,\n locale,\n localeRegion,\n };\n}\n"],"mappings":"wRAuCA,SAAgB,EAA0B,CACxC,QAAS,EACT,gBACA,gCAAgC,GAChC,4BAA4B,IACK,EAAE,CAAgC,CAEnE,IAAM,EAAiB,GAAY,CAC7B,EAAsB,GAAkB,CACxC,EAAS,GAAW,CACpB,EAAS,GAAW,CACpB,CAAE,WAAY,GAAiB,EACnC,EACA,EACA,EACD,CAEK,CACJ,EACA,GACE,MAAmD,CACrD,IAAM,EAAK,GAAe,CAAC,WAAW,EAAO,CACvC,EAAoB,IAAI,IAC5B,EAAe,IAAK,GAAM,CACxB,IAAM,EAAK,EAAoB,EAAG,EAAQ,EAAoB,CAC9D,MAAO,CAAC,EAAG,WAAY,EAAG,EAC1B,CACH,CAEK,EAAU,EACZ,CAAC,GAAG,EAAS,CACb,MAAM,KAAK,GAAmB,MAAM,EAAI,CAAC,EAAa,CAAC,CAErD,EAAa,IAAI,IACrB,EAAQ,IAAK,GACJ,CACL,EACA,CACE,OAAQ,GAAmB,IAAI,EAAE,EAAE,MAAQ,EAC3C,GAAG,EAAG,oBAAoB,EAAE,CAC5B,GAAI,OAAO,IAAgB,IAAO,SAC9B,CAAE,KAAM,IAAgB,GAAI,CAC5B,IAAgB,GACrB,CACF,CACD,CACH,CAWD,GATI,GACF,EAAQ,MAAM,EAAG,IACf,IAAI,KAAK,UAAU,CAAC,QAClB,EAAW,IAAI,EAAE,CAAE,KACnB,EAAW,IAAI,EAAE,CAAE,KACpB,CACF,CAGC,EAA+B,CACjC,IAAM,EAAoB,EAAQ,QAAQ,EAAa,CACnD,EAAoB,IAEtB,EAAQ,OAAO,EAAmB,EAAE,CACpC,EAAQ,QAAQ,EAAa,EAIjC,MAAO,CAAC,EAAS,EAAW,EAC3B,CACD,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CAAC,CAEF,MAAO,CACL,SACA,UACA,aACA,SACA,eACD"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../condition-store/singleton-operations.cjs`);let t=require(`gt-i18n/internal`);function n(){let n=e.getReadonlyConditionStoreWithFallback(),r=(0,t.getI18nConfig)(),i=n.getEnableI18n(),a=n.getLocale();return i&&r.requiresTranslation(a)}exports.getShouldTranslate=n;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../condition-store/singleton-operations.cjs`);let t=require(`gt-i18n/internal`);function n(){let n=e.getConditionStore(),r=(0,t.getI18nConfig)(),i=n.getEnableI18n(),a=n.getLocale();return i&&r.requiresTranslation(a)}exports.getShouldTranslate=n;
2
2
  //# sourceMappingURL=getShouldTranslate.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getShouldTranslate.cjs","names":["getReadonlyConditionStoreWithFallback"],"sources":["../../../src/hooks/utils/getShouldTranslate.ts"],"sourcesContent":["import { getReadonlyConditionStoreWithFallback } from '../../condition-store/singleton-operations';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\n// Pure helper shared by hook-based and RSC code paths. This module must stay\n// free of hook/context imports so it can be reached from the components-rsc\n// entrypoint.\n\n/**\n * Returns true if (1) i18n enabled and (2) translation is required\n */\nexport function getShouldTranslate(): boolean {\n const conditionStore = getReadonlyConditionStoreWithFallback();\n const i18nConfig = getI18nConfig();\n\n const enableI18n = conditionStore.getEnableI18n();\n const locale = conditionStore.getLocale();\n return enableI18n && i18nConfig.requiresTranslation(locale);\n}\n"],"mappings":"oJAUA,SAAgB,GAA8B,CAC5C,IAAM,EAAiBA,EAAAA,uCAAuC,CACxD,GAAA,EAAA,EAAA,gBAA4B,CAE5B,EAAa,EAAe,eAAe,CAC3C,EAAS,EAAe,WAAW,CACzC,OAAO,GAAc,EAAW,oBAAoB,EAAO"}
1
+ {"version":3,"file":"getShouldTranslate.cjs","names":["getReadonlyConditionStore"],"sources":["../../../src/hooks/utils/getShouldTranslate.ts"],"sourcesContent":["import { getReadonlyConditionStore } from '../../condition-store/singleton-operations';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\n// Pure helper shared by hook-based and RSC code paths. This module must stay\n// free of hook/context imports so it can be reached from the components-rsc\n// entrypoint.\n\n/**\n * Returns true if (1) i18n enabled and (2) translation is required\n */\nexport function getShouldTranslate(): boolean {\n const conditionStore = getReadonlyConditionStore();\n const i18nConfig = getI18nConfig();\n\n const enableI18n = conditionStore.getEnableI18n();\n const locale = conditionStore.getLocale();\n return enableI18n && i18nConfig.requiresTranslation(locale);\n}\n"],"mappings":"oJAUA,SAAgB,GAA8B,CAC5C,IAAM,EAAiBA,EAAAA,mBAA2B,CAC5C,GAAA,EAAA,EAAA,gBAA4B,CAE5B,EAAa,EAAe,eAAe,CAC3C,EAAS,EAAe,WAAW,CACzC,OAAO,GAAc,EAAW,oBAAoB,EAAO"}
@@ -1,2 +1,2 @@
1
- import{getReadonlyConditionStoreWithFallback as e}from"../../condition-store/singleton-operations.mjs";import{getI18nConfig as t}from"gt-i18n/internal";function n(){let n=e(),r=t(),i=n.getEnableI18n(),a=n.getLocale();return i&&r.requiresTranslation(a)}export{n as getShouldTranslate};
1
+ import{getConditionStore as e}from"../../condition-store/singleton-operations.mjs";import{getI18nConfig as t}from"gt-i18n/internal";function n(){let n=e(),r=t(),i=n.getEnableI18n(),a=n.getLocale();return i&&r.requiresTranslation(a)}export{n as getShouldTranslate};
2
2
  //# sourceMappingURL=getShouldTranslate.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getShouldTranslate.mjs","names":[],"sources":["../../../src/hooks/utils/getShouldTranslate.ts"],"sourcesContent":["import { getReadonlyConditionStoreWithFallback } from '../../condition-store/singleton-operations';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\n// Pure helper shared by hook-based and RSC code paths. This module must stay\n// free of hook/context imports so it can be reached from the components-rsc\n// entrypoint.\n\n/**\n * Returns true if (1) i18n enabled and (2) translation is required\n */\nexport function getShouldTranslate(): boolean {\n const conditionStore = getReadonlyConditionStoreWithFallback();\n const i18nConfig = getI18nConfig();\n\n const enableI18n = conditionStore.getEnableI18n();\n const locale = conditionStore.getLocale();\n return enableI18n && i18nConfig.requiresTranslation(locale);\n}\n"],"mappings":"wJAUA,SAAgB,GAA8B,CAC5C,IAAM,EAAiB,GAAuC,CACxD,EAAa,GAAe,CAE5B,EAAa,EAAe,eAAe,CAC3C,EAAS,EAAe,WAAW,CACzC,OAAO,GAAc,EAAW,oBAAoB,EAAO"}
1
+ {"version":3,"file":"getShouldTranslate.mjs","names":["getReadonlyConditionStore"],"sources":["../../../src/hooks/utils/getShouldTranslate.ts"],"sourcesContent":["import { getReadonlyConditionStore } from '../../condition-store/singleton-operations';\nimport { getI18nConfig } from 'gt-i18n/internal';\n\n// Pure helper shared by hook-based and RSC code paths. This module must stay\n// free of hook/context imports so it can be reached from the components-rsc\n// entrypoint.\n\n/**\n * Returns true if (1) i18n enabled and (2) translation is required\n */\nexport function getShouldTranslate(): boolean {\n const conditionStore = getReadonlyConditionStore();\n const i18nConfig = getI18nConfig();\n\n const enableI18n = conditionStore.getEnableI18n();\n const locale = conditionStore.getLocale();\n return enableI18n && i18nConfig.requiresTranslation(locale);\n}\n"],"mappings":"oIAUA,SAAgB,GAA8B,CAC5C,IAAM,EAAiBA,GAA2B,CAC5C,EAAa,GAAe,CAE5B,EAAa,EAAe,eAAe,CAC3C,EAAS,EAAe,WAAW,CACzC,OAAO,GAAc,EAAW,oBAAoB,EAAO"}
@@ -1,11 +1,11 @@
1
1
  import { getFormatLocales } from "./utils/getFormatLocales.js";
2
2
  import { LocaleProperties } from "@generaltranslation/format/types";
3
- import * as _$generaltranslation from "generaltranslation";
3
+ import * as _$generaltranslation_runtime0 from "generaltranslation/runtime";
4
4
 
5
5
  //#region src/hooks/utils.d.ts
6
6
  declare function useFormatLocales(localesProp?: string[]): string[];
7
7
  declare function useShouldTranslate(): boolean;
8
- declare function useGTClass(): _$generaltranslation.GT;
8
+ declare function useGTClass(): _$generaltranslation_runtime0.GTRuntime;
9
9
  declare function useLocaleProperties(locale: string): LocaleProperties;
10
10
  declare function useLocaleDirection(locale?: string): 'ltr' | 'rtl';
11
11
  declare function useVersionId(): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/hooks/utils.ts"],"mappings":";;;;;iBAUgB,gBAAA,CACd,WAAA;AAAA,iBAec,kBAAA,CAAA;AAAA,iBAMA,UAAA,CAAA,GAAU,oBAAA,CAAA,EAAA;AAAA,iBAIV,mBAAA,CAAoB,MAAA,WAAiB,gBAAA;AAAA,iBAOrC,kBAAA,CAAmB,MAAA;AAAA,iBASnB,YAAA,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/hooks/utils.ts"],"mappings":";;;;;iBAUgB,gBAAA,CACd,WAAA;AAAA,iBAec,kBAAA,CAAA;AAAA,iBAMA,UAAA,CAAA,GAAU,6BAAA,CAAA,SAAA;AAAA,iBAIV,mBAAA,CAAoB,MAAA,WAAiB,gBAAA;AAAA,iBAOrC,kBAAA,CAAmB,MAAA;AAAA,iBASnB,YAAA,CAAA"}
package/dist/pure.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./utils/plurals/getPluralBranch.cjs`),t=require(`./utils/internal/addGTIdentifier.cjs`),n=require(`./utils/variables/getVariableName.cjs`),r=require(`./utils/internal/writeChildrenAsObjects.cjs`),i=require(`./utils/dictionaries/flattenDictionary.cjs`),a=require(`./utils/variables/_getVariableProps.cjs`),o=require(`./hooks/utils/getFormatLocales.cjs`),s=require(`./i18n-cache/singleton-operations.cjs`),c=require(`./functions/helpers/getTranslationsSnapshot.cjs`),l=require(`./setup/i18nConfig.cjs`),u=require(`./condition-store/singleton-operations.cjs`),d=require(`./functions/translation/t.cjs`),f=require(`./utils/rendering/createRenderPipeline.cjs`),p=require(`./utils/dictionaries/getDictionaryEntry.cjs`),m=require(`./utils/dictionaries/getEntryAndMetadata.cjs`),h=require(`./utils/dictionaries/isDictionaryEntry.cjs`),g=require(`./utils/dictionaries/mergeDictionaries.cjs`),_=require(`./utils/rendering/getDefaultRenderSettings.cjs`),v=require(`./i18n-cache/ReactI18nCache.cjs`),y=require(`./setup/initializeGTSRA.cjs`),b=require(`./i18n-store/singleton-operations.cjs`),x=require(`./i18n-store/I18nStore.cjs`);let S=require(`gt-i18n`),C=require(`gt-i18n/internal`);exports.I18nStore=x.I18nStore,exports.ReactI18nCache=v.ReactI18nCache,exports.ReactI18nConfig=l.ReactI18nConfig,Object.defineProperty(exports,`ReadonlyConditionStore`,{enumerable:!0,get:function(){return C.ReadonlyConditionStore}}),Object.defineProperty(exports,`WritableConditionStore`,{enumerable:!0,get:function(){return C.WritableConditionStore}}),exports.addGTIdentifier=t.addGTIdentifier,exports.createRenderPipeline=f.createRenderPipeline,Object.defineProperty(exports,`declareVar`,{enumerable:!0,get:function(){return S.declareVar}}),Object.defineProperty(exports,`decodeMsg`,{enumerable:!0,get:function(){return S.decodeMsg}}),Object.defineProperty(exports,`decodeOptions`,{enumerable:!0,get:function(){return S.decodeOptions}}),Object.defineProperty(exports,`decodeVars`,{enumerable:!0,get:function(){return S.decodeVars}}),exports.defaultEnableI18nCookieName=l.defaultEnableI18nCookieName,exports.defaultLocaleCookieName=l.defaultLocaleCookieName,exports.defaultRegionCookieName=l.defaultRegionCookieName,exports.defaultResetLocaleCookieName=l.defaultResetLocaleCookieName,Object.defineProperty(exports,`derive`,{enumerable:!0,get:function(){return S.derive}}),exports.flattenDictionary=i.flattenDictionary,Object.defineProperty(exports,`getDefaultLocale`,{enumerable:!0,get:function(){return S.getDefaultLocale}}),exports.getDefaultRenderSettings=_.getDefaultRenderSettings,exports.getDictionaryEntry=p.getDictionaryEntry,exports.getEntryAndMetadata=m.getEntryAndMetadata,exports.getFormatLocales=o.getFormatLocales,Object.defineProperty(exports,`getGTClass`,{enumerable:!0,get:function(){return S.getGTClass}}),exports.getI18nConfig=l.getI18nConfig,exports.getI18nStore=b.getI18nStore,Object.defineProperty(exports,`getLocaleProperties`,{enumerable:!0,get:function(){return S.getLocaleProperties}}),Object.defineProperty(exports,`getLocales`,{enumerable:!0,get:function(){return S.getLocales}}),exports.getPluralBranch=e.getPluralBranch,exports.getReactI18nCache=s.getReactI18nCache,exports.getReadonlyConditionStoreWithFallback=u.getReadonlyConditionStoreWithFallback,exports.getTranslationsSnapshot=c.getTranslationsSnapshot,exports.getVariableName=n.getVariableName,exports.getVariableProps=a.getVariableProps,Object.defineProperty(exports,`getVersionId`,{enumerable:!0,get:function(){return S.getVersionId}}),Object.defineProperty(exports,`gtFallback`,{enumerable:!0,get:function(){return S.gtFallback}}),exports.initializeGT=y.internalInitializeGTSRA,exports.initializeI18nConfig=l.initializeI18nConfig,exports.internalInitializeGTSRA=y.internalInitializeGTSRA,exports.isDictionaryEntry=h.isDictionaryEntry,exports.isI18nStoreInitialized=b.isI18nStoreInitialized,exports.isValidDictionaryEntry=p.isValidDictionaryEntry,Object.defineProperty(exports,`mFallback`,{enumerable:!0,get:function(){return S.mFallback}}),exports.mergeDictionaries=g.mergeDictionaries,Object.defineProperty(exports,`msg`,{enumerable:!0,get:function(){return S.msg}}),exports.setI18nConfig=l.setI18nConfig,exports.setI18nStore=b.setI18nStore,exports.setReactI18nCache=s.setReactI18nCache,exports.setReadonlyConditionStore=u.setConditionStore,exports.t=d.t,exports.writeChildrenAsObjects=r.writeChildrenAsObjects;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./utils/plurals/getPluralBranch.cjs`),t=require(`./utils/internal/addGTIdentifier.cjs`),n=require(`./utils/variables/getVariableName.cjs`),r=require(`./utils/internal/writeChildrenAsObjects.cjs`),i=require(`./utils/dictionaries/flattenDictionary.cjs`),a=require(`./utils/variables/_getVariableProps.cjs`),o=require(`./hooks/utils/getFormatLocales.cjs`),s=require(`./i18n-cache/singleton-operations.cjs`),c=require(`./functions/helpers/getTranslationsSnapshot.cjs`),l=require(`./setup/i18nConfig.cjs`),u=require(`./condition-store/singleton-operations.cjs`),d=require(`./functions/translation/t.cjs`),f=require(`./utils/rendering/createRenderPipeline.cjs`),p=require(`./utils/dictionaries/getDictionaryEntry.cjs`),m=require(`./utils/dictionaries/getEntryAndMetadata.cjs`),h=require(`./utils/dictionaries/isDictionaryEntry.cjs`),g=require(`./utils/dictionaries/mergeDictionaries.cjs`),_=require(`./utils/rendering/getDefaultRenderSettings.cjs`),v=require(`./i18n-cache/ReactI18nCache.cjs`),y=require(`./setup/initializeGTSRA.cjs`),b=require(`./i18n-store/singleton-operations.cjs`),x=require(`./i18n-store/I18nStore.cjs`);let S=require(`gt-i18n`),C=require(`gt-i18n/internal`);exports.I18nStore=x.I18nStore,exports.ReactI18nCache=v.ReactI18nCache,exports.ReactI18nConfig=l.ReactI18nConfig,Object.defineProperty(exports,`ReadonlyConditionStore`,{enumerable:!0,get:function(){return C.ReadonlyConditionStore}}),Object.defineProperty(exports,`WritableConditionStore`,{enumerable:!0,get:function(){return C.WritableConditionStore}}),exports.addGTIdentifier=t.addGTIdentifier,exports.createRenderPipeline=f.createRenderPipeline,Object.defineProperty(exports,`declareVar`,{enumerable:!0,get:function(){return S.declareVar}}),Object.defineProperty(exports,`decodeMsg`,{enumerable:!0,get:function(){return S.decodeMsg}}),Object.defineProperty(exports,`decodeOptions`,{enumerable:!0,get:function(){return S.decodeOptions}}),Object.defineProperty(exports,`decodeVars`,{enumerable:!0,get:function(){return S.decodeVars}}),exports.defaultEnableI18nCookieName=l.defaultEnableI18nCookieName,exports.defaultLocaleCookieName=l.defaultLocaleCookieName,exports.defaultRegionCookieName=l.defaultRegionCookieName,exports.defaultResetLocaleCookieName=l.defaultResetLocaleCookieName,Object.defineProperty(exports,`derive`,{enumerable:!0,get:function(){return S.derive}}),exports.flattenDictionary=i.flattenDictionary,Object.defineProperty(exports,`getDefaultLocale`,{enumerable:!0,get:function(){return S.getDefaultLocale}}),exports.getDefaultRenderSettings=_.getDefaultRenderSettings,exports.getDictionaryEntry=p.getDictionaryEntry,exports.getEntryAndMetadata=m.getEntryAndMetadata,exports.getFormatLocales=o.getFormatLocales,Object.defineProperty(exports,`getGTClass`,{enumerable:!0,get:function(){return S.getGTClass}}),exports.getI18nConfig=l.getI18nConfig,exports.getI18nStore=b.getI18nStore,Object.defineProperty(exports,`getLocaleProperties`,{enumerable:!0,get:function(){return S.getLocaleProperties}}),Object.defineProperty(exports,`getLocales`,{enumerable:!0,get:function(){return S.getLocales}}),exports.getPluralBranch=e.getPluralBranch,exports.getReactI18nCache=s.getReactI18nCache,exports.getReadonlyConditionStore=u.getConditionStore,exports.getTranslationsSnapshot=c.getTranslationsSnapshot,exports.getVariableName=n.getVariableName,exports.getVariableProps=a.getVariableProps,Object.defineProperty(exports,`getVersionId`,{enumerable:!0,get:function(){return S.getVersionId}}),Object.defineProperty(exports,`gtFallback`,{enumerable:!0,get:function(){return S.gtFallback}}),exports.initializeGT=y.internalInitializeGTSRA,exports.initializeI18nConfig=l.initializeI18nConfig,exports.internalInitializeGTSRA=y.internalInitializeGTSRA,exports.isDictionaryEntry=h.isDictionaryEntry,exports.isI18nStoreInitialized=b.isI18nStoreInitialized,exports.isValidDictionaryEntry=p.isValidDictionaryEntry,Object.defineProperty(exports,`mFallback`,{enumerable:!0,get:function(){return S.mFallback}}),exports.mergeDictionaries=g.mergeDictionaries,Object.defineProperty(exports,`msg`,{enumerable:!0,get:function(){return S.msg}}),exports.setI18nConfig=l.setI18nConfig,exports.setI18nStore=b.setI18nStore,exports.setReactI18nCache=s.setReactI18nCache,exports.setReadonlyConditionStore=u.setConditionStore,exports.t=d.t,exports.writeChildrenAsObjects=r.writeChildrenAsObjects;
package/dist/pure.d.ts CHANGED
@@ -22,9 +22,9 @@ import { internalInitializeGTSRA } from "./setup/initializeGTSRA.js";
22
22
  import { DictionaryLookup, TranslateLookup } from "./i18n-store/storeTypes.js";
23
23
  import { I18nStore } from "./i18n-store/I18nStore.js";
24
24
  import { getI18nStore, isI18nStoreInitialized, setI18nStore } from "./i18n-store/singleton-operations.js";
25
- import { getReadonlyConditionStoreWithFallback, setConditionStore } from "./condition-store/singleton-operations.js";
25
+ import { getConditionStore, setConditionStore } from "./condition-store/singleton-operations.js";
26
26
  import { OnMissingDictionaryEntry, OnMissingDictionaryObj, OnMissingTranslation } from "./hooks/utils/missing-translation.js";
27
27
  import { WritableConditionStoreParams } from "gt-i18n/internal/types";
28
28
  import { declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLocale, getGTClass, getLocaleProperties, getLocales, getVersionId, gtFallback, mFallback, msg } from "gt-i18n";
29
29
  import { ReadonlyConditionStore, WritableConditionStore } from "gt-i18n/internal";
30
- export { type CustomLoader, type Dictionary, type DictionaryContent, type DictionaryEntry, type DictionaryLookup, type DictionaryObject, type Entry, type FlattenedDictionary, type GTFunctionType, type GTProp, type GTTranslationOptions, type ReactI18nConfigParams as I18nConfigParams, I18nStore, type LocalesDictionary, type MFunctionType, type Metadata, type OnMissingDictionaryEntry, type OnMissingDictionaryObj, type OnMissingTranslation, ReactI18nCache, type ReactI18nCacheParams, ReactI18nConfig, ReadonlyConditionStore, type RelativeTimeFormatOptions, type RenderMethod, type RenderPipeline, type RenderPreparedT, type RenderVariable, type RuntimeTranslationOptions, type TranslateLookup, type TranslatedChildren, type Translations, type VariableProps, WritableConditionStore, type WritableConditionStoreParams, type _Message, type _Messages, addGTIdentifier, createRenderPipeline, declareVar, decodeMsg, decodeOptions, decodeVars, defaultEnableI18nCookieName, defaultLocaleCookieName, defaultRegionCookieName, defaultResetLocaleCookieName, derive, flattenDictionary, getDefaultLocale, getDefaultRenderSettings, getDictionaryEntry, getEntryAndMetadata, getFormatLocales, getGTClass, getI18nConfig, getI18nStore, getLocaleProperties, getLocales, getPluralBranch, getReactI18nCache, getReadonlyConditionStoreWithFallback, getTranslationsSnapshot, getVariableName, getVariableProps, getVersionId, gtFallback, internalInitializeGTSRA as initializeGT, initializeI18nConfig, internalInitializeGTSRA, isDictionaryEntry, isI18nStoreInitialized, isValidDictionaryEntry, mFallback, mergeDictionaries, msg, setI18nConfig, setI18nStore, setReactI18nCache, setConditionStore as setReadonlyConditionStore, t, writeChildrenAsObjects };
30
+ export { type CustomLoader, type Dictionary, type DictionaryContent, type DictionaryEntry, type DictionaryLookup, type DictionaryObject, type Entry, type FlattenedDictionary, type GTFunctionType, type GTProp, type GTTranslationOptions, type ReactI18nConfigParams as I18nConfigParams, I18nStore, type LocalesDictionary, type MFunctionType, type Metadata, type OnMissingDictionaryEntry, type OnMissingDictionaryObj, type OnMissingTranslation, ReactI18nCache, type ReactI18nCacheParams, ReactI18nConfig, ReadonlyConditionStore, type RelativeTimeFormatOptions, type RenderMethod, type RenderPipeline, type RenderPreparedT, type RenderVariable, type RuntimeTranslationOptions, type TranslateLookup, type TranslatedChildren, type Translations, type VariableProps, WritableConditionStore, type WritableConditionStoreParams, type _Message, type _Messages, addGTIdentifier, createRenderPipeline, declareVar, decodeMsg, decodeOptions, decodeVars, defaultEnableI18nCookieName, defaultLocaleCookieName, defaultRegionCookieName, defaultResetLocaleCookieName, derive, flattenDictionary, getDefaultLocale, getDefaultRenderSettings, getDictionaryEntry, getEntryAndMetadata, getFormatLocales, getGTClass, getI18nConfig, getI18nStore, getLocaleProperties, getLocales, getPluralBranch, getReactI18nCache, getConditionStore as getReadonlyConditionStore, getTranslationsSnapshot, getVariableName, getVariableProps, getVersionId, gtFallback, internalInitializeGTSRA as initializeGT, initializeI18nConfig, internalInitializeGTSRA, isDictionaryEntry, isI18nStoreInitialized, isValidDictionaryEntry, mFallback, mergeDictionaries, msg, setI18nConfig, setI18nStore, setReactI18nCache, setConditionStore as setReadonlyConditionStore, t, writeChildrenAsObjects };
package/dist/pure.mjs CHANGED
@@ -1 +1 @@
1
- import{getPluralBranch as e}from"./utils/plurals/getPluralBranch.mjs";import{addGTIdentifier as t}from"./utils/internal/addGTIdentifier.mjs";import{getVariableName as n}from"./utils/variables/getVariableName.mjs";import{writeChildrenAsObjects as r}from"./utils/internal/writeChildrenAsObjects.mjs";import{flattenDictionary as i}from"./utils/dictionaries/flattenDictionary.mjs";import{getVariableProps as a}from"./utils/variables/_getVariableProps.mjs";import{getFormatLocales as o}from"./hooks/utils/getFormatLocales.mjs";import{getReactI18nCache as s,setReactI18nCache as c}from"./i18n-cache/singleton-operations.mjs";import{getTranslationsSnapshot as l}from"./functions/helpers/getTranslationsSnapshot.mjs";import{ReactI18nConfig as u,defaultEnableI18nCookieName as d,defaultLocaleCookieName as f,defaultRegionCookieName as p,defaultResetLocaleCookieName as m,getI18nConfig as h,initializeI18nConfig as g,setI18nConfig as _}from"./setup/i18nConfig.mjs";import{getReadonlyConditionStoreWithFallback as v,setConditionStore as y}from"./condition-store/singleton-operations.mjs";import{t as b}from"./functions/translation/t.mjs";import{createRenderPipeline as x}from"./utils/rendering/createRenderPipeline.mjs";import{getDictionaryEntry as S,isValidDictionaryEntry as C}from"./utils/dictionaries/getDictionaryEntry.mjs";import{getEntryAndMetadata as w}from"./utils/dictionaries/getEntryAndMetadata.mjs";import{isDictionaryEntry as T}from"./utils/dictionaries/isDictionaryEntry.mjs";import{mergeDictionaries as E}from"./utils/dictionaries/mergeDictionaries.mjs";import{getDefaultRenderSettings as D}from"./utils/rendering/getDefaultRenderSettings.mjs";import{ReactI18nCache as O}from"./i18n-cache/ReactI18nCache.mjs";import{internalInitializeGTSRA as k}from"./setup/initializeGTSRA.mjs";import{getI18nStore as A,isI18nStoreInitialized as j,setI18nStore as M}from"./i18n-store/singleton-operations.mjs";import{I18nStore as N}from"./i18n-store/I18nStore.mjs";import{declareVar as P,decodeMsg as F,decodeOptions as I,decodeVars as L,derive as R,getDefaultLocale as z,getGTClass as B,getLocaleProperties as V,getLocales as H,getVersionId as U,gtFallback as W,mFallback as G,msg as K}from"gt-i18n";import{ReadonlyConditionStore as q,WritableConditionStore as J}from"gt-i18n/internal";export{N as I18nStore,O as ReactI18nCache,u as ReactI18nConfig,q as ReadonlyConditionStore,J as WritableConditionStore,t as addGTIdentifier,x as createRenderPipeline,P as declareVar,F as decodeMsg,I as decodeOptions,L as decodeVars,d as defaultEnableI18nCookieName,f as defaultLocaleCookieName,p as defaultRegionCookieName,m as defaultResetLocaleCookieName,R as derive,i as flattenDictionary,z as getDefaultLocale,D as getDefaultRenderSettings,S as getDictionaryEntry,w as getEntryAndMetadata,o as getFormatLocales,B as getGTClass,h as getI18nConfig,A as getI18nStore,V as getLocaleProperties,H as getLocales,e as getPluralBranch,s as getReactI18nCache,v as getReadonlyConditionStoreWithFallback,l as getTranslationsSnapshot,n as getVariableName,a as getVariableProps,U as getVersionId,W as gtFallback,k as initializeGT,g as initializeI18nConfig,k as internalInitializeGTSRA,T as isDictionaryEntry,j as isI18nStoreInitialized,C as isValidDictionaryEntry,G as mFallback,E as mergeDictionaries,K as msg,_ as setI18nConfig,M as setI18nStore,c as setReactI18nCache,y as setReadonlyConditionStore,b as t,r as writeChildrenAsObjects};
1
+ import{getPluralBranch as e}from"./utils/plurals/getPluralBranch.mjs";import{addGTIdentifier as t}from"./utils/internal/addGTIdentifier.mjs";import{getVariableName as n}from"./utils/variables/getVariableName.mjs";import{writeChildrenAsObjects as r}from"./utils/internal/writeChildrenAsObjects.mjs";import{flattenDictionary as i}from"./utils/dictionaries/flattenDictionary.mjs";import{getVariableProps as a}from"./utils/variables/_getVariableProps.mjs";import{getFormatLocales as o}from"./hooks/utils/getFormatLocales.mjs";import{getReactI18nCache as s,setReactI18nCache as c}from"./i18n-cache/singleton-operations.mjs";import{getTranslationsSnapshot as l}from"./functions/helpers/getTranslationsSnapshot.mjs";import{ReactI18nConfig as u,defaultEnableI18nCookieName as d,defaultLocaleCookieName as f,defaultRegionCookieName as p,defaultResetLocaleCookieName as m,getI18nConfig as h,initializeI18nConfig as g,setI18nConfig as _}from"./setup/i18nConfig.mjs";import{getConditionStore as v,setConditionStore as y}from"./condition-store/singleton-operations.mjs";import{t as b}from"./functions/translation/t.mjs";import{createRenderPipeline as x}from"./utils/rendering/createRenderPipeline.mjs";import{getDictionaryEntry as S,isValidDictionaryEntry as C}from"./utils/dictionaries/getDictionaryEntry.mjs";import{getEntryAndMetadata as w}from"./utils/dictionaries/getEntryAndMetadata.mjs";import{isDictionaryEntry as T}from"./utils/dictionaries/isDictionaryEntry.mjs";import{mergeDictionaries as E}from"./utils/dictionaries/mergeDictionaries.mjs";import{getDefaultRenderSettings as D}from"./utils/rendering/getDefaultRenderSettings.mjs";import{ReactI18nCache as O}from"./i18n-cache/ReactI18nCache.mjs";import{internalInitializeGTSRA as k}from"./setup/initializeGTSRA.mjs";import{getI18nStore as A,isI18nStoreInitialized as j,setI18nStore as M}from"./i18n-store/singleton-operations.mjs";import{I18nStore as N}from"./i18n-store/I18nStore.mjs";import{declareVar as P,decodeMsg as F,decodeOptions as I,decodeVars as L,derive as R,getDefaultLocale as z,getGTClass as B,getLocaleProperties as V,getLocales as H,getVersionId as U,gtFallback as W,mFallback as G,msg as K}from"gt-i18n";import{ReadonlyConditionStore as q,WritableConditionStore as J}from"gt-i18n/internal";export{N as I18nStore,O as ReactI18nCache,u as ReactI18nConfig,q as ReadonlyConditionStore,J as WritableConditionStore,t as addGTIdentifier,x as createRenderPipeline,P as declareVar,F as decodeMsg,I as decodeOptions,L as decodeVars,d as defaultEnableI18nCookieName,f as defaultLocaleCookieName,p as defaultRegionCookieName,m as defaultResetLocaleCookieName,R as derive,i as flattenDictionary,z as getDefaultLocale,D as getDefaultRenderSettings,S as getDictionaryEntry,w as getEntryAndMetadata,o as getFormatLocales,B as getGTClass,h as getI18nConfig,A as getI18nStore,V as getLocaleProperties,H as getLocales,e as getPluralBranch,s as getReactI18nCache,v as getReadonlyConditionStore,l as getTranslationsSnapshot,n as getVariableName,a as getVariableProps,U as getVersionId,W as gtFallback,k as initializeGT,g as initializeI18nConfig,k as internalInitializeGTSRA,T as isDictionaryEntry,j as isI18nStoreInitialized,C as isValidDictionaryEntry,G as mFallback,E as mergeDictionaries,K as msg,_ as setI18nConfig,M as setI18nStore,c as setReactI18nCache,y as setReadonlyConditionStore,b as t,r as writeChildrenAsObjects};
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../plurals/getPluralBranch.cjs`),n=require(`../variables/_getVariableProps.cjs`),r=require(`./getGTTag.cjs`);let i=require(`generaltranslation/internal`),a=require(`react`);a=e.__toESM(a);function o({renderVariable:e}){return function({children:o,defaultLocale:s=i.libraryDefaultLocale,enableI18n:c}){let l=i=>{let o=r.getGTTag(i);if(n.isVariableElementProps(i.props)){let{variableType:t,variableValue:r,variableOptions:a,injectionType:o}=n.getVariableProps(i.props);return e({variableType:t,variableValue:r,variableOptions:a,locales:[s],enableI18n:c,injectionType:o})}if(o?.transformation===`plural`){let e=o.branches||{};if(typeof i.props.n!=`number`)return i.props.children==null?null:d(i.props.children);let n=t.getPluralBranch(i.props.n,[s],e);return d(n===null?i.props.children:n)}if(o?.transformation===`branch`){let{children:e,branch:t}=i.props,n=o.branches||{},r=t==null||t===``?void 0:t.toString();return d(r&&n[r]!==void 0?n[r]:e)}return o?.transformation===`fragment`?a.default.createElement(a.default.Fragment,{key:i.props.key,children:d(i.props.children)}):i.props.children?a.default.cloneElement(i,{...i.props,"data-_gt":void 0,children:d(i.props.children)}):a.default.cloneElement(i,{...i.props,"data-_gt":void 0})},u=e=>a.default.isValidElement(e)?l(e):e,d=e=>Array.isArray(e)?a.default.Children.map(e,u):u(e);return d(o)}}exports.createRenderDefaultChildren=o;
1
+ const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../plurals/getPluralBranch.cjs`),n=require(`../variables/_getVariableProps.cjs`),r=require(`./getGTTag.cjs`);let i=require(`generaltranslation/internal`),a=require(`react`);a=e.__toESM(a);function o({renderVariable:e}){return function({children:o,defaultLocale:s=i.libraryDefaultLocale,enableI18n:c}){let l=i=>{let o=r.getGTTag(i);if(n.isVariableElementProps(i.props)){let{variableType:t,variableValue:r,variableOptions:a,injectionType:o}=n.getVariableProps(i.props);return e({variableType:t,variableValue:r,variableOptions:a,locales:[s],enableI18n:c,injectionType:o})}if(o?.transformation===`plural`){let e=o.branches||{};return typeof i.props.n==`number`?d(t.getPluralBranch(i.props.n,[s],e)??i.props.children):i.props.children==null?null:d(i.props.children)}if(o?.transformation===`branch`){let{children:e,branch:t}=i.props,n=o.branches||{},r=t==null||t===``?void 0:t.toString();return d(r&&n[r]!==void 0?n[r]:e)}return o?.transformation===`fragment`?a.default.createElement(a.default.Fragment,{key:i.props.key,children:d(i.props.children)}):i.props.children?a.default.cloneElement(i,{...i.props,"data-_gt":void 0,children:d(i.props.children)}):a.default.cloneElement(i,{...i.props,"data-_gt":void 0})},u=e=>a.default.isValidElement(e)?l(e):e,d=e=>Array.isArray(e)?a.default.Children.map(e,u):u(e);return d(o)}}exports.createRenderDefaultChildren=o;
2
2
  //# sourceMappingURL=renderDefaultChildren.shared.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderDefaultChildren.shared.cjs","names":["libraryDefaultLocale","getGTTag","isVariableElementProps","getVariableProps","getPluralBranch","React"],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch !== null\n ? resolvedBranch\n : child.props.children) as TaggedChildren\n );\n }\n\n // Branch\n if (generaltranslation?.transformation === 'branch') {\n const { children, branch } = child.props;\n const branches = generaltranslation.branches || {};\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n return handleChildren(\n branchKey && branches[branchKey] !== undefined\n ? branches[branchKey]\n : children\n );\n }\n\n // Fragment\n if (generaltranslation?.transformation === 'fragment') {\n return React.createElement(React.Fragment, {\n key: child.props.key,\n children: handleChildren(child.props.children),\n });\n }\n\n // Default\n if (child.props.children) {\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n children: handleChildren(child.props.children) as TaggedChildren,\n });\n }\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n });\n };\n\n const handleSingleChild = (child: TaggedChild): ReactNode => {\n if (React.isValidElement(child)) {\n return handleSingleChildElement(child);\n }\n return child;\n };\n\n const handleChildren = (children: TaggedChildren): ReactNode => {\n return Array.isArray(children)\n ? React.Children.map(children, handleSingleChild)\n : handleSingleChild(children);\n };\n\n return handleChildren(children);\n };\n}\n\nexport { createRenderDefaultChildren };\n"],"mappings":"+PAwBA,SAAS,EAA4B,CACnC,kBAGuD,CACvD,OAAO,SAA+B,CACpC,WACA,gBAAgBA,EAAAA,qBAChB,cAC6C,CAC7C,IAAM,EAA4B,GAAoC,CACpE,IAAM,EAAqBC,EAAAA,SAAS,EAAM,CAG1C,GAAIC,EAAAA,uBAAuB,EAAM,MAAM,CAAE,CACvC,GAAM,CAAE,eAAc,gBAAe,kBAAiB,iBACpDC,EAAAA,iBAAiB,EAAM,MAAM,CAC/B,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,QAAS,CAAC,EAAc,CACxB,aACA,gBACD,CAAC,CAIJ,GAAI,GAAoB,iBAAmB,SAAU,CACnD,IAAM,EAAW,EAAmB,UAAY,EAAE,CAClD,GAAI,OAAO,EAAM,MAAM,GAAM,SAC3B,OAAO,EAAM,MAAM,UAAY,KAE3B,KADA,EAAe,EAAM,MAAM,SAAS,CAG1C,IAAM,EAAiBC,EAAAA,gBACrB,EAAM,MAAM,EACZ,CAAC,EAAc,CACf,EACD,CACD,OAAO,EACJ,IAAmB,KAEhB,EAAM,MAAM,SADZ,EAEL,CAIH,GAAI,GAAoB,iBAAmB,SAAU,CACnD,GAAM,CAAE,WAAU,UAAW,EAAM,MAC7B,EAAW,EAAmB,UAAY,EAAE,CAC5C,EACJ,GAAU,MAAQ,IAAW,GAAK,IAAA,GAAY,EAAO,UAAU,CACjE,OAAO,EACL,GAAa,EAAS,KAAe,IAAA,GACjC,EAAS,GACT,EACL,CAmBH,OAfI,GAAoB,iBAAmB,WAClCC,EAAAA,QAAM,cAAcA,EAAAA,QAAM,SAAU,CACzC,IAAK,EAAM,MAAM,IACjB,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAIA,EAAM,MAAM,SACPA,EAAAA,QAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACZ,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAEGA,EAAAA,QAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACb,CAAC,EAGE,EAAqB,GACrBA,EAAAA,QAAM,eAAe,EAAM,CACtB,EAAyB,EAAM,CAEjC,EAGH,EAAkB,GACf,MAAM,QAAQ,EAAS,CAC1BA,EAAAA,QAAM,SAAS,IAAI,EAAU,EAAkB,CAC/C,EAAkB,EAAS,CAGjC,OAAO,EAAe,EAAS"}
1
+ {"version":3,"file":"renderDefaultChildren.shared.cjs","names":["libraryDefaultLocale","getGTTag","isVariableElementProps","getVariableProps","getPluralBranch","React"],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch != null\n ? resolvedBranch\n : child.props.children) as TaggedChildren\n );\n }\n\n // Branch\n if (generaltranslation?.transformation === 'branch') {\n const { children, branch } = child.props;\n const branches = generaltranslation.branches || {};\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n return handleChildren(\n branchKey && branches[branchKey] !== undefined\n ? branches[branchKey]\n : children\n );\n }\n\n // Fragment\n if (generaltranslation?.transformation === 'fragment') {\n return React.createElement(React.Fragment, {\n key: child.props.key,\n children: handleChildren(child.props.children),\n });\n }\n\n // Default\n if (child.props.children) {\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n children: handleChildren(child.props.children) as TaggedChildren,\n });\n }\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n });\n };\n\n const handleSingleChild = (child: TaggedChild): ReactNode => {\n if (React.isValidElement(child)) {\n return handleSingleChildElement(child);\n }\n return child;\n };\n\n const handleChildren = (children: TaggedChildren): ReactNode => {\n return Array.isArray(children)\n ? React.Children.map(children, handleSingleChild)\n : handleSingleChild(children);\n };\n\n return handleChildren(children);\n };\n}\n\nexport { createRenderDefaultChildren };\n"],"mappings":"+PAwBA,SAAS,EAA4B,CACnC,kBAGuD,CACvD,OAAO,SAA+B,CACpC,WACA,gBAAgBA,EAAAA,qBAChB,cAC6C,CAC7C,IAAM,EAA4B,GAAoC,CACpE,IAAM,EAAqBC,EAAAA,SAAS,EAAM,CAG1C,GAAIC,EAAAA,uBAAuB,EAAM,MAAM,CAAE,CACvC,GAAM,CAAE,eAAc,gBAAe,kBAAiB,iBACpDC,EAAAA,iBAAiB,EAAM,MAAM,CAC/B,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,QAAS,CAAC,EAAc,CACxB,aACA,gBACD,CAAC,CAIJ,GAAI,GAAoB,iBAAmB,SAAU,CACnD,IAAM,EAAW,EAAmB,UAAY,EAAE,CAWlD,OAVI,OAAO,EAAM,MAAM,GAAM,SAUtB,EALgBC,EAAAA,gBACrB,EAAM,MAAM,EACZ,CAAC,EAAc,CACf,EAGC,EAEG,EAAM,MAAM,SACjB,CAbQ,EAAM,MAAM,UAAY,KAE3B,KADA,EAAe,EAAM,MAAM,SAAS,CAgB5C,GAAI,GAAoB,iBAAmB,SAAU,CACnD,GAAM,CAAE,WAAU,UAAW,EAAM,MAC7B,EAAW,EAAmB,UAAY,EAAE,CAC5C,EACJ,GAAU,MAAQ,IAAW,GAAK,IAAA,GAAY,EAAO,UAAU,CACjE,OAAO,EACL,GAAa,EAAS,KAAe,IAAA,GACjC,EAAS,GACT,EACL,CAmBH,OAfI,GAAoB,iBAAmB,WAClCC,EAAAA,QAAM,cAAcA,EAAAA,QAAM,SAAU,CACzC,IAAK,EAAM,MAAM,IACjB,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAIA,EAAM,MAAM,SACPA,EAAAA,QAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACZ,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAEGA,EAAAA,QAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACb,CAAC,EAGE,EAAqB,GACrBA,EAAAA,QAAM,eAAe,EAAM,CACtB,EAAyB,EAAM,CAEjC,EAGH,EAAkB,GACf,MAAM,QAAQ,EAAS,CAC1BA,EAAAA,QAAM,SAAS,IAAI,EAAU,EAAkB,CAC/C,EAAkB,EAAS,CAGjC,OAAO,EAAe,EAAS"}
@@ -1,2 +1,2 @@
1
- import{getPluralBranch as e}from"../plurals/getPluralBranch.mjs";import{getVariableProps as t,isVariableElementProps as n}from"../variables/_getVariableProps.mjs";import{getGTTag as r}from"./getGTTag.mjs";import{libraryDefaultLocale as i}from"generaltranslation/internal";import a from"react";function o({renderVariable:o}){return function({children:s,defaultLocale:c=i,enableI18n:l}){let u=i=>{let s=r(i);if(n(i.props)){let{variableType:e,variableValue:n,variableOptions:r,injectionType:a}=t(i.props);return o({variableType:e,variableValue:n,variableOptions:r,locales:[c],enableI18n:l,injectionType:a})}if(s?.transformation===`plural`){let t=s.branches||{};if(typeof i.props.n!=`number`)return i.props.children==null?null:f(i.props.children);let n=e(i.props.n,[c],t);return f(n===null?i.props.children:n)}if(s?.transformation===`branch`){let{children:e,branch:t}=i.props,n=s.branches||{},r=t==null||t===``?void 0:t.toString();return f(r&&n[r]!==void 0?n[r]:e)}return s?.transformation===`fragment`?a.createElement(a.Fragment,{key:i.props.key,children:f(i.props.children)}):i.props.children?a.cloneElement(i,{...i.props,"data-_gt":void 0,children:f(i.props.children)}):a.cloneElement(i,{...i.props,"data-_gt":void 0})},d=e=>a.isValidElement(e)?u(e):e,f=e=>Array.isArray(e)?a.Children.map(e,d):d(e);return f(s)}}export{o as createRenderDefaultChildren};
1
+ import{getPluralBranch as e}from"../plurals/getPluralBranch.mjs";import{getVariableProps as t,isVariableElementProps as n}from"../variables/_getVariableProps.mjs";import{getGTTag as r}from"./getGTTag.mjs";import{libraryDefaultLocale as i}from"generaltranslation/internal";import a from"react";function o({renderVariable:o}){return function({children:s,defaultLocale:c=i,enableI18n:l}){let u=i=>{let s=r(i);if(n(i.props)){let{variableType:e,variableValue:n,variableOptions:r,injectionType:a}=t(i.props);return o({variableType:e,variableValue:n,variableOptions:r,locales:[c],enableI18n:l,injectionType:a})}if(s?.transformation===`plural`){let t=s.branches||{};return typeof i.props.n==`number`?f(e(i.props.n,[c],t)??i.props.children):i.props.children==null?null:f(i.props.children)}if(s?.transformation===`branch`){let{children:e,branch:t}=i.props,n=s.branches||{},r=t==null||t===``?void 0:t.toString();return f(r&&n[r]!==void 0?n[r]:e)}return s?.transformation===`fragment`?a.createElement(a.Fragment,{key:i.props.key,children:f(i.props.children)}):i.props.children?a.cloneElement(i,{...i.props,"data-_gt":void 0,children:f(i.props.children)}):a.cloneElement(i,{...i.props,"data-_gt":void 0})},d=e=>a.isValidElement(e)?u(e):e,f=e=>Array.isArray(e)?a.Children.map(e,d):d(e);return f(s)}}export{o as createRenderDefaultChildren};
2
2
  //# sourceMappingURL=renderDefaultChildren.shared.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderDefaultChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch !== null\n ? resolvedBranch\n : child.props.children) as TaggedChildren\n );\n }\n\n // Branch\n if (generaltranslation?.transformation === 'branch') {\n const { children, branch } = child.props;\n const branches = generaltranslation.branches || {};\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n return handleChildren(\n branchKey && branches[branchKey] !== undefined\n ? branches[branchKey]\n : children\n );\n }\n\n // Fragment\n if (generaltranslation?.transformation === 'fragment') {\n return React.createElement(React.Fragment, {\n key: child.props.key,\n children: handleChildren(child.props.children),\n });\n }\n\n // Default\n if (child.props.children) {\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n children: handleChildren(child.props.children) as TaggedChildren,\n });\n }\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n });\n };\n\n const handleSingleChild = (child: TaggedChild): ReactNode => {\n if (React.isValidElement(child)) {\n return handleSingleChildElement(child);\n }\n return child;\n };\n\n const handleChildren = (children: TaggedChildren): ReactNode => {\n return Array.isArray(children)\n ? React.Children.map(children, handleSingleChild)\n : handleSingleChild(children);\n };\n\n return handleChildren(children);\n };\n}\n\nexport { createRenderDefaultChildren };\n"],"mappings":"qSAwBA,SAAS,EAA4B,CACnC,kBAGuD,CACvD,OAAO,SAA+B,CACpC,WACA,gBAAgB,EAChB,cAC6C,CAC7C,IAAM,EAA4B,GAAoC,CACpE,IAAM,EAAqB,EAAS,EAAM,CAG1C,GAAI,EAAuB,EAAM,MAAM,CAAE,CACvC,GAAM,CAAE,eAAc,gBAAe,kBAAiB,iBACpD,EAAiB,EAAM,MAAM,CAC/B,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,QAAS,CAAC,EAAc,CACxB,aACA,gBACD,CAAC,CAIJ,GAAI,GAAoB,iBAAmB,SAAU,CACnD,IAAM,EAAW,EAAmB,UAAY,EAAE,CAClD,GAAI,OAAO,EAAM,MAAM,GAAM,SAC3B,OAAO,EAAM,MAAM,UAAY,KAE3B,KADA,EAAe,EAAM,MAAM,SAAS,CAG1C,IAAM,EAAiB,EACrB,EAAM,MAAM,EACZ,CAAC,EAAc,CACf,EACD,CACD,OAAO,EACJ,IAAmB,KAEhB,EAAM,MAAM,SADZ,EAEL,CAIH,GAAI,GAAoB,iBAAmB,SAAU,CACnD,GAAM,CAAE,WAAU,UAAW,EAAM,MAC7B,EAAW,EAAmB,UAAY,EAAE,CAC5C,EACJ,GAAU,MAAQ,IAAW,GAAK,IAAA,GAAY,EAAO,UAAU,CACjE,OAAO,EACL,GAAa,EAAS,KAAe,IAAA,GACjC,EAAS,GACT,EACL,CAmBH,OAfI,GAAoB,iBAAmB,WAClC,EAAM,cAAc,EAAM,SAAU,CACzC,IAAK,EAAM,MAAM,IACjB,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAIA,EAAM,MAAM,SACP,EAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACZ,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAEG,EAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACb,CAAC,EAGE,EAAqB,GACrB,EAAM,eAAe,EAAM,CACtB,EAAyB,EAAM,CAEjC,EAGH,EAAkB,GACf,MAAM,QAAQ,EAAS,CAC1B,EAAM,SAAS,IAAI,EAAU,EAAkB,CAC/C,EAAkB,EAAS,CAGjC,OAAO,EAAe,EAAS"}
1
+ {"version":3,"file":"renderDefaultChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch != null\n ? resolvedBranch\n : child.props.children) as TaggedChildren\n );\n }\n\n // Branch\n if (generaltranslation?.transformation === 'branch') {\n const { children, branch } = child.props;\n const branches = generaltranslation.branches || {};\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n return handleChildren(\n branchKey && branches[branchKey] !== undefined\n ? branches[branchKey]\n : children\n );\n }\n\n // Fragment\n if (generaltranslation?.transformation === 'fragment') {\n return React.createElement(React.Fragment, {\n key: child.props.key,\n children: handleChildren(child.props.children),\n });\n }\n\n // Default\n if (child.props.children) {\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n children: handleChildren(child.props.children) as TaggedChildren,\n });\n }\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n });\n };\n\n const handleSingleChild = (child: TaggedChild): ReactNode => {\n if (React.isValidElement(child)) {\n return handleSingleChildElement(child);\n }\n return child;\n };\n\n const handleChildren = (children: TaggedChildren): ReactNode => {\n return Array.isArray(children)\n ? React.Children.map(children, handleSingleChild)\n : handleSingleChild(children);\n };\n\n return handleChildren(children);\n };\n}\n\nexport { createRenderDefaultChildren };\n"],"mappings":"qSAwBA,SAAS,EAA4B,CACnC,kBAGuD,CACvD,OAAO,SAA+B,CACpC,WACA,gBAAgB,EAChB,cAC6C,CAC7C,IAAM,EAA4B,GAAoC,CACpE,IAAM,EAAqB,EAAS,EAAM,CAG1C,GAAI,EAAuB,EAAM,MAAM,CAAE,CACvC,GAAM,CAAE,eAAc,gBAAe,kBAAiB,iBACpD,EAAiB,EAAM,MAAM,CAC/B,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,QAAS,CAAC,EAAc,CACxB,aACA,gBACD,CAAC,CAIJ,GAAI,GAAoB,iBAAmB,SAAU,CACnD,IAAM,EAAW,EAAmB,UAAY,EAAE,CAWlD,OAVI,OAAO,EAAM,MAAM,GAAM,SAUtB,EALgB,EACrB,EAAM,MAAM,EACZ,CAAC,EAAc,CACf,EAGC,EAEG,EAAM,MAAM,SACjB,CAbQ,EAAM,MAAM,UAAY,KAE3B,KADA,EAAe,EAAM,MAAM,SAAS,CAgB5C,GAAI,GAAoB,iBAAmB,SAAU,CACnD,GAAM,CAAE,WAAU,UAAW,EAAM,MAC7B,EAAW,EAAmB,UAAY,EAAE,CAC5C,EACJ,GAAU,MAAQ,IAAW,GAAK,IAAA,GAAY,EAAO,UAAU,CACjE,OAAO,EACL,GAAa,EAAS,KAAe,IAAA,GACjC,EAAS,GACT,EACL,CAmBH,OAfI,GAAoB,iBAAmB,WAClC,EAAM,cAAc,EAAM,SAAU,CACzC,IAAK,EAAM,MAAM,IACjB,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAIA,EAAM,MAAM,SACP,EAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACZ,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAEG,EAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACb,CAAC,EAGE,EAAqB,GACrB,EAAM,eAAe,EAAM,CACtB,EAAyB,EAAM,CAEjC,EAGH,EAAkB,GACf,MAAM,QAAQ,EAAS,CAC1B,EAAM,SAAS,IAAI,EAAU,EAAkB,CAC/C,EAAkB,EAAS,CAGjC,OAAO,EAAe,EAAS"}
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../plurals/getPluralBranch.cjs`),n=require(`../variables/_getVariableProps.cjs`),r=require(`./getGTTag.cjs`),i=require(`./renderDefaultChildren.shared.cjs`);let a=require(`generaltranslation/internal`),o=require(`react`);o=e.__toESM(o);let s=require(`@generaltranslation/format/types`),c=require(`react/jsx-runtime`);function l({renderVariable:e}){let l=i.createRenderDefaultChildren({renderVariable:e});function u({sourceElement:e,targetElement:n,locales:r=[a.libraryDefaultLocale],enableI18n:i}){let{props:c}=e,u=c[`data-_gt`],f=u?.transformation,p=n.d,m={};if(p&&Object.entries(s.HTML_CONTENT_PROPS).forEach(([e,t])=>{p[e]&&(m[t]=p[e])}),f===`plural`){let a=e.props.n;if(typeof a!=`number`)return l({children:e,defaultLocale:r[0],enableI18n:i});let o=t.getPluralBranch(a,r,u.branches||{}),s=o===null?e.props.children:o,c=t.getPluralBranch(a,r,n.d?.b||{});return d({source:s,target:c===null?n.c:c,locales:r,enableI18n:i})}if(f===`branch`){let{branch:e,children:t}=c,a=e==null||e===``?void 0:e.toString(),o=u.branches||{},s=n.d?.b||{};return d({source:a&&o[a]!==void 0?o[a]:t,target:a&&s[a]!==void 0?s[a]:n.c,locales:r,enableI18n:i})}return f===`fragment`&&n.c?o.default.createElement(o.default.Fragment,{key:e.props.key,children:d({source:c.children,target:n.c,locales:r,enableI18n:i})}):c?.children&&n?.c?o.default.cloneElement(e,{...c,...m,"data-_gt":void 0,children:d({source:c.children,target:n.c,locales:r,enableI18n:i})}):l({children:e,defaultLocale:r[0],enableI18n:i})}function d({source:t,target:i,locales:s=[a.libraryDefaultLocale],enableI18n:d}){if(i==null&&t)return l({children:t,defaultLocale:s[0],enableI18n:d});if(typeof i==`string`)return i;if(Array.isArray(i)&&!Array.isArray(t)&&t&&(t=[t]),Array.isArray(t)&&Array.isArray(i)){let l={},f={},p={},m=t.filter(e=>{if(o.default.isValidElement(e))if(n.isVariableElementProps(e.props)){let{variableName:t,variableValue:r,variableOptions:i,injectionType:a}=n.getVariableProps(e.props);l[t]=r,f[t]=i,p[t]=a}else return!0;return!1}),h=e=>m.find(t=>{let n=r.getGTTag(t);return n?.id===void 0?!1:n.id===e.i})||m.shift();return i.map((t,n)=>{if(typeof t==`string`)return(0,c.jsx)(o.default.Fragment,{children:t},`string_${n}`);if((0,a.isVariable)(t))return(0,c.jsx)(o.default.Fragment,{children:e({variableType:t.v||`v`,variableValue:l[t.k],variableOptions:f[t.k],locales:s,enableI18n:d,injectionType:p[t.k]||`manual`})},`var_${n}`);let r=h(t);return r?(0,c.jsx)(o.default.Fragment,{children:u({sourceElement:r,targetElement:t,locales:s,enableI18n:d})},`element_${n}`):null})}if(i&&typeof i==`object`&&!Array.isArray(i)){let r=(0,a.isVariable)(i)?`variable`:`element`;if(o.default.isValidElement(t)){if(r===`element`)return u({sourceElement:t,targetElement:i,locales:s,enableI18n:d});if(n.isVariableElementProps(t.props)){let{variableValue:r,variableOptions:i,variableType:a,injectionType:o}=n.getVariableProps(t.props);return e({variableType:a,variableValue:r,variableOptions:i,locales:s,enableI18n:d,injectionType:o})}}}return l({children:t,defaultLocale:s[0],enableI18n:d})}return d}exports.createRenderTranslatedChildren=l;
1
+ const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../plurals/getPluralBranch.cjs`),n=require(`../variables/_getVariableProps.cjs`),r=require(`./getGTTag.cjs`),i=require(`./renderDefaultChildren.shared.cjs`);let a=require(`generaltranslation/internal`),o=require(`react`);o=e.__toESM(o);let s=require(`@generaltranslation/format/types`),c=require(`react/jsx-runtime`);function l({renderVariable:e}){let l=i.createRenderDefaultChildren({renderVariable:e});function u({sourceElement:e,targetElement:n,locales:r=[a.libraryDefaultLocale],enableI18n:i}){let{props:c}=e,u=c[`data-_gt`],f=u?.transformation,p=n.d,m={};if(p&&Object.entries(s.HTML_CONTENT_PROPS).forEach(([e,t])=>{p[e]&&(m[t]=p[e])}),f===`plural`){let a=e.props.n;return typeof a==`number`?d({source:t.getPluralBranch(a,r,u.branches||{})??e.props.children,target:t.getPluralBranch(a,r,n.d?.b||{})??n.c,locales:r,enableI18n:i}):l({children:e,defaultLocale:r[0],enableI18n:i})}if(f===`branch`){let{branch:e,children:t}=c,a=e==null||e===``?void 0:e.toString(),o=u.branches||{},s=n.d?.b||{};return d({source:a&&o[a]!==void 0?o[a]:t,target:a&&s[a]!==void 0?s[a]:n.c,locales:r,enableI18n:i})}return f===`fragment`&&n.c?o.default.createElement(o.default.Fragment,{key:e.props.key,children:d({source:c.children,target:n.c,locales:r,enableI18n:i})}):c?.children&&n?.c?o.default.cloneElement(e,{...c,...m,"data-_gt":void 0,children:d({source:c.children,target:n.c,locales:r,enableI18n:i})}):l({children:e,defaultLocale:r[0],enableI18n:i})}function d({source:t,target:i,locales:s=[a.libraryDefaultLocale],enableI18n:d}){if(i==null&&t)return l({children:t,defaultLocale:s[0],enableI18n:d});if(typeof i==`string`)return i;if(Array.isArray(i)&&!Array.isArray(t)&&t&&(t=[t]),Array.isArray(t)&&Array.isArray(i)){let l={},f={},p={},m=t.filter(e=>{if(o.default.isValidElement(e))if(n.isVariableElementProps(e.props)){let{variableName:t,variableValue:r,variableOptions:i,injectionType:a}=n.getVariableProps(e.props);l[t]=r,f[t]=i,p[t]=a}else return!0;return!1}),h=e=>m.find(t=>{let n=r.getGTTag(t);return n?.id===void 0?!1:n.id===e.i})||m.shift();return i.map((t,n)=>{if(typeof t==`string`)return(0,c.jsx)(o.default.Fragment,{children:t},`string_${n}`);if((0,a.isVariable)(t))return(0,c.jsx)(o.default.Fragment,{children:e({variableType:t.v||`v`,variableValue:l[t.k],variableOptions:f[t.k],locales:s,enableI18n:d,injectionType:p[t.k]||`manual`})},`var_${n}`);let r=h(t);return r?(0,c.jsx)(o.default.Fragment,{children:u({sourceElement:r,targetElement:t,locales:s,enableI18n:d})},`element_${n}`):null})}if(i&&typeof i==`object`&&!Array.isArray(i)){let r=(0,a.isVariable)(i)?`variable`:`element`;if(o.default.isValidElement(t)){if(r===`element`)return u({sourceElement:t,targetElement:i,locales:s,enableI18n:d});if(n.isVariableElementProps(t.props)){let{variableValue:r,variableOptions:i,variableType:a,injectionType:o}=n.getVariableProps(t.props);return e({variableType:a,variableValue:r,variableOptions:i,locales:s,enableI18n:d,injectionType:o})}}}return l({children:t,defaultLocale:s[0],enableI18n:d})}return d}exports.createRenderTranslatedChildren=l;
2
2
  //# sourceMappingURL=renderTranslatedChildren.shared.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderTranslatedChildren.shared.cjs","names":["createRenderDefaultChildren","libraryDefaultLocale","HTML_CONTENT_PROPS","getPluralBranch","React","isVariableElementProps","getVariableProps","getGTTag"],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch !== null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch !== null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"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"}
1
+ {"version":3,"file":"renderTranslatedChildren.shared.cjs","names":["createRenderDefaultChildren","libraryDefaultLocale","HTML_CONTENT_PROPS","getPluralBranch","React","isVariableElementProps","getVariableProps","getGTTag"],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch != null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch != null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"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"}
@@ -1,2 +1,2 @@
1
- import{getPluralBranch as e}from"../plurals/getPluralBranch.mjs";import{getVariableProps as t,isVariableElementProps as n}from"../variables/_getVariableProps.mjs";import{getGTTag as r}from"./getGTTag.mjs";import{createRenderDefaultChildren as i}from"./renderDefaultChildren.shared.mjs";import{isVariable as a,libraryDefaultLocale as o}from"generaltranslation/internal";import s from"react";import{HTML_CONTENT_PROPS as c}from"@generaltranslation/format/types";import{jsx as l}from"react/jsx-runtime";function u({renderVariable:u}){let d=i({renderVariable:u});function f({sourceElement:t,targetElement:n,locales:r=[o],enableI18n:i}){let{props:a}=t,l=a[`data-_gt`],u=l?.transformation,f=n.d,m={};if(f&&Object.entries(c).forEach(([e,t])=>{f[e]&&(m[t]=f[e])}),u===`plural`){let a=t.props.n;if(typeof a!=`number`)return d({children:t,defaultLocale:r[0],enableI18n:i});let o=e(a,r,l.branches||{}),s=o===null?t.props.children:o,c=e(a,r,n.d?.b||{});return p({source:s,target:c===null?n.c:c,locales:r,enableI18n:i})}if(u===`branch`){let{branch:e,children:t}=a,o=e==null||e===``?void 0:e.toString(),s=l.branches||{},c=n.d?.b||{};return p({source:o&&s[o]!==void 0?s[o]:t,target:o&&c[o]!==void 0?c[o]:n.c,locales:r,enableI18n:i})}return u===`fragment`&&n.c?s.createElement(s.Fragment,{key:t.props.key,children:p({source:a.children,target:n.c,locales:r,enableI18n:i})}):a?.children&&n?.c?s.cloneElement(t,{...a,...m,"data-_gt":void 0,children:p({source:a.children,target:n.c,locales:r,enableI18n:i})}):d({children:t,defaultLocale:r[0],enableI18n:i})}function p({source:e,target:i,locales:c=[o],enableI18n:p}){if(i==null&&e)return d({children:e,defaultLocale:c[0],enableI18n:p});if(typeof i==`string`)return i;if(Array.isArray(i)&&!Array.isArray(e)&&e&&(e=[e]),Array.isArray(e)&&Array.isArray(i)){let o={},d={},m={},h=e.filter(e=>{if(s.isValidElement(e))if(n(e.props)){let{variableName:n,variableValue:r,variableOptions:i,injectionType:a}=t(e.props);o[n]=r,d[n]=i,m[n]=a}else return!0;return!1}),g=e=>h.find(t=>{let n=r(t);return n?.id===void 0?!1:n.id===e.i})||h.shift();return i.map((e,t)=>{if(typeof e==`string`)return l(s.Fragment,{children:e},`string_${t}`);if(a(e))return l(s.Fragment,{children:u({variableType:e.v||`v`,variableValue:o[e.k],variableOptions:d[e.k],locales:c,enableI18n:p,injectionType:m[e.k]||`manual`})},`var_${t}`);let n=g(e);return n?l(s.Fragment,{children:f({sourceElement:n,targetElement:e,locales:c,enableI18n:p})},`element_${t}`):null})}if(i&&typeof i==`object`&&!Array.isArray(i)){let r=a(i)?`variable`:`element`;if(s.isValidElement(e)){if(r===`element`)return f({sourceElement:e,targetElement:i,locales:c,enableI18n:p});if(n(e.props)){let{variableValue:n,variableOptions:r,variableType:i,injectionType:a}=t(e.props);return u({variableType:i,variableValue:n,variableOptions:r,locales:c,enableI18n:p,injectionType:a})}}}return d({children:e,defaultLocale:c[0],enableI18n:p})}return p}export{u as createRenderTranslatedChildren};
1
+ import{getPluralBranch as e}from"../plurals/getPluralBranch.mjs";import{getVariableProps as t,isVariableElementProps as n}from"../variables/_getVariableProps.mjs";import{getGTTag as r}from"./getGTTag.mjs";import{createRenderDefaultChildren as i}from"./renderDefaultChildren.shared.mjs";import{isVariable as a,libraryDefaultLocale as o}from"generaltranslation/internal";import s from"react";import{HTML_CONTENT_PROPS as c}from"@generaltranslation/format/types";import{jsx as l}from"react/jsx-runtime";function u({renderVariable:u}){let d=i({renderVariable:u});function f({sourceElement:t,targetElement:n,locales:r=[o],enableI18n:i}){let{props:a}=t,l=a[`data-_gt`],u=l?.transformation,f=n.d,m={};if(f&&Object.entries(c).forEach(([e,t])=>{f[e]&&(m[t]=f[e])}),u===`plural`){let a=t.props.n;return typeof a==`number`?p({source:e(a,r,l.branches||{})??t.props.children,target:e(a,r,n.d?.b||{})??n.c,locales:r,enableI18n:i}):d({children:t,defaultLocale:r[0],enableI18n:i})}if(u===`branch`){let{branch:e,children:t}=a,o=e==null||e===``?void 0:e.toString(),s=l.branches||{},c=n.d?.b||{};return p({source:o&&s[o]!==void 0?s[o]:t,target:o&&c[o]!==void 0?c[o]:n.c,locales:r,enableI18n:i})}return u===`fragment`&&n.c?s.createElement(s.Fragment,{key:t.props.key,children:p({source:a.children,target:n.c,locales:r,enableI18n:i})}):a?.children&&n?.c?s.cloneElement(t,{...a,...m,"data-_gt":void 0,children:p({source:a.children,target:n.c,locales:r,enableI18n:i})}):d({children:t,defaultLocale:r[0],enableI18n:i})}function p({source:e,target:i,locales:c=[o],enableI18n:p}){if(i==null&&e)return d({children:e,defaultLocale:c[0],enableI18n:p});if(typeof i==`string`)return i;if(Array.isArray(i)&&!Array.isArray(e)&&e&&(e=[e]),Array.isArray(e)&&Array.isArray(i)){let o={},d={},m={},h=e.filter(e=>{if(s.isValidElement(e))if(n(e.props)){let{variableName:n,variableValue:r,variableOptions:i,injectionType:a}=t(e.props);o[n]=r,d[n]=i,m[n]=a}else return!0;return!1}),g=e=>h.find(t=>{let n=r(t);return n?.id===void 0?!1:n.id===e.i})||h.shift();return i.map((e,t)=>{if(typeof e==`string`)return l(s.Fragment,{children:e},`string_${t}`);if(a(e))return l(s.Fragment,{children:u({variableType:e.v||`v`,variableValue:o[e.k],variableOptions:d[e.k],locales:c,enableI18n:p,injectionType:m[e.k]||`manual`})},`var_${t}`);let n=g(e);return n?l(s.Fragment,{children:f({sourceElement:n,targetElement:e,locales:c,enableI18n:p})},`element_${t}`):null})}if(i&&typeof i==`object`&&!Array.isArray(i)){let r=a(i)?`variable`:`element`;if(s.isValidElement(e)){if(r===`element`)return f({sourceElement:e,targetElement:i,locales:c,enableI18n:p});if(n(e.props)){let{variableValue:n,variableOptions:r,variableType:i,injectionType:a}=t(e.props);return u({variableType:i,variableValue:n,variableOptions:r,locales:c,enableI18n:p,injectionType:a})}}}return d({children:e,defaultLocale:c[0],enableI18n:p})}return p}export{u as createRenderTranslatedChildren};
2
2
  //# sourceMappingURL=renderTranslatedChildren.shared.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderTranslatedChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch !== null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch !== null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"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"}
1
+ {"version":3,"file":"renderTranslatedChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch != null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch != null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@generaltranslation/react-core",
3
- "version": "11.0.0-odysseus.14",
3
+ "version": "11.0.0-odysseus.15",
4
4
  "description": "A pure React library for internationalization",
5
5
  "files": [
6
6
  "dist",
@@ -12,9 +12,9 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@generaltranslation/format": "0.1.2-odysseus.1",
15
- "@generaltranslation/supported-locales": "2.1.2-odysseus.4",
16
- "generaltranslation": "9.0.0-odysseus.4",
17
- "gt-i18n": "1.0.0-odysseus.7"
15
+ "@generaltranslation/supported-locales": "2.1.2-odysseus.5",
16
+ "generaltranslation": "9.0.0-odysseus.5",
17
+ "gt-i18n": "1.0.0-odysseus.8"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",