@generaltranslation/react-core 11.0.0-odysseus.9 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.md +249 -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/helpers/InternalLocaleSelector.cjs +1 -1
  7. package/dist/components/helpers/InternalLocaleSelector.cjs.map +1 -1
  8. package/dist/components/helpers/InternalLocaleSelector.mjs +1 -1
  9. package/dist/components/helpers/InternalRegionSelector.cjs +1 -1
  10. package/dist/components/helpers/InternalRegionSelector.cjs.map +1 -1
  11. package/dist/components/helpers/InternalRegionSelector.mjs +1 -1
  12. package/dist/components/translation/T.cjs +1 -1
  13. package/dist/components/translation/T.cjs.map +1 -1
  14. package/dist/components/translation/T.mjs +1 -1
  15. package/dist/components/translation/T.mjs.map +1 -1
  16. package/dist/components/translation/T.rsc.cjs +1 -1
  17. package/dist/components/translation/T.rsc.cjs.map +1 -1
  18. package/dist/components/translation/T.rsc.mjs +1 -1
  19. package/dist/components/translation/T.rsc.mjs.map +1 -1
  20. package/dist/components-rsc.cjs +1 -1
  21. package/dist/components-rsc.d.ts +5 -5
  22. package/dist/components-rsc.mjs +1 -1
  23. package/dist/condition-store/singleton-operations.cjs +1 -1
  24. package/dist/condition-store/singleton-operations.cjs.map +1 -1
  25. package/dist/condition-store/singleton-operations.d.ts +2 -7
  26. package/dist/condition-store/singleton-operations.d.ts.map +1 -1
  27. package/dist/condition-store/singleton-operations.mjs +1 -1
  28. package/dist/condition-store/singleton-operations.mjs.map +1 -1
  29. package/dist/context/InternalGTProvider.cjs +1 -1
  30. package/dist/context/InternalGTProvider.mjs +1 -1
  31. package/dist/context/context.cjs +1 -1
  32. package/dist/context/context.cjs.map +1 -1
  33. package/dist/context/context.mjs +1 -1
  34. package/dist/context/context.mjs.map +1 -1
  35. package/dist/functions/translation/t.cjs +1 -1
  36. package/dist/functions/translation/t.cjs.map +1 -1
  37. package/dist/functions/translation/t.d.ts.map +1 -1
  38. package/dist/functions/translation/t.mjs +1 -1
  39. package/dist/functions/translation/t.mjs.map +1 -1
  40. package/dist/hooks/condition-store.cjs +1 -1
  41. package/dist/hooks/condition-store.cjs.map +1 -1
  42. package/dist/hooks/condition-store.mjs +1 -1
  43. package/dist/hooks/condition-store.mjs.map +1 -1
  44. package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs +2 -0
  45. package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs.map +1 -0
  46. package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs +2 -0
  47. package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs.map +1 -0
  48. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs +1 -1
  49. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs.map +1 -1
  50. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs +1 -1
  51. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs.map +1 -1
  52. package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs +1 -1
  53. package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs.map +1 -1
  54. package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs +1 -1
  55. package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs.map +1 -1
  56. package/dist/hooks/external-store/useTrackedTranslationResolver.cjs +1 -1
  57. package/dist/hooks/external-store/useTrackedTranslationResolver.cjs.map +1 -1
  58. package/dist/hooks/external-store/useTrackedTranslationResolver.d.ts.map +1 -1
  59. package/dist/hooks/external-store/useTrackedTranslationResolver.mjs +1 -1
  60. package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
  61. package/dist/hooks/external-store.cjs +1 -1
  62. package/dist/hooks/external-store.cjs.map +1 -1
  63. package/dist/hooks/external-store.mjs +1 -1
  64. package/dist/hooks/external-store.mjs.map +1 -1
  65. package/dist/hooks/i18n-config.cjs +1 -1
  66. package/dist/hooks/i18n-config.mjs +1 -1
  67. package/dist/hooks/useGT.cjs +1 -1
  68. package/dist/hooks/useGT.cjs.map +1 -1
  69. package/dist/hooks/useGT.mjs +1 -1
  70. package/dist/hooks/useGT.mjs.map +1 -1
  71. package/dist/hooks/useInternalLocaleSelector.cjs +1 -1
  72. package/dist/hooks/useInternalLocaleSelector.cjs.map +1 -1
  73. package/dist/hooks/useInternalLocaleSelector.d.ts +5 -4
  74. package/dist/hooks/useInternalLocaleSelector.d.ts.map +1 -1
  75. package/dist/hooks/useInternalLocaleSelector.mjs +1 -1
  76. package/dist/hooks/useInternalLocaleSelector.mjs.map +1 -1
  77. package/dist/hooks/useInternalRegionSelector.cjs +1 -1
  78. package/dist/hooks/useInternalRegionSelector.cjs.map +1 -1
  79. package/dist/hooks/useInternalRegionSelector.d.ts +9 -8
  80. package/dist/hooks/useInternalRegionSelector.d.ts.map +1 -1
  81. package/dist/hooks/useInternalRegionSelector.mjs +1 -1
  82. package/dist/hooks/useInternalRegionSelector.mjs.map +1 -1
  83. package/dist/hooks/useMessages.cjs +1 -1
  84. package/dist/hooks/useMessages.mjs +1 -1
  85. package/dist/hooks/useTranslations.cjs +1 -1
  86. package/dist/hooks/useTranslations.mjs +1 -1
  87. package/dist/hooks/utils/getShouldTranslate.cjs +1 -1
  88. package/dist/hooks/utils/getShouldTranslate.cjs.map +1 -1
  89. package/dist/hooks/utils/getShouldTranslate.mjs +1 -1
  90. package/dist/hooks/utils/getShouldTranslate.mjs.map +1 -1
  91. package/dist/hooks/utils/missing-translation.cjs +1 -1
  92. package/dist/hooks/utils/missing-translation.cjs.map +1 -1
  93. package/dist/hooks/utils/missing-translation.mjs +1 -1
  94. package/dist/hooks/utils/missing-translation.mjs.map +1 -1
  95. package/dist/hooks/utils.cjs +1 -1
  96. package/dist/hooks/utils.cjs.map +1 -1
  97. package/dist/hooks/utils.d.ts +2 -6
  98. package/dist/hooks/utils.d.ts.map +1 -1
  99. package/dist/hooks/utils.mjs +1 -1
  100. package/dist/hooks/utils.mjs.map +1 -1
  101. package/dist/hooks.cjs +1 -1
  102. package/dist/hooks.d.ts +4 -4
  103. package/dist/hooks.mjs +1 -1
  104. package/dist/i18n-cache/ReactI18nCache.cjs.map +1 -1
  105. package/dist/i18n-cache/ReactI18nCache.d.ts +1 -1
  106. package/dist/i18n-cache/ReactI18nCache.d.ts.map +1 -1
  107. package/dist/i18n-cache/ReactI18nCache.mjs.map +1 -1
  108. package/dist/i18n-store/I18nStore.cjs.map +1 -1
  109. package/dist/i18n-store/I18nStore.d.ts.map +1 -1
  110. package/dist/i18n-store/I18nStore.mjs.map +1 -1
  111. package/dist/i18n-store/singleton-operations.cjs +1 -1
  112. package/dist/i18n-store/singleton-operations.cjs.map +1 -1
  113. package/dist/i18n-store/singleton-operations.d.ts +2 -4
  114. package/dist/i18n-store/singleton-operations.d.ts.map +1 -1
  115. package/dist/i18n-store/singleton-operations.mjs +1 -1
  116. package/dist/i18n-store/singleton-operations.mjs.map +1 -1
  117. package/dist/i18n-store/storeTypes.d.ts +2 -1
  118. package/dist/i18n-store/storeTypes.d.ts.map +1 -1
  119. package/dist/pure.cjs +1 -1
  120. package/dist/pure.d.ts +7 -21
  121. package/dist/pure.mjs +1 -1
  122. package/dist/setup/i18nConfig.cjs +1 -1
  123. package/dist/setup/i18nConfig.cjs.map +1 -1
  124. package/dist/setup/i18nConfig.d.ts +31 -4
  125. package/dist/setup/i18nConfig.d.ts.map +1 -1
  126. package/dist/setup/i18nConfig.mjs +1 -1
  127. package/dist/setup/i18nConfig.mjs.map +1 -1
  128. package/dist/setup/initializeGTSRA.cjs +1 -1
  129. package/dist/setup/initializeGTSRA.cjs.map +1 -1
  130. package/dist/setup/initializeGTSRA.d.ts +2 -2
  131. package/dist/setup/initializeGTSRA.d.ts.map +1 -1
  132. package/dist/setup/initializeGTSRA.mjs +1 -1
  133. package/dist/setup/initializeGTSRA.mjs.map +1 -1
  134. package/dist/utils/rendering/createRenderPipeline.cjs +1 -1
  135. package/dist/utils/rendering/createRenderPipeline.cjs.map +1 -1
  136. package/dist/utils/rendering/createRenderPipeline.d.ts +2 -2
  137. package/dist/utils/rendering/createRenderPipeline.mjs +1 -1
  138. package/dist/utils/rendering/createRenderPipeline.mjs.map +1 -1
  139. package/dist/utils/rendering/renderDefaultChildren.shared.cjs +1 -1
  140. package/dist/utils/rendering/renderDefaultChildren.shared.cjs.map +1 -1
  141. package/dist/utils/rendering/renderDefaultChildren.shared.mjs +1 -1
  142. package/dist/utils/rendering/renderDefaultChildren.shared.mjs.map +1 -1
  143. package/dist/utils/rendering/renderPipeline.rsc.d.ts +1 -1
  144. package/dist/utils/rendering/renderPreparedT.shared.cjs +1 -1
  145. package/dist/utils/rendering/renderPreparedT.shared.cjs.map +1 -1
  146. package/dist/utils/rendering/renderPreparedT.shared.mjs +1 -1
  147. package/dist/utils/rendering/renderPreparedT.shared.mjs.map +1 -1
  148. package/dist/utils/rendering/renderTranslatedChildren.shared.cjs +1 -1
  149. package/dist/utils/rendering/renderTranslatedChildren.shared.cjs.map +1 -1
  150. package/dist/utils/rendering/renderTranslatedChildren.shared.mjs +1 -1
  151. package/dist/utils/rendering/renderTranslatedChildren.shared.mjs.map +1 -1
  152. package/dist/utils/translation/prepareT.shared.cjs +1 -1
  153. package/dist/utils/translation/prepareT.shared.cjs.map +1 -1
  154. package/dist/utils/translation/prepareT.shared.mjs +1 -1
  155. package/dist/utils/translation/prepareT.shared.mjs.map +1 -1
  156. package/dist/utils/translation/usePrepareT.cjs +1 -1
  157. package/dist/utils/translation/usePrepareT.mjs +1 -1
  158. package/dist/utils/types.d.ts +1 -43
  159. package/dist/utils/types.d.ts.map +1 -1
  160. package/package.json +5 -33
  161. package/dist/cookies.cjs +0 -1
  162. package/dist/cookies.d.ts +0 -2
  163. package/dist/cookies.mjs +0 -1
  164. package/dist/setup/initializeGTSPA.cjs +0 -2
  165. package/dist/setup/initializeGTSPA.cjs.map +0 -1
  166. package/dist/setup/initializeGTSPA.d.ts +0 -16
  167. package/dist/setup/initializeGTSPA.d.ts.map +0 -1
  168. package/dist/setup/initializeGTSPA.mjs +0 -2
  169. package/dist/setup/initializeGTSPA.mjs.map +0 -1
  170. package/dist/utils/cookies.cjs +0 -2
  171. package/dist/utils/cookies.cjs.map +0 -1
  172. package/dist/utils/cookies.d.ts +0 -16
  173. package/dist/utils/cookies.d.ts.map +0 -1
  174. package/dist/utils/cookies.mjs +0 -2
  175. package/dist/utils/cookies.mjs.map +0 -1
  176. package/dist/utils/dictionaries/flattenDictionary.cjs +0 -2
  177. package/dist/utils/dictionaries/flattenDictionary.cjs.map +0 -1
  178. package/dist/utils/dictionaries/flattenDictionary.d.ts +0 -15
  179. package/dist/utils/dictionaries/flattenDictionary.d.ts.map +0 -1
  180. package/dist/utils/dictionaries/flattenDictionary.mjs +0 -2
  181. package/dist/utils/dictionaries/flattenDictionary.mjs.map +0 -1
  182. package/dist/utils/dictionaries/getDictionaryEntry.cjs +0 -2
  183. package/dist/utils/dictionaries/getDictionaryEntry.cjs.map +0 -1
  184. package/dist/utils/dictionaries/getDictionaryEntry.d.ts +0 -8
  185. package/dist/utils/dictionaries/getDictionaryEntry.d.ts.map +0 -1
  186. package/dist/utils/dictionaries/getDictionaryEntry.mjs +0 -2
  187. package/dist/utils/dictionaries/getDictionaryEntry.mjs.map +0 -1
  188. package/dist/utils/dictionaries/getEntryAndMetadata.cjs +0 -2
  189. package/dist/utils/dictionaries/getEntryAndMetadata.cjs.map +0 -1
  190. package/dist/utils/dictionaries/getEntryAndMetadata.d.ts +0 -10
  191. package/dist/utils/dictionaries/getEntryAndMetadata.d.ts.map +0 -1
  192. package/dist/utils/dictionaries/getEntryAndMetadata.mjs +0 -2
  193. package/dist/utils/dictionaries/getEntryAndMetadata.mjs.map +0 -1
  194. package/dist/utils/dictionaries/indexDict.cjs +0 -2
  195. package/dist/utils/dictionaries/indexDict.cjs.map +0 -1
  196. package/dist/utils/dictionaries/indexDict.mjs +0 -2
  197. package/dist/utils/dictionaries/indexDict.mjs.map +0 -1
  198. package/dist/utils/dictionaries/isDictionaryEntry.cjs +0 -2
  199. package/dist/utils/dictionaries/isDictionaryEntry.cjs.map +0 -1
  200. package/dist/utils/dictionaries/isDictionaryEntry.d.ts +0 -12
  201. package/dist/utils/dictionaries/isDictionaryEntry.d.ts.map +0 -1
  202. package/dist/utils/dictionaries/isDictionaryEntry.mjs +0 -2
  203. package/dist/utils/dictionaries/isDictionaryEntry.mjs.map +0 -1
  204. package/dist/utils/dictionaries/mergeDictionaries.cjs +0 -2
  205. package/dist/utils/dictionaries/mergeDictionaries.cjs.map +0 -1
  206. package/dist/utils/dictionaries/mergeDictionaries.d.ts +0 -7
  207. package/dist/utils/dictionaries/mergeDictionaries.d.ts.map +0 -1
  208. package/dist/utils/dictionaries/mergeDictionaries.mjs +0 -2
  209. package/dist/utils/dictionaries/mergeDictionaries.mjs.map +0 -1
  210. package/dist/utils/internal/addGTIdentifier.d.ts +0 -8
  211. package/dist/utils/internal/addGTIdentifier.d.ts.map +0 -1
  212. package/dist/utils/internal/writeChildrenAsObjects.d.ts +0 -14
  213. package/dist/utils/internal/writeChildrenAsObjects.d.ts.map +0 -1
  214. package/dist/utils/variables/_getVariableProps.d.ts +0 -13
  215. package/dist/utils/variables/_getVariableProps.d.ts.map +0 -1
  216. package/dist/utils/variables/getVariableName.d.ts +0 -12
  217. package/dist/utils/variables/getVariableName.d.ts.map +0 -1
@@ -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 getConditionStore as getReadonlyConditionStore,\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":"wHAYA,KAAM,CAAE,oBAAmB,oBAAmB,gCAAA,EAAA,EAAA,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 getConditionStore: () => ReadonlyConditionStoreInterface, setConditionStore: (nextConditionStore: 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 };
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":";;;cAmBQ,iBAAA,QAAiB,+BAAA,EAAE,iBAAA,GAAiB,kBAAA,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{createConditionStoreSingleton as e}from"gt-i18n/internal";import{createDiagnosticMessage as t}from"generaltranslation/internal";const{getConditionStore:n,setConditionStore:r,isConditionStoreInitialized:i}=e(t({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};
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 getConditionStore as getReadonlyConditionStore,\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(`./context.cjs`);let t=require(`react`),n=require(`react/jsx-runtime`);const r=e.getGTContext();function i({children:e,translations:i,dictionaries:a,conditionStore:o,i18nStore:s,onMissingTranslation:c,onMissingDictionaryEntry:l,onMissingDictionaryObj:u}){let d=(0,t.useMemo)(()=>({translationsSnapshot:i,dictionariesSnapshot:a??{},i18nStore:s,conditionStore:o,onMissingTranslation:c,onMissingDictionaryEntry:l,onMissingDictionaryObj:u}),[i,a,s,o,c,l,u]);return(0,t.useEffect)(()=>{s.updateTranslations(i),s.updateDictionaries(a??{})},[i,a,s]),(0,n.jsx)(r.Provider,{value:d,children:e})}exports.InternalGTProvider=i;
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./context.cjs`);let t=require(`react/jsx-runtime`),n=require(`react`);const r=e.getGTContext();function i({children:e,translations:i,dictionaries:a,conditionStore:o,i18nStore:s,onMissingTranslation:c,onMissingDictionaryEntry:l,onMissingDictionaryObj:u}){let d=(0,n.useMemo)(()=>({translationsSnapshot:i,dictionariesSnapshot:a??{},i18nStore:s,conditionStore:o,onMissingTranslation:c,onMissingDictionaryEntry:l,onMissingDictionaryObj:u}),[i,a,s,o,c,l,u]);return(0,n.useEffect)(()=>{s.updateTranslations(i),s.updateDictionaries(a??{})},[i,a,s]),(0,t.jsx)(r.Provider,{value:d,children:e})}exports.InternalGTProvider=i;
2
2
  //# sourceMappingURL=InternalGTProvider.cjs.map
@@ -1,2 +1,2 @@
1
- import{getGTContext as e}from"./context.mjs";import{useEffect as t,useMemo as n}from"react";import{jsx as r}from"react/jsx-runtime";const i=e();function a({children:e,translations:a,dictionaries:o,conditionStore:s,i18nStore:c,onMissingTranslation:l,onMissingDictionaryEntry:u,onMissingDictionaryObj:d}){let f=n(()=>({translationsSnapshot:a,dictionariesSnapshot:o??{},i18nStore:c,conditionStore:s,onMissingTranslation:l,onMissingDictionaryEntry:u,onMissingDictionaryObj:d}),[a,o,c,s,l,u,d]);return t(()=>{c.updateTranslations(a),c.updateDictionaries(o??{})},[a,o,c]),r(i.Provider,{value:f,children:e})}export{a as InternalGTProvider};
1
+ import{getGTContext as e}from"./context.mjs";import{jsx as t}from"react/jsx-runtime";import{useEffect as n,useMemo as r}from"react";const i=e();function a({children:e,translations:a,dictionaries:o,conditionStore:s,i18nStore:c,onMissingTranslation:l,onMissingDictionaryEntry:u,onMissingDictionaryObj:d}){let f=r(()=>({translationsSnapshot:a,dictionariesSnapshot:o??{},i18nStore:c,conditionStore:s,onMissingTranslation:l,onMissingDictionaryEntry:u,onMissingDictionaryObj:d}),[a,o,c,s,l,u,d]);return n(()=>{c.updateTranslations(a),c.updateDictionaries(o??{})},[a,o,c]),t(i.Provider,{value:f,children:e})}export{a as InternalGTProvider};
2
2
  //# sourceMappingURL=InternalGTProvider.mjs.map
@@ -1,2 +1,2 @@
1
- require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../setup/i18nConfig.cjs`);let t=require(`generaltranslation/internal`),n=require(`react`);function r(){let e=globalThis;return e.__generaltranslation??={},e.__generaltranslation.reactCore??={},e.__generaltranslation.reactCore}function i(){let e=r();return e.gtContext??=(0,n.createContext)(void 0),e.gtContext}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(`gt-i18n/internal`),n=require(`generaltranslation/internal`),r=require(`react`);const i=(0,t.createGlobalSingleton)({namespace:`reactCore`,key:`gtContext`,source:`@generaltranslation/react-core`,notInitialized:()=>(0,n.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 a(){return i.isInitialized()||i.set((0,r.createContext)(void 0)),i.get()}function o(){let t=(0,r.useContext)(a());if(t||e.getI18nConfig().getRenderStrategy()===`SPA`)return t;throw Error(s())}function s(){return(0,n.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=a,exports.useGTContext=o;
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 { 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\ntype ReactCoreGlobals = {\n gtContext?: Context<GTContextType | undefined>;\n [key: string]: unknown;\n};\n\ntype GeneralTranslationGlobal = {\n reactCore?: ReactCoreGlobals;\n [key: string]: unknown;\n};\n\ntype GlobalWithGeneralTranslation = {\n __generaltranslation?: GeneralTranslationGlobal;\n};\n\nfunction getReactCoreGlobals(): ReactCoreGlobals {\n const globalObj = globalThis as unknown as GlobalWithGeneralTranslation;\n globalObj.__generaltranslation ??= {};\n // TODO: Consider checking package versions and using a compatibility matrix before sharing global singletons.\n globalObj.__generaltranslation.reactCore ??= {};\n return globalObj.__generaltranslation.reactCore;\n}\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n const reactCoreGlobals = getReactCoreGlobals();\n reactCoreGlobals.gtContext ??= createContext<GTContextType | undefined>(\n undefined\n );\n return reactCoreGlobals.gtContext;\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":"wJA0DA,SAAS,GAAwC,CAC/C,IAAM,EAAY,WAIlB,MAHA,GAAU,uBAAyB,EAAE,CAErC,EAAU,qBAAqB,YAAc,EAAE,CACxC,EAAU,qBAAqB,UAGxC,SAAgB,GAAmD,CACjE,IAAM,EAAmB,GAAqB,CAI9C,MAHA,GAAiB,aAAA,EAAA,EAAA,eACf,IAAA,GACD,CACM,EAAiB,UAG1B,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":"sLA6CA,MAAM,GAAA,EAAA,EAAA,uBAEJ,CACA,UAAW,YACX,IAAK,YACL,OAAQ,iCACR,oBAAA,EAAA,EAAA,yBAC0B,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,uDACd,IAAK,kDACL,IAAK,yDACN,CAAC,CACL,CAAC,CAEF,SAAgB,GAAmD,CAKjE,OAHK,EAAmB,eAAe,EACrC,EAAmB,KAAA,EAAA,EAAA,eAA6C,IAAA,GAAU,CAAC,CAEtE,EAAmB,KAAK,CAGjC,SAAgB,GAA0C,CACxD,IAAM,GAAA,EAAA,EAAA,YAAqB,GAAc,CAAC,CAC1C,GAAI,GAAWA,EAAAA,eAAe,CAAC,mBAAmB,GAAK,MACrD,OAAO,EAKT,MAAU,MAAM,GAA8B,CAAC,CAGjD,SAAS,GAAuC,CAC9C,OAAA,EAAA,EAAA,yBAA+B,CAC7B,OAAQ,iCACR,SAAU,QACV,aAAc,uCACd,IAAK,mDACL,IAAK,yDACN,CAAC"}
@@ -1,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";function i(){let e=globalThis;return e.__generaltranslation??={},e.__generaltranslation.reactCore??={},e.__generaltranslation.reactCore}function a(){let e=i();return e.gtContext??=n(void 0),e.gtContext}function o(){let t=r(a());if(t||e().getRenderStrategy()===`SPA`)return t;throw Error(s())}function s(){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{a as getGTContext,o as useGTContext};
1
+ import{getI18nConfig as e}from"../setup/i18nConfig.mjs";import{createGlobalSingleton as t}from"gt-i18n/internal";import{createDiagnosticMessage as n}from"generaltranslation/internal";import{createContext as r,useContext as i}from"react";const a=t({namespace:`reactCore`,key:`gtContext`,source:`@generaltranslation/react-core`,notInitialized:()=>n({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(r(void 0)),a.get()}function s(){let t=i(o());if(t||e().getRenderStrategy()===`SPA`)return t;throw Error(c())}function c(){return n({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":[],"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 { 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\ntype ReactCoreGlobals = {\n gtContext?: Context<GTContextType | undefined>;\n [key: string]: unknown;\n};\n\ntype GeneralTranslationGlobal = {\n reactCore?: ReactCoreGlobals;\n [key: string]: unknown;\n};\n\ntype GlobalWithGeneralTranslation = {\n __generaltranslation?: GeneralTranslationGlobal;\n};\n\nfunction getReactCoreGlobals(): ReactCoreGlobals {\n const globalObj = globalThis as unknown as GlobalWithGeneralTranslation;\n globalObj.__generaltranslation ??= {};\n // TODO: Consider checking package versions and using a compatibility matrix before sharing global singletons.\n globalObj.__generaltranslation.reactCore ??= {};\n return globalObj.__generaltranslation.reactCore;\n}\n\nexport function getGTContext(): Context<GTContextType | undefined> {\n const reactCoreGlobals = getReactCoreGlobals();\n reactCoreGlobals.gtContext ??= createContext<GTContextType | undefined>(\n undefined\n );\n return reactCoreGlobals.gtContext;\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":"oLA0DA,SAAS,GAAwC,CAC/C,IAAM,EAAY,WAIlB,MAHA,GAAU,uBAAyB,EAAE,CAErC,EAAU,qBAAqB,YAAc,EAAE,CACxC,EAAU,qBAAqB,UAGxC,SAAgB,GAAmD,CACjE,IAAM,EAAmB,GAAqB,CAI9C,MAHA,GAAiB,YAAc,EAC7B,IAAA,GACD,CACM,EAAiB,UAG1B,SAAgB,GAA0C,CACxD,IAAM,EAAU,EAAW,GAAc,CAAC,CAC1C,GAAI,GAAW,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(`gt-i18n/internal`),a=require(`generaltranslation/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,i.createLookupOptions)(r,n??{},`ICU`))}return c(e,t)};function s(n,a,o={}){let s=e.getReactI18nCache(),c=t.getI18nConfig().getDefaultLocale();if(!r.getShouldTranslate())return(0,i.interpolateMessage)({options:o,source:a,sourceLocale:c});let l=(0,i.createLookupOptions)(n,o,`ICU`);return(0,i.interpolateMessage)({source:a,target:s.lookupTranslation(l.$locale,a,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,a.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,i.getRuntimeEnvironment)()===`development`?void 0:`Falling back to defaultLocale value.`,details:`Message: "${s}"`});if((0,i.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 } from 'gt-i18n/types';\nimport type { LookupOptionsFor } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\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":"kVAiCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,GAAA,EAAA,EAAA,qBACoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAYA,EAAAA,mBAAmB,CAC/B,EAAgBC,EAAAA,eAAe,CAAC,kBAAkB,CACxD,GAAI,CAACC,EAAAA,oBAAoB,CACvB,OAAA,EAAA,EAAA,oBAA0B,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,GAAA,EAAA,EAAA,qBAAoC,EAAQ,EAAS,MAAM,CAMjE,OAAA,EAAA,EAAA,oBAA0B,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADYF,EAAAA,mBAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,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":";;;;AAiCA;;;;;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{createLookupOptions as a,getRuntimeEnvironment as o,interpolateMessage as s}from"gt-i18n/internal";import{createDiagnosticMessage as c}from"generaltranslation/internal";const l=(e,...t)=>{if(m(e),typeof e==`string`){let n=t.at(0),r=n?.$locale??h();return u(r,e,a(r,n??{},`ICU`))}return d(e,t)};function u(n,r,o={}){let c=e(),l=t().getDefaultLocale();if(!i())return s({options:o,source:r,sourceLocale:l});let u=a(n,o,`ICU`);return s({source:r,target:c.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 a=typeof e==`string`?e:e.join(``),s=c({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:o()===`development`?void 0:`Falling back to defaultLocale value.`,details:`Message: "${a}"`});if(o()===`development`)throw Error(s);console.error(s)}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 } from 'gt-i18n/types';\nimport type { LookupOptionsFor } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '../../setup/i18nConfig';\nimport {\n getReadonlyConditionStore,\n isReadonlyConditionStoreInitialized,\n} from '../../condition-store/singleton-operations';\nimport { StringContent, StringFormat } from 'generaltranslation/types';\nimport { getReactI18nCache } from '../../i18n-cache/singleton-operations';\nimport { getShouldTranslate } from '../../hooks/utils/getShouldTranslate';\nimport { createDiagnosticMessage } from 'generaltranslation/internal';\n\n/**\n * Translate a message\n * @param {string} message - The message to translate.\n * @param {GTTranslationOptions} [options] - The options for the translation.\n * @returns {string} The translated message.\n *\n * @example\n * t('Hello, world!'); // Translates 'Hello, world!'\n *\n * @example\n * t('Hello, {name}!', { name: 'John' }); // Translates 'Hello, John!'\n *\n * @example\n * t`Hello, ${name}` // Translate via tagged template literal\n *\n */\nexport const t: StringOrTemplateSyncResolutionFunction = (\n messageOrStrings: string | TemplateStringsArray,\n ...values: unknown[]\n) => {\n // Warnings and errors\n enforceSSRRules(messageOrStrings);\n\n // t(\"Hello, {name}!\", { name: \"John\" })\n if (typeof messageOrStrings === 'string') {\n const options = values.at(0) as GTTranslationOptions | undefined;\n const locale = options?.$locale ?? getLocale();\n return resolveStringContent(\n locale,\n messageOrStrings,\n createLookupOptions(locale, options ?? {}, 'ICU')\n );\n }\n\n // t`Hello, ${name}`\n return handleTaggedTemplateLiteralTranslation(messageOrStrings, values);\n};\n\n// ----- Helper Functions ----- //\n\nexport function resolveStringContent(\n locale: string,\n content: StringContent,\n options: LookupOptionsFor<StringFormat> = {}\n): StringContent {\n const i18nCache = getReactI18nCache();\n const defaultLocale = getI18nConfig().getDefaultLocale();\n if (!getShouldTranslate()) {\n return interpolateMessage({\n options,\n source: content,\n sourceLocale: defaultLocale,\n });\n }\n\n const lookupOptions = createLookupOptions(locale, options, 'ICU');\n const translation = i18nCache.lookupTranslation(\n lookupOptions.$locale,\n content,\n lookupOptions\n );\n return interpolateMessage({\n source: content,\n target: translation,\n options: lookupOptions,\n sourceLocale: defaultLocale,\n });\n}\n\n/**\n * Handle tagged template literal translation\n * @param messageOrStrings - The message or strings to translate.\n * @param values - The values to interpolate.\n * @returns The translated message.\n *\n * This is triggered when there has been no compiler transformation\n *\n * Try looking up interpolated template first\n * If not found, resolve uninterpolated message\n */\nfunction handleTaggedTemplateLiteralTranslation(\n messageOrStrings: TemplateStringsArray,\n values: unknown[]\n): string {\n const locale = getLocale();\n // for tagged template literals, there has been no compiler transformation\n // (1) lookup interpolated template (aka derived message)\n const interpolatedTemplate = interpolateTemplateLiteral(\n messageOrStrings,\n values\n );\n const i18nCache = getReactI18nCache();\n const translatedInterpolatedTemplate = i18nCache.lookupTranslation(\n locale,\n interpolatedTemplate,\n { $format: 'STRING' }\n );\n if (translatedInterpolatedTemplate) return translatedInterpolatedTemplate;\n\n // (2) resolve uninterpolated message\n const { message, variables } = extractInterpolatableValues(\n messageOrStrings,\n values\n );\n return resolveStringContent(locale, message, variables);\n}\n\n/**\n * Given a TemplateStringsArray, and values, return the uninterpolated message and variables.\n * @param strings - The template strings.\n * @param values - The values to interpolate.\n * @returns The interpolated message and variables.\n */\nfunction extractInterpolatableValues(\n strings: TemplateStringsArray,\n values: unknown[]\n): {\n message: string;\n variables: Record<string, unknown>;\n} {\n // String parts\n const parts: string[] = [];\n // Variables\n const variables: Record<string, unknown> = {};\n let varIndex = 0;\n\n for (let i = 0; i < strings.length; i++) {\n // Add the cooked text from the quasi (use cooked to handle escape sequences)\n parts.push(strings[i]);\n\n // If there's a corresponding expression, create a variable placeholder\n if (i < values.length) {\n const key = varIndex.toString();\n parts.push(`{${key}}`);\n variables[key] = values[i];\n varIndex++;\n }\n }\n\n return {\n message: parts.join(''),\n variables,\n };\n}\n\n/**\n * Interpolate a template literal\n * @param message - The message to interpolate.\n * @param variables - The variables to interpolate.\n * @returns The interpolated message.\n */\nfunction interpolateTemplateLiteral(\n strings: TemplateStringsArray,\n values: unknown[]\n): string {\n return strings\n .map((string, index) => {\n return string + (values[index] ?? '');\n })\n .join('');\n}\n\n/**\n * Module-level t() only works for SPA.\n * We have to error or fallback in SSR.\n */\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":"2fAiCA,MAAa,GACX,EACA,GAAG,IACA,CAKH,GAHA,EAAgB,EAAiB,CAG7B,OAAO,GAAqB,SAAU,CACxC,IAAM,EAAU,EAAO,GAAG,EAAE,CACtB,EAAS,GAAS,SAAW,GAAW,CAC9C,OAAO,EACL,EACA,EACA,EAAoB,EAAQ,GAAW,EAAE,CAAE,MAAM,CAClD,CAIH,OAAO,EAAuC,EAAkB,EAAO,EAKzE,SAAgB,EACd,EACA,EACA,EAA0C,EAAE,CAC7B,CACf,IAAM,EAAY,GAAmB,CAC/B,EAAgBA,GAAe,CAAC,kBAAkB,CACxD,GAAI,CAAC,GAAoB,CACvB,OAAO,EAAmB,CACxB,UACA,OAAQ,EACR,aAAc,EACf,CAAC,CAGJ,IAAM,EAAgB,EAAoB,EAAQ,EAAS,MAAM,CAMjE,OAAO,EAAmB,CACxB,OAAQ,EACR,OAPkB,EAAU,kBAC5B,EAAc,QACd,EACA,EAImB,CACnB,QAAS,EACT,aAAc,EACf,CAAC,CAcJ,SAAS,EACP,EACA,EACQ,CACR,IAAM,EAAS,GAAW,CAGpB,EAAuB,EAC3B,EACA,EACD,CAEK,EADY,GAC8B,CAAC,kBAC/C,EACA,EACA,CAAE,QAAS,SAAU,CACtB,CACD,GAAI,EAAgC,OAAO,EAG3C,GAAM,CAAE,UAAS,aAAc,EAC7B,EACA,EACD,CACD,OAAO,EAAqB,EAAQ,EAAS,EAAU,CASzD,SAAS,EACP,EACA,EAIA,CAEA,IAAM,EAAkB,EAAE,CAEpB,EAAqC,EAAE,CACzC,EAAW,EAEf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAKlC,GAHA,EAAM,KAAK,EAAQ,GAAG,CAGlB,EAAI,EAAO,OAAQ,CACrB,IAAM,EAAM,EAAS,UAAU,CAC/B,EAAM,KAAK,IAAI,EAAI,GAAG,CACtB,EAAU,GAAO,EAAO,GACxB,IAIJ,MAAO,CACL,QAAS,EAAM,KAAK,GAAG,CACvB,YACD,CASH,SAAS,EACP,EACA,EACQ,CACR,OAAO,EACJ,KAAK,EAAQ,IACL,GAAU,EAAO,IAAU,IAClC,CACD,KAAK,GAAG,CAOb,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"}
@@ -0,0 +1,2 @@
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);let e=require(`react`);function t(t,n,r){let i=(0,e.useRef)(0),a=(0,e.useCallback)(e=>n(n=>{t.current.has(r(n))&&(i.current++,e())}),[n,r,t]),o=(0,e.useCallback)(()=>i.current,[]);(0,e.useSyncExternalStore)(a,o,o)}const n=process.env.NODE_ENV===`production`?()=>{}:t;exports.useSubscribeToTrackedLookups=n;
2
+ //# sourceMappingURL=useSubscribeToTrackedLookups.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSubscribeToTrackedLookups.cjs","names":[],"sources":["../../../src/hooks/external-store/useSubscribeToTrackedLookups.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport type { StoreListener, Unsubscribe } from '../../i18n-store/storeTypes';\n\ntype UseSubscribeToTrackedLookups = <L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) => void;\n\n/**\n * Subscribe to store events, but only trigger re-renders when the event's\n * lookup is in the tracked keys set. Shared by the tracked translation and\n * dictionary resolvers, which differ only in the store subscribe method and the\n * listener-key function.\n *\n * Remember that we can make no assumptions about when the tracked set gets\n * updated. This is technically not pure, but it is an acceptable trade since it\n * only drives dev translation hot reload.\n */\nfunction useSubscribeToTrackedLookupsDev<L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return subscribeToEvents((lookup) => {\n if (!trackedKeysRef.current!.has(getListenerKey(lookup))) return;\n versionRef.current++;\n listener();\n });\n },\n [subscribeToEvents, getListenerKey, trackedKeysRef]\n );\n const getSnapshot = useCallback(() => versionRef.current, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nconst useSubscribeToTrackedLookupsProd: UseSubscribeToTrackedLookups = () => {};\n\nexport const useSubscribeToTrackedLookups: UseSubscribeToTrackedLookups =\n process.env.NODE_ENV === 'production'\n ? useSubscribeToTrackedLookupsProd\n : useSubscribeToTrackedLookupsDev;\n"],"mappings":"uEAwBA,SAAS,EACP,EACA,EACA,EACA,CAEA,IAAM,GAAA,EAAA,EAAA,QAAoB,EAAE,CACtB,GAAA,EAAA,EAAA,aACH,GACQ,EAAmB,GAAW,CAC9B,EAAe,QAAS,IAAI,EAAe,EAAO,CAAC,GACxD,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAmB,EAAgB,EAAe,CACpD,CACK,GAAA,EAAA,EAAA,iBAAgC,EAAW,QAAS,EAAE,CAAC,EAE7D,EAAA,EAAA,sBAAqB,EAAW,EAAa,EAAY,CAK3D,MAAa,EACX,QAAQ,IAAI,WAAa,iBAHkD,GAKvE"}
@@ -0,0 +1,2 @@
1
+ import{useCallback as e,useRef as t,useSyncExternalStore as n}from"react";function r(r,i,a){let o=t(0),s=e(e=>i(t=>{r.current.has(a(t))&&(o.current++,e())}),[i,a,r]),c=e(()=>o.current,[]);n(s,c,c)}const i=process.env.NODE_ENV===`production`?()=>{}:r;export{i as useSubscribeToTrackedLookups};
2
+ //# sourceMappingURL=useSubscribeToTrackedLookups.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSubscribeToTrackedLookups.mjs","names":[],"sources":["../../../src/hooks/external-store/useSubscribeToTrackedLookups.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport type { StoreListener, Unsubscribe } from '../../i18n-store/storeTypes';\n\ntype UseSubscribeToTrackedLookups = <L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) => void;\n\n/**\n * Subscribe to store events, but only trigger re-renders when the event's\n * lookup is in the tracked keys set. Shared by the tracked translation and\n * dictionary resolvers, which differ only in the store subscribe method and the\n * listener-key function.\n *\n * Remember that we can make no assumptions about when the tracked set gets\n * updated. This is technically not pure, but it is an acceptable trade since it\n * only drives dev translation hot reload.\n */\nfunction useSubscribeToTrackedLookupsDev<L>(\n trackedKeysRef: RefObject<Set<string> | null>,\n subscribeToEvents: (onEvent: (lookup: L) => void) => Unsubscribe,\n getListenerKey: (lookup: L) => string\n) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return subscribeToEvents((lookup) => {\n if (!trackedKeysRef.current!.has(getListenerKey(lookup))) return;\n versionRef.current++;\n listener();\n });\n },\n [subscribeToEvents, getListenerKey, trackedKeysRef]\n );\n const getSnapshot = useCallback(() => versionRef.current, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nconst useSubscribeToTrackedLookupsProd: UseSubscribeToTrackedLookups = () => {};\n\nexport const useSubscribeToTrackedLookups: UseSubscribeToTrackedLookups =\n process.env.NODE_ENV === 'production'\n ? useSubscribeToTrackedLookupsProd\n : useSubscribeToTrackedLookupsDev;\n"],"mappings":"0EAwBA,SAAS,EACP,EACA,EACA,EACA,CAEA,IAAM,EAAa,EAAO,EAAE,CACtB,EAAY,EACf,GACQ,EAAmB,GAAW,CAC9B,EAAe,QAAS,IAAI,EAAe,EAAO,CAAC,GACxD,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAmB,EAAgB,EAAe,CACpD,CACK,EAAc,MAAkB,EAAW,QAAS,EAAE,CAAC,CAE7D,EAAqB,EAAW,EAAa,EAAY,CAK3D,MAAa,EACX,QAAQ,IAAI,WAAa,iBAHkD,GAKvE"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`);let n=require(`react`),r=require(`gt-i18n/internal`);function i(){let i=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryObject(),l=(0,n.useRef)(null);return l.current??=new Set,a(l),(0,n.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryObjectSnapshot(e,i);return n==null&&s&&c(e),n},[o,i,s,c])}function a(t){let i=(0,n.useRef)(0),a=e.useI18nStore(),o=(0,n.useCallback)(e=>a.subscribeToDictionaryObjectEvents(n=>{let a=(0,r.getDictionaryListenerKey)(n);t.current.has(a)&&(i.current++,e())}),[a]),s=(0,n.useCallback)(()=>i.current,[]);(0,n.useSyncExternalStore)(o,s,s)}exports.useTrackedDictionaryObjResolver=i;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(){let a=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryObject(),l=(0,i.useRef)(null);return l.current??=new Set,n.useSubscribeToTrackedLookups(l,o.subscribeToDictionaryObjectEvents,r.getDictionaryListenerKey),(0,i.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryObjectSnapshot(e,a);return n==null&&s&&c(e),n},[o,a,s,c])}exports.useTrackedDictionaryObjResolver=a;
2
2
  //# sourceMappingURL=useTrackedDictionaryObjResolver.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryObjResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryObject"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled = getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToLookups(trackedKeysRef);\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n ]\n );\n}\n\nfunction useSubscribeToLookups(trackedKeysRef: RefObject<Set<string> | null>) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const i18nStore = useI18nStore();\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return i18nStore.subscribeToDictionaryObjectEvents((lookup) => {\n const key = getDictionaryListenerKey(lookup);\n if (!trackedKeysRef.current!.has(key)) return;\n versionRef.current++;\n listener();\n });\n },\n [i18nStore]\n );\n const getSnapshot = useCallback(() => {\n return versionRef.current;\n }, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"mappings":"wMAuBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,GAAA,EAAA,EAAA,gBAAqC,CAAC,uBAAuB,CAC7D,EAAyBC,EAAAA,kCAAkC,CAE3D,GAAA,EAAA,EAAA,QAA4C,KAAK,CASvD,MARA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAsB,EAAe,EAGrC,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAET,CACE,EACA,EACA,EACA,EACD,CACF,CAGH,SAAS,EAAsB,EAA+C,CAE5E,IAAM,GAAA,EAAA,EAAA,QAAoB,EAAE,CACtB,EAAYD,EAAAA,cAAc,CAC1B,GAAA,EAAA,EAAA,aACH,GACQ,EAAU,kCAAmC,GAAW,CAC7D,IAAM,GAAA,EAAA,EAAA,0BAA+B,EAAO,CACvC,EAAe,QAAS,IAAI,EAAI,GACrC,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAU,CACZ,CACK,GAAA,EAAA,EAAA,iBACG,EAAW,QACjB,EAAE,CAAC,EAEN,EAAA,EAAA,sBAAqB,EAAW,EAAa,EAAY"}
1
+ {"version":3,"file":"useTrackedDictionaryObjResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryObject","getDictionaryListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary object updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryObjectEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n ]\n );\n}\n"],"mappings":"wPAkBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAyBC,EAAAA,kCAAkC,CAE3D,GAAA,EAAA,EAAA,QAA4C,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAA,6BACE,EACA,EAAU,kCACVC,EAAAA,yBACD,EAGD,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
@@ -1,2 +1,2 @@
1
- import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryObject as n}from"../utils/missing-translation.mjs";import{useCallback as r,useRef as i,useSyncExternalStore as a}from"react";import{getDictionaryListenerKey as o,getI18nConfig as s}from"gt-i18n/internal";function c(){let a=e(),c=t(),u=s().isDevHotReloadEnabled(),d=n(),f=i(null);return f.current??=new Set,l(f),r(e=>{let t=o(e);u&&f.current.add(t);let n=c.getDictionaryObjectSnapshot(e,a);return n==null&&u&&d(e),n},[c,a,u,d])}function l(e){let n=i(0),s=t(),c=r(t=>s.subscribeToDictionaryObjectEvents(r=>{let i=o(r);e.current.has(i)&&(n.current++,t())}),[s]),l=r(()=>n.current,[]);a(c,l,l)}export{c as useTrackedDictionaryObjResolver};
1
+ import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryObject as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{getDictionaryListenerKey as i,getI18nConfig as a}from"gt-i18n/internal";import{useCallback as o,useRef as s}from"react";function c(){let c=e(),l=t(),u=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),d=n(),f=s(null);return f.current??=new Set,r(f,l.subscribeToDictionaryObjectEvents,i),o(e=>{let t=i(e);u&&f.current.add(t);let n=l.getDictionaryObjectSnapshot(e,c);return n==null&&u&&d(e),n},[l,c,u,d])}export{c as useTrackedDictionaryObjResolver};
2
2
  //# sourceMappingURL=useTrackedDictionaryObjResolver.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryObjResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n StoreListener,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport {\n type RefObject,\n useCallback,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled = getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToLookups(trackedKeysRef);\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n ]\n );\n}\n\nfunction useSubscribeToLookups(trackedKeysRef: RefObject<Set<string> | null>) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const i18nStore = useI18nStore();\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return i18nStore.subscribeToDictionaryObjectEvents((lookup) => {\n const key = getDictionaryListenerKey(lookup);\n if (!trackedKeysRef.current!.has(key)) return;\n versionRef.current++;\n listener();\n });\n },\n [i18nStore]\n );\n const getSnapshot = useCallback(() => {\n return versionRef.current;\n }, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"mappings":"2UAuBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EAAsB,GAAe,CAAC,uBAAuB,CAC7D,EAAyB,GAAkC,CAE3D,EAAiB,EAA2B,KAAK,CASvD,MARA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAsB,EAAe,CAG9B,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAET,CACE,EACA,EACA,EACA,EACD,CACF,CAGH,SAAS,EAAsB,EAA+C,CAE5E,IAAM,EAAa,EAAO,EAAE,CACtB,EAAY,GAAc,CAC1B,EAAY,EACf,GACQ,EAAU,kCAAmC,GAAW,CAC7D,IAAM,EAAM,EAAyB,EAAO,CACvC,EAAe,QAAS,IAAI,EAAI,GACrC,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAU,CACZ,CACK,EAAc,MACX,EAAW,QACjB,EAAE,CAAC,CAEN,EAAqB,EAAW,EAAa,EAAY"}
1
+ {"version":3,"file":"useTrackedDictionaryObjResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport type {\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from '../../i18n-store/storeTypes';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryObj = useHandleMissingDictionaryObject();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary object updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryObjectEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryObject = i18nStore.getDictionaryObjectSnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryObject == null && devHotReloadEnabled) {\n onMissingDictionaryObj(lookup);\n }\n\n return dictionaryObject;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n ]\n );\n}\n"],"mappings":"mYAkBA,SAAgB,GAAgE,CAC9E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAAyB,GAAkC,CAE3D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EACE,EACA,EAAU,kCACV,EACD,CAGM,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAU,4BACjC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`);let n=require(`react`),r=require(`gt-i18n/internal`);function i(){let i=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryEntry(),l=(0,n.useRef)(null);return l.current??=new Set,a(l),(0,n.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryEntrySnapshot(e,i);return n==null&&s&&c(e),n},[o,i,s,c])}function a(t){let i=(0,n.useRef)(0),a=e.useI18nStore(),o=(0,n.useCallback)(e=>a.subscribeToDictionaryEntryEvents(n=>{let a=(0,r.getDictionaryListenerKey)(n);t.current.has(a)&&(i.current++,e())}),[a]),s=(0,n.useCallback)(()=>i.current,[]);(0,n.useSyncExternalStore)(o,s,s)}exports.useTrackedDictionaryResolver=i;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../i18n-store/useI18nStore.cjs`),t=require(`../utils/missing-translation.cjs`),n=require(`./useSubscribeToTrackedLookups.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a(){let a=e.useDictionariesSnapshot(),o=e.useI18nStore(),s=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),c=t.useHandleMissingDictionaryEntry(),l=(0,i.useRef)(null);return l.current??=new Set,n.useSubscribeToTrackedLookups(l,o.subscribeToDictionaryEntryEvents,r.getDictionaryListenerKey),(0,i.useCallback)(e=>{let t=(0,r.getDictionaryListenerKey)(e);s&&l.current.add(t);let n=o.getDictionaryEntrySnapshot(e,a);return n==null&&s&&c(e),n},[o,a,s,c])}exports.useTrackedDictionaryResolver=a;
2
2
  //# sourceMappingURL=useTrackedDictionaryResolver.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryEntry"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n StoreListener,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useSyncExternalStore } from 'react';\nimport type { RefObject } from 'react';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled = getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToLookups(trackedKeysRef);\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n ]\n );\n}\n\nfunction useSubscribeToLookups(trackedKeysRef: RefObject<Set<string> | null>) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const i18nStore = useI18nStore();\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return i18nStore.subscribeToDictionaryEntryEvents((lookup) => {\n const key = getDictionaryListenerKey(lookup);\n if (!trackedKeysRef.current!.has(key)) return;\n versionRef.current++;\n listener();\n });\n },\n [i18nStore]\n );\n const getSnapshot = useCallback(() => {\n return versionRef.current;\n }, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"mappings":"wMAoBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,GAAA,EAAA,EAAA,gBAAqC,CAAC,uBAAuB,CAC7D,EAA2BC,EAAAA,iCAAiC,CAE5D,GAAA,EAAA,EAAA,QAA4C,KAAK,CASvD,MARA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAsB,EAAe,EAGrC,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAET,CACE,EACA,EACA,EACA,EACD,CACF,CAGH,SAAS,EAAsB,EAA+C,CAE5E,IAAM,GAAA,EAAA,EAAA,QAAoB,EAAE,CACtB,EAAYD,EAAAA,cAAc,CAC1B,GAAA,EAAA,EAAA,aACH,GACQ,EAAU,iCAAkC,GAAW,CAC5D,IAAM,GAAA,EAAA,EAAA,0BAA+B,EAAO,CACvC,EAAe,QAAS,IAAI,EAAI,GACrC,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAU,CACZ,CACK,GAAA,EAAA,EAAA,iBACG,EAAW,QACjB,EAAE,CAAC,EAEN,EAAA,EAAA,sBAAqB,EAAW,EAAa,EAAY"}
1
+ {"version":3,"file":"useTrackedDictionaryResolver.cjs","names":["useDictionariesSnapshot","useI18nStore","useHandleMissingDictionaryEntry","getDictionaryListenerKey"],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryEntryEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n ]\n );\n}\n"],"mappings":"wPAkBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAA2BC,EAAAA,iCAAiC,CAE5D,GAAA,EAAA,EAAA,QAA4C,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAA,6BACE,EACA,EAAU,iCACVC,EAAAA,yBACD,EAGD,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
@@ -1,2 +1,2 @@
1
- import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryEntry as n}from"../utils/missing-translation.mjs";import{useCallback as r,useRef as i,useSyncExternalStore as a}from"react";import{getDictionaryListenerKey as o,getI18nConfig as s}from"gt-i18n/internal";function c(){let a=e(),c=t(),u=s().isDevHotReloadEnabled(),d=n(),f=i(null);return f.current??=new Set,l(f),r(e=>{let t=o(e);u&&f.current.add(t);let n=c.getDictionaryEntrySnapshot(e,a);return n==null&&u&&d(e),n},[c,a,u,d])}function l(e){let n=i(0),s=t(),c=r(t=>s.subscribeToDictionaryEntryEvents(r=>{let i=o(r);e.current.has(i)&&(n.current++,t())}),[s]),l=r(()=>n.current,[]);a(c,l,l)}export{c as useTrackedDictionaryResolver};
1
+ import{useDictionariesSnapshot as e,useI18nStore as t}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingDictionaryEntry as n}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as r}from"./useSubscribeToTrackedLookups.mjs";import{getDictionaryListenerKey as i,getI18nConfig as a}from"gt-i18n/internal";import{useCallback as o,useRef as s}from"react";function c(){let c=e(),l=t(),u=process.env.NODE_ENV!==`production`&&a().isDevHotReloadEnabled(),d=n(),f=s(null);return f.current??=new Set,r(f,l.subscribeToDictionaryEntryEvents,i),o(e=>{let t=i(e);u&&f.current.add(t);let n=l.getDictionaryEntrySnapshot(e,c);return n==null&&u&&d(e),n},[l,c,u,d])}export{c as useTrackedDictionaryResolver};
2
2
  //# sourceMappingURL=useTrackedDictionaryResolver.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedDictionaryResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n StoreListener,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useSyncExternalStore } from 'react';\nimport type { RefObject } from 'react';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled = getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToLookups(trackedKeysRef);\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n ]\n );\n}\n\nfunction useSubscribeToLookups(trackedKeysRef: RefObject<Set<string> | null>) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const i18nStore = useI18nStore();\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return i18nStore.subscribeToDictionaryEntryEvents((lookup) => {\n const key = getDictionaryListenerKey(lookup);\n if (!trackedKeysRef.current!.has(key)) return;\n versionRef.current++;\n listener();\n });\n },\n [i18nStore]\n );\n const getSnapshot = useCallback(() => {\n return versionRef.current;\n }, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"mappings":"0UAoBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EAAsB,GAAe,CAAC,uBAAuB,CAC7D,EAA2B,GAAiC,CAE5D,EAAiB,EAA2B,KAAK,CASvD,MARA,CACE,EAAe,UAAU,IAAI,IAI/B,EAAsB,EAAe,CAG9B,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAET,CACE,EACA,EACA,EACA,EACD,CACF,CAGH,SAAS,EAAsB,EAA+C,CAE5E,IAAM,EAAa,EAAO,EAAE,CACtB,EAAY,GAAc,CAC1B,EAAY,EACf,GACQ,EAAU,iCAAkC,GAAW,CAC5D,IAAM,EAAM,EAAyB,EAAO,CACvC,EAAe,QAAS,IAAI,EAAI,GACrC,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAU,CACZ,CACK,EAAc,MACX,EAAW,QACjB,EAAE,CAAC,CAEN,EAAqB,EAAW,EAAa,EAAY"}
1
+ {"version":3,"file":"useTrackedDictionaryResolver.mjs","names":[],"sources":["../../../src/hooks/external-store/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport {\n useDictionariesSnapshot,\n useI18nStore,\n} from '../../i18n-store/useI18nStore';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n} from '../../i18n-store/storeTypes';\nimport { getDictionaryListenerKey, getI18nConfig } from 'gt-i18n/internal';\nimport { useHandleMissingDictionaryEntry } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\nexport type TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const dictionariesSnapshot = useDictionariesSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingDictionaryEntry = useHandleMissingDictionaryEntry();\n\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // subscribe to dictionary entry updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToDictionaryEntryEvents,\n getDictionaryListenerKey\n );\n\n // Resolution callback\n return useCallback(\n (lookup: DictionaryLookup) => {\n // Track the lookup for dev hot reload\n const lookupKey = getDictionaryListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the dictionary entry from the store\n const dictionaryEntry = i18nStore.getDictionaryEntrySnapshot(\n lookup,\n dictionariesSnapshot\n );\n\n // Hot reload\n if (dictionaryEntry == null && devHotReloadEnabled) {\n onMissingDictionaryEntry(lookup);\n }\n\n return dictionaryEntry;\n },\n [\n i18nStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n ]\n );\n}\n"],"mappings":"kYAkBA,SAAgB,GAA+D,CAC7E,IAAM,EAAuB,GAAyB,CAChD,EAAY,GAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAA2B,GAAiC,CAE5D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAI/B,EACE,EACA,EAAU,iCACV,EACD,CAGM,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAU,2BAChC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAET,CACE,EACA,EACA,EACA,EACD,CACF"}
@@ -1,2 +1,2 @@
1
- require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../condition-store.cjs`),t=require(`../utils.cjs`),n=require(`../../i18n-store/useI18nStore.cjs`),r=require(`../utils/missing-translation.cjs`);let i=require(`react`),a=require(`gt-i18n/internal`);function o(e=[]){let t=n.useTranslationsSnapshot(),o=n.useI18nStore(),l=(0,a.getI18nConfig)().isDevHotReloadEnabled(),u=r.useHandleMissingTranslation(),d=(0,i.useRef)(null);return d.current??=new Set,c(e,d),s(d),(0,i.useCallback)(e=>{let n=(0,a.getTranslateListenerKey)(e);l&&d.current.add(n);let r=o.getTranslateSnapshot(e,t);return r==null&&l&&u(e),r},[o,t,u,l])}function s(e){let t=(0,i.useRef)(0),r=n.useI18nStore(),o=(0,i.useCallback)(n=>r.subscribeToTranslationEvents(r=>{let i=(0,a.getTranslateListenerKey)(r);e.current.has(i)&&(t.current++,n())}),[r]),s=(0,i.useCallback)(()=>t.current,[]);(0,i.useSyncExternalStore)(o,s,s)}function c(r,o){let s=n.useI18nStore(),c=e.useLocale(),l=(0,a.getI18nConfig)().isDevHotReloadEnabled(),u=t.useShouldTranslate(),d=n.useTranslationsSnapshot(),f=(0,i.useMemo)(()=>r?.length>0&&u&&l,[r,u,l]),p=(0,i.useMemo)(()=>f?r.map(({message:e,...t})=>{let n=t.$locale??c,r={locale:n,message:e,options:(0,a.createLookupOptions)(n,t,`ICU`)};return[r,(0,a.getTranslateListenerKey)(r)]}):[],[c,f,r]);f&&p.forEach(([,e])=>{o.current.add(e)}),(0,i.useEffect)(()=>{f&&p.filter(([e])=>s.getTranslateSnapshot(e,d)==null).forEach(([e])=>s.translate(e))},[f,s,p,d])}exports.useTrackedTranslationResolver=o;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../condition-store.cjs`),t=require(`../utils.cjs`),n=require(`../../i18n-store/useI18nStore.cjs`),r=require(`../utils/missing-translation.cjs`),i=require(`./useSubscribeToTrackedLookups.cjs`);let a=require(`gt-i18n/internal`),o=require(`react`);function s(e=[]){let t=n.useTranslationsSnapshot(),s=n.useI18nStore(),l=process.env.NODE_ENV!==`production`&&(0,a.getI18nConfig)().isDevHotReloadEnabled(),u=r.useHandleMissingTranslation(),d=(0,o.useRef)(null);return d.current??=new Set,c(e,d),i.useSubscribeToTrackedLookups(d,s.subscribeToTranslationEvents,a.getTranslateListenerKey),(0,o.useCallback)(e=>{let n=(0,a.getTranslateListenerKey)(e);l&&d.current.add(n);let r=s.getTranslateSnapshot(e,t);return r==null&&l&&u(e),r},[s,t,u,l])}function c(r,i){let s=n.useI18nStore(),c=e.useLocale(),l=process.env.NODE_ENV!==`production`&&(0,a.getI18nConfig)().isDevHotReloadEnabled(),u=t.useShouldTranslate(),d=n.useTranslationsSnapshot(),f=(0,o.useMemo)(()=>r?.length>0&&u&&l,[r,u,l]),p=(0,o.useMemo)(()=>f?r.map(({message:e,...t})=>{let n=t.$locale??c,r={locale:n,message:e,options:(0,a.createLookupOptions)(n,t,`ICU`)};return[r,(0,a.getTranslateListenerKey)(r)]}):[],[c,f,r]);f&&p.forEach(([,e])=>{i.current.add(e)}),(0,o.useEffect)(()=>{f&&p.filter(([e])=>s.getTranslateSnapshot(e,d)==null).forEach(([e])=>s.translate(e))},[f,s,p,d])}exports.useTrackedTranslationResolver=s;
2
2
  //# sourceMappingURL=useTrackedTranslationResolver.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedTranslationResolver.cjs","names":["useTranslationsSnapshot","useI18nStore","useHandleMissingTranslation","useLocale","useShouldTranslate"],"sources":["../../../src/hooks/external-store/useTrackedTranslationResolver.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport {\n createLookupOptions,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport type { Translation } from 'gt-i18n/types';\nimport type {\n StoreListener,\n TranslateLookup,\n TranslateSnapshot,\n} from '../../i18n-store/storeTypes';\nimport type { TranslationMetadata } from 'gt-i18n/internal/types';\nimport type { StringFormat } from '@generaltranslation/format';\nimport { useLocale } from '../condition-store';\nimport { useShouldTranslate } from '../utils';\nimport {\n useI18nStore,\n useTranslationsSnapshot,\n} from '../../i18n-store/useI18nStore';\nimport { useHandleMissingTranslation } from '../utils/missing-translation';\n\n/**\n * Returns the translation, but also triggers a translation if it is not found\n * when dev hot reload is enabled.\n */\nexport type TrackedTranslationResolver = <T extends Translation>(\n lookup: TranslateLookup<T>\n) => TranslateSnapshot<T>;\n\nexport type Message = TranslationMetadata & {\n message: string;\n};\n\n/**\n * NOTE:\n * gt() may be called during render, so tracking intentionally only mutates\n * hook-local refs. This widens the event filter used by our existing\n * useSyncExternalStore subscription, but does not update React state or mutate\n * the translation cache during render.\n *\n * A render that is later aborted may leave behind an extra tracked key. That is\n * acceptable for dev hot reload because the worst case is an unnecessary\n * invalidation for this hook instance, not incorrect rendered output.\n */\n\nexport function useTrackedTranslationResolver(\n messages: Message[] = []\n): TrackedTranslationResolver {\n const translationsSnapshot = useTranslationsSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled = getI18nConfig().isDevHotReloadEnabled();\n const onMissingTranslation = useHandleMissingTranslation();\n\n /**\n * Track lookups per hook instance without updating React state during render.\n */\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // (optimization) Pre-subscribe to compiler-injected lookups\n usePreloadCompilerLookups(messages, trackedKeysRef);\n\n // (tx hot reload) Subscribe to translation updates\n useSubscribeToLookups(trackedKeysRef);\n\n /**\n * Remember that we can make no assumptions about when this cb gets invoked\n * - Resolves translation from lookup\n * - enqueues dev hot reload (if needed)\n */\n return useCallback(\n <T extends Translation>(\n lookup: TranslateLookup<T>\n ): TranslateSnapshot<T> => {\n // Track the lookup for dev hot reload\n const lookupKey = getTranslateListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the translation from the store\n const translation = i18nStore.getTranslateSnapshot(\n lookup,\n translationsSnapshot\n );\n\n // Trigger a hot reload if the translation is not found\n if (translation == null && devHotReloadEnabled) {\n onMissingTranslation(lookup);\n }\n return translation;\n },\n [i18nStore, translationsSnapshot, onMissingTranslation, devHotReloadEnabled]\n );\n}\n\n/**\n * Subscribe to translation updates, but only trigger re-renders\n * if the lookup is in the tracked keys. Remember that we can make\n * no assumptions about when this list gets updated. Technically,\n * not pure, but this is an acceptable trade since this is\n * really just for translation hot reload.\n *\n * TODO: (separate PR) we can probably do better filtering for adding to the set since this is primarily dev only\n * TODO: reduce code duplication with the other two useSubscribeToLookups functions\n */\nfunction useSubscribeToLookups(trackedKeysRef: RefObject<Set<string> | null>) {\n // invalidation counter for triggering updates\n const versionRef = useRef(0);\n const i18nStore = useI18nStore();\n const subscribe = useCallback(\n (listener: StoreListener) => {\n return i18nStore.subscribeToTranslationEvents((lookup) => {\n const key = getTranslateListenerKey(lookup);\n if (!trackedKeysRef.current!.has(key)) return;\n versionRef.current++;\n listener();\n });\n },\n [i18nStore]\n );\n const getSnapshot = useCallback(() => {\n return versionRef.current;\n }, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/**\n * Pre-subscribe to compiler-injected lookups\n * trigger translations for them\n *\n * This ref mutation is safe because this is translation hot reload only\n * and effects are deterministic\n */\nfunction usePreloadCompilerLookups(\n messages: Message[],\n trackedKeysRef: RefObject<Set<string> | null>\n) {\n const i18nStore = useI18nStore();\n const locale = useLocale();\n const devHotReloadEnabled = getI18nConfig().isDevHotReloadEnabled();\n const shouldTranslate = useShouldTranslate();\n const translationsSnapshot = useTranslationsSnapshot();\n const txHotReloadEnabled = useMemo(() => {\n return messages?.length > 0 && shouldTranslate && devHotReloadEnabled;\n }, [messages, shouldTranslate, devHotReloadEnabled]);\n\n // Precompute as much as we can\n const lookups: [TranslateLookup<string>, string][] = useMemo(() => {\n if (!txHotReloadEnabled) return [];\n return messages.map(({ message, ...options }) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n const lookup = {\n locale: targetLocale,\n message,\n options: lookupOptions,\n };\n return [lookup, getTranslateListenerKey(lookup)];\n });\n }, [locale, txHotReloadEnabled, messages]);\n\n // Pre-subscribe to the lookups\n if (txHotReloadEnabled) {\n lookups.forEach(([, lookupKey]) => {\n trackedKeysRef.current!.add(lookupKey);\n });\n }\n\n /**\n * Delegate non-pure operations to post commit\n *\n * (Optimization) Trigger a hot reload if the translation is not found\n * for compiler-injected lookups\n *\n * TODO: for use() + suspense strategy, use a Promise.all()\n * TODO: server side translation invocation\n */\n useEffect(() => {\n if (!txHotReloadEnabled) return;\n\n lookups\n .filter(\n ([lookup]) =>\n i18nStore.getTranslateSnapshot(lookup, translationsSnapshot) == null\n )\n .forEach(([lookup]) => i18nStore.translate(lookup));\n }, [txHotReloadEnabled, i18nStore, lookups, translationsSnapshot]);\n}\n"],"mappings":"sQAqDA,SAAgB,EACd,EAAsB,EAAE,CACI,CAC5B,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,GAAA,EAAA,EAAA,gBAAqC,CAAC,uBAAuB,CAC7D,EAAuBC,EAAAA,6BAA6B,CAKpD,GAAA,EAAA,EAAA,QAA4C,KAAK,CAgBvD,MAfA,CACE,EAAe,UAAU,IAAI,IAI/B,EAA0B,EAAU,EAAe,CAGnD,EAAsB,EAAe,EAOrC,EAAA,EAAA,aAEI,GACyB,CAEzB,IAAM,GAAA,EAAA,EAAA,yBAAoC,EAAO,CAC7C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAc,EAAU,qBAC5B,EACA,EACD,CAMD,OAHI,GAAe,MAAQ,GACzB,EAAqB,EAAO,CAEvB,GAET,CAAC,EAAW,EAAsB,EAAsB,EAAoB,CAC7E,CAaH,SAAS,EAAsB,EAA+C,CAE5E,IAAM,GAAA,EAAA,EAAA,QAAoB,EAAE,CACtB,EAAYD,EAAAA,cAAc,CAC1B,GAAA,EAAA,EAAA,aACH,GACQ,EAAU,6BAA8B,GAAW,CACxD,IAAM,GAAA,EAAA,EAAA,yBAA8B,EAAO,CACtC,EAAe,QAAS,IAAI,EAAI,GACrC,EAAW,UACX,GAAU,GACV,CAEJ,CAAC,EAAU,CACZ,CACK,GAAA,EAAA,EAAA,iBACG,EAAW,QACjB,EAAE,CAAC,EAEN,EAAA,EAAA,sBAAqB,EAAW,EAAa,EAAY,CAU3D,SAAS,EACP,EACA,EACA,CACA,IAAM,EAAYA,EAAAA,cAAc,CAC1B,EAASE,EAAAA,WAAW,CACpB,GAAA,EAAA,EAAA,gBAAqC,CAAC,uBAAuB,CAC7D,EAAkBC,EAAAA,oBAAoB,CACtC,EAAuBJ,EAAAA,yBAAyB,CAChD,GAAA,EAAA,EAAA,aACG,GAAU,OAAS,GAAK,GAAmB,EACjD,CAAC,EAAU,EAAiB,EAAoB,CAAC,CAG9C,GAAA,EAAA,EAAA,aACC,EACE,EAAS,KAAK,CAAE,UAAS,GAAG,KAAc,CAC/C,IAAM,EAAe,EAAQ,SAAW,EAMlC,EAAS,CACb,OAAQ,EACR,UACA,SAAA,EAAA,EAAA,qBAPA,EACA,EACA,MAKsB,CACvB,CACD,MAAO,CAAC,GAAA,EAAA,EAAA,yBAAgC,EAAO,CAAC,EAChD,CAd8B,EAAE,CAejC,CAAC,EAAQ,EAAoB,EAAS,CAAC,CAGtC,GACF,EAAQ,SAAS,EAAG,KAAe,CACjC,EAAe,QAAS,IAAI,EAAU,EACtC,EAYJ,EAAA,EAAA,eAAgB,CACT,GAEL,EACG,QACE,CAAC,KACA,EAAU,qBAAqB,EAAQ,EAAqB,EAAI,KACnE,CACA,SAAS,CAAC,KAAY,EAAU,UAAU,EAAO,CAAC,EACpD,CAAC,EAAoB,EAAW,EAAS,EAAqB,CAAC"}
1
+ {"version":3,"file":"useTrackedTranslationResolver.cjs","names":["useTranslationsSnapshot","useI18nStore","useHandleMissingTranslation","getTranslateListenerKey","useLocale","useShouldTranslate"],"sources":["../../../src/hooks/external-store/useTrackedTranslationResolver.ts"],"sourcesContent":["import { type RefObject, useCallback, useEffect, useMemo, useRef } from 'react';\nimport {\n createLookupOptions,\n getI18nConfig,\n getTranslateListenerKey,\n} from 'gt-i18n/internal';\nimport type { Translation } from 'gt-i18n/types';\nimport type {\n TranslateLookup,\n TranslateSnapshot,\n} from '../../i18n-store/storeTypes';\nimport type { TranslationMetadata } from 'gt-i18n/internal/types';\nimport type { StringFormat } from '@generaltranslation/format';\nimport { useLocale } from '../condition-store';\nimport { useShouldTranslate } from '../utils';\nimport {\n useI18nStore,\n useTranslationsSnapshot,\n} from '../../i18n-store/useI18nStore';\nimport { useHandleMissingTranslation } from '../utils/missing-translation';\nimport { useSubscribeToTrackedLookups } from './useSubscribeToTrackedLookups';\n\n/**\n * Returns the translation, but also triggers a translation if it is not found\n * when dev hot reload is enabled.\n */\nexport type TrackedTranslationResolver = <T extends Translation>(\n lookup: TranslateLookup<T>\n) => TranslateSnapshot<T>;\n\nexport type Message = TranslationMetadata & {\n message: string;\n};\n\n/**\n * NOTE:\n * gt() may be called during render, so tracking intentionally only mutates\n * hook-local refs. This widens the event filter used by our existing\n * useSyncExternalStore subscription, but does not update React state or mutate\n * the translation cache during render.\n *\n * A render that is later aborted may leave behind an extra tracked key. That is\n * acceptable for dev hot reload because the worst case is an unnecessary\n * invalidation for this hook instance, not incorrect rendered output.\n */\n\nexport function useTrackedTranslationResolver(\n messages: Message[] = []\n): TrackedTranslationResolver {\n const translationsSnapshot = useTranslationsSnapshot();\n const i18nStore = useI18nStore();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const onMissingTranslation = useHandleMissingTranslation();\n\n /**\n * Track lookups per hook instance without updating React state during render.\n */\n const trackedKeysRef = useRef<Set<string> | null>(null);\n if (trackedKeysRef.current == null) {\n trackedKeysRef.current = new Set();\n }\n\n // (optimization) Pre-subscribe to compiler-injected lookups\n usePreloadCompilerLookups(messages, trackedKeysRef);\n\n // (tx hot reload) Subscribe to translation updates\n useSubscribeToTrackedLookups(\n trackedKeysRef,\n i18nStore.subscribeToTranslationEvents,\n getTranslateListenerKey\n );\n\n /**\n * Remember that we can make no assumptions about when this cb gets invoked\n * - Resolves translation from lookup\n * - enqueues dev hot reload (if needed)\n */\n return useCallback(\n <T extends Translation>(\n lookup: TranslateLookup<T>\n ): TranslateSnapshot<T> => {\n // Track the lookup for dev hot reload\n const lookupKey = getTranslateListenerKey(lookup);\n if (devHotReloadEnabled) {\n trackedKeysRef.current!.add(lookupKey);\n }\n\n // Resolve the translation from the store\n const translation = i18nStore.getTranslateSnapshot(\n lookup,\n translationsSnapshot\n );\n\n // Trigger a hot reload if the translation is not found\n if (translation == null && devHotReloadEnabled) {\n onMissingTranslation(lookup);\n }\n return translation;\n },\n [i18nStore, translationsSnapshot, onMissingTranslation, devHotReloadEnabled]\n );\n}\n\n/**\n * Pre-subscribe to compiler-injected lookups\n * trigger translations for them\n *\n * This ref mutation is safe because this is translation hot reload only\n * and effects are deterministic\n */\nfunction usePreloadCompilerLookups(\n messages: Message[],\n trackedKeysRef: RefObject<Set<string> | null>\n) {\n const i18nStore = useI18nStore();\n const locale = useLocale();\n const devHotReloadEnabled =\n process.env.NODE_ENV !== 'production' &&\n getI18nConfig().isDevHotReloadEnabled();\n const shouldTranslate = useShouldTranslate();\n const translationsSnapshot = useTranslationsSnapshot();\n const txHotReloadEnabled = useMemo(() => {\n return messages?.length > 0 && shouldTranslate && devHotReloadEnabled;\n }, [messages, shouldTranslate, devHotReloadEnabled]);\n\n // Precompute as much as we can\n const lookups: [TranslateLookup<string>, string][] = useMemo(() => {\n if (!txHotReloadEnabled) return [];\n return messages.map(({ message, ...options }) => {\n const targetLocale = options.$locale ?? locale;\n const lookupOptions = createLookupOptions<StringFormat>(\n targetLocale,\n options,\n 'ICU'\n );\n const lookup = {\n locale: targetLocale,\n message,\n options: lookupOptions,\n };\n return [lookup, getTranslateListenerKey(lookup)];\n });\n }, [locale, txHotReloadEnabled, messages]);\n\n // Pre-subscribe to the lookups\n if (txHotReloadEnabled) {\n lookups.forEach(([, lookupKey]) => {\n trackedKeysRef.current!.add(lookupKey);\n });\n }\n\n /**\n * Delegate non-pure operations to post commit\n *\n * (Optimization) Trigger a hot reload if the translation is not found\n * for compiler-injected lookups\n *\n * TODO: for use() + suspense strategy, use a Promise.all()\n * TODO: server side translation invocation\n */\n useEffect(() => {\n if (!txHotReloadEnabled) return;\n\n lookups\n .filter(\n ([lookup]) =>\n i18nStore.getTranslateSnapshot(lookup, translationsSnapshot) == null\n )\n .forEach(([lookup]) => i18nStore.translate(lookup));\n }, [txHotReloadEnabled, i18nStore, lookups, translationsSnapshot]);\n}\n"],"mappings":"sTA8CA,SAAgB,EACd,EAAsB,EAAE,CACI,CAC5B,IAAM,EAAuBA,EAAAA,yBAAyB,CAChD,EAAYC,EAAAA,cAAc,CAC1B,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAuBC,EAAAA,6BAA6B,CAKpD,GAAA,EAAA,EAAA,QAA4C,KAAK,CAoBvD,MAnBA,CACE,EAAe,UAAU,IAAI,IAI/B,EAA0B,EAAU,EAAe,CAGnD,EAAA,6BACE,EACA,EAAU,6BACVC,EAAAA,wBACD,EAOD,EAAA,EAAA,aAEI,GACyB,CAEzB,IAAM,GAAA,EAAA,EAAA,yBAAoC,EAAO,CAC7C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAc,EAAU,qBAC5B,EACA,EACD,CAMD,OAHI,GAAe,MAAQ,GACzB,EAAqB,EAAO,CAEvB,GAET,CAAC,EAAW,EAAsB,EAAsB,EAAoB,CAC7E,CAUH,SAAS,EACP,EACA,EACA,CACA,IAAM,EAAYF,EAAAA,cAAc,CAC1B,EAASG,EAAAA,WAAW,CACpB,EACJ,QAAQ,IAAI,WAAa,eAAA,EAAA,EAAA,gBACV,CAAC,uBAAuB,CACnC,EAAkBC,EAAAA,oBAAoB,CACtC,EAAuBL,EAAAA,yBAAyB,CAChD,GAAA,EAAA,EAAA,aACG,GAAU,OAAS,GAAK,GAAmB,EACjD,CAAC,EAAU,EAAiB,EAAoB,CAAC,CAG9C,GAAA,EAAA,EAAA,aACC,EACE,EAAS,KAAK,CAAE,UAAS,GAAG,KAAc,CAC/C,IAAM,EAAe,EAAQ,SAAW,EAMlC,EAAS,CACb,OAAQ,EACR,UACA,SAAA,EAAA,EAAA,qBAPA,EACA,EACA,MAKsB,CACvB,CACD,MAAO,CAAC,GAAA,EAAA,EAAA,yBAAgC,EAAO,CAAC,EAChD,CAd8B,EAAE,CAejC,CAAC,EAAQ,EAAoB,EAAS,CAAC,CAGtC,GACF,EAAQ,SAAS,EAAG,KAAe,CACjC,EAAe,QAAS,IAAI,EAAU,EACtC,EAYJ,EAAA,EAAA,eAAgB,CACT,GAEL,EACG,QACE,CAAC,KACA,EAAU,qBAAqB,EAAQ,EAAqB,EAAI,KACnE,CACA,SAAS,CAAC,KAAY,EAAU,UAAU,EAAO,CAAC,EACpD,CAAC,EAAoB,EAAW,EAAS,EAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useTrackedTranslationResolver.d.ts","names":[],"sources":["../../../src/hooks/external-store/useTrackedTranslationResolver.ts"],"mappings":";;;;KAqCY,OAAA,GAAU,mBAAA;EACpB,OAAA;AAAA"}
1
+ {"version":3,"file":"useTrackedTranslationResolver.d.ts","names":[],"sources":["../../../src/hooks/external-store/useTrackedTranslationResolver.ts"],"mappings":";;;;KA8BY,OAAA,GAAU,mBAAA;EACpB,OAAA;AAAA"}
@@ -1,2 +1,2 @@
1
- import{useLocale as e}from"../condition-store.mjs";import{useShouldTranslate as t}from"../utils.mjs";import{useI18nStore as n,useTranslationsSnapshot as r}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingTranslation as i}from"../utils/missing-translation.mjs";import{useCallback as a,useEffect as o,useMemo as s,useRef as c,useSyncExternalStore as l}from"react";import{createLookupOptions as u,getI18nConfig as d,getTranslateListenerKey as f}from"gt-i18n/internal";function p(e=[]){let t=r(),o=n(),s=d().isDevHotReloadEnabled(),l=i(),u=c(null);return u.current??=new Set,h(e,u),m(u),a(e=>{let n=f(e);s&&u.current.add(n);let r=o.getTranslateSnapshot(e,t);return r==null&&s&&l(e),r},[o,t,l,s])}function m(e){let t=c(0),r=n(),i=a(n=>r.subscribeToTranslationEvents(r=>{let i=f(r);e.current.has(i)&&(t.current++,n())}),[r]),o=a(()=>t.current,[]);l(i,o,o)}function h(i,a){let c=n(),l=e(),p=d().isDevHotReloadEnabled(),m=t(),h=r(),g=s(()=>i?.length>0&&m&&p,[i,m,p]),_=s(()=>g?i.map(({message:e,...t})=>{let n=t.$locale??l,r={locale:n,message:e,options:u(n,t,`ICU`)};return[r,f(r)]}):[],[l,g,i]);g&&_.forEach(([,e])=>{a.current.add(e)}),o(()=>{g&&_.filter(([e])=>c.getTranslateSnapshot(e,h)==null).forEach(([e])=>c.translate(e))},[g,c,_,h])}export{p as useTrackedTranslationResolver};
1
+ import{useLocale as e}from"../condition-store.mjs";import{useShouldTranslate as t}from"../utils.mjs";import{useI18nStore as n,useTranslationsSnapshot as r}from"../../i18n-store/useI18nStore.mjs";import{useHandleMissingTranslation as i}from"../utils/missing-translation.mjs";import{useSubscribeToTrackedLookups as a}from"./useSubscribeToTrackedLookups.mjs";import{createLookupOptions as o,getI18nConfig as s,getTranslateListenerKey as c}from"gt-i18n/internal";import{useCallback as l,useEffect as u,useMemo as d,useRef as f}from"react";function p(e=[]){let t=r(),o=n(),u=process.env.NODE_ENV!==`production`&&s().isDevHotReloadEnabled(),d=i(),p=f(null);return p.current??=new Set,m(e,p),a(p,o.subscribeToTranslationEvents,c),l(e=>{let n=c(e);u&&p.current.add(n);let r=o.getTranslateSnapshot(e,t);return r==null&&u&&d(e),r},[o,t,d,u])}function m(i,a){let l=n(),f=e(),p=process.env.NODE_ENV!==`production`&&s().isDevHotReloadEnabled(),m=t(),h=r(),g=d(()=>i?.length>0&&m&&p,[i,m,p]),_=d(()=>g?i.map(({message:e,...t})=>{let n=t.$locale??f,r={locale:n,message:e,options:o(n,t,`ICU`)};return[r,c(r)]}):[],[f,g,i]);g&&_.forEach(([,e])=>{a.current.add(e)}),u(()=>{g&&_.filter(([e])=>l.getTranslateSnapshot(e,h)==null).forEach(([e])=>l.translate(e))},[g,l,_,h])}export{p as useTrackedTranslationResolver};
2
2
  //# sourceMappingURL=useTrackedTranslationResolver.mjs.map