@generaltranslation/react-core 12.0.0-samsara.7 → 12.0.0-samsara.9

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 (270) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/dist/compat/CompatStore.cjs +2 -0
  3. package/dist/compat/CompatStore.cjs.map +1 -0
  4. package/dist/compat/CompatStore.d.ts +26 -0
  5. package/dist/compat/CompatStore.d.ts.map +1 -0
  6. package/dist/compat/CompatStore.mjs +2 -0
  7. package/dist/compat/CompatStore.mjs.map +1 -0
  8. package/dist/compat/DictionaryContext.cjs +2 -0
  9. package/dist/compat/DictionaryContext.cjs.map +1 -0
  10. package/dist/compat/DictionaryContext.mjs +2 -0
  11. package/dist/compat/DictionaryContext.mjs.map +1 -0
  12. package/dist/compat/DictionaryProvider.cjs +2 -0
  13. package/dist/compat/DictionaryProvider.cjs.map +1 -0
  14. package/dist/compat/DictionaryProvider.d.ts +29 -0
  15. package/dist/compat/DictionaryProvider.d.ts.map +1 -0
  16. package/dist/compat/DictionaryProvider.mjs +2 -0
  17. package/dist/compat/DictionaryProvider.mjs.map +1 -0
  18. package/dist/compat/dictionaries.cjs +2 -0
  19. package/dist/compat/dictionaries.cjs.map +1 -0
  20. package/dist/compat/dictionaries.mjs +2 -0
  21. package/dist/compat/dictionaries.mjs.map +1 -0
  22. package/dist/compat/missing-dictionary.cjs +2 -0
  23. package/dist/compat/missing-dictionary.cjs.map +1 -0
  24. package/dist/compat/missing-dictionary.mjs +2 -0
  25. package/dist/compat/missing-dictionary.mjs.map +1 -0
  26. package/dist/compat/types.d.ts +15 -0
  27. package/dist/compat/types.d.ts.map +1 -0
  28. package/dist/compat/useTrackedDictionaryObjResolver.cjs +2 -0
  29. package/dist/compat/useTrackedDictionaryObjResolver.cjs.map +1 -0
  30. package/dist/compat/useTrackedDictionaryObjResolver.mjs +2 -0
  31. package/dist/compat/useTrackedDictionaryObjResolver.mjs.map +1 -0
  32. package/dist/compat/useTrackedDictionaryResolver.cjs +2 -0
  33. package/dist/compat/useTrackedDictionaryResolver.cjs.map +1 -0
  34. package/dist/compat/useTrackedDictionaryResolver.mjs +2 -0
  35. package/dist/compat/useTrackedDictionaryResolver.mjs.map +1 -0
  36. package/dist/compat/useTranslations.cjs +2 -0
  37. package/dist/compat/useTranslations.cjs.map +1 -0
  38. package/dist/compat/useTranslations.d.ts +7 -0
  39. package/dist/compat/useTranslations.d.ts.map +1 -0
  40. package/dist/compat/useTranslations.mjs +2 -0
  41. package/dist/compat/useTranslations.mjs.map +1 -0
  42. package/dist/compat.cjs +1 -0
  43. package/dist/compat.d.mts +1 -0
  44. package/dist/compat.d.ts +4 -0
  45. package/dist/compat.mjs +1 -0
  46. package/dist/components/helpers/InternalLocaleSelector.cjs +1 -1
  47. package/dist/components/helpers/InternalLocaleSelector.cjs.map +1 -1
  48. package/dist/components/helpers/InternalLocaleSelector.d.ts +1 -6
  49. package/dist/components/helpers/InternalLocaleSelector.d.ts.map +1 -1
  50. package/dist/components/helpers/InternalLocaleSelector.mjs +1 -1
  51. package/dist/components/helpers/InternalLocaleSelector.mjs.map +1 -1
  52. package/dist/components/translation/T.rsc.cjs +1 -1
  53. package/dist/components/translation/T.rsc.cjs.map +1 -1
  54. package/dist/components/translation/T.rsc.mjs +1 -1
  55. package/dist/components/translation/T.rsc.mjs.map +1 -1
  56. package/dist/components/translation/Tx.rsc.cjs +1 -1
  57. package/dist/components/translation/Tx.rsc.cjs.map +1 -1
  58. package/dist/components/translation/Tx.rsc.mjs +1 -1
  59. package/dist/components/translation/Tx.rsc.mjs.map +1 -1
  60. package/dist/components/variables/Currency.shared.cjs +1 -1
  61. package/dist/components/variables/Currency.shared.cjs.map +1 -1
  62. package/dist/components/variables/Currency.shared.mjs +1 -1
  63. package/dist/components/variables/Currency.shared.mjs.map +1 -1
  64. package/dist/components/variables/DateTime.shared.cjs +1 -1
  65. package/dist/components/variables/DateTime.shared.cjs.map +1 -1
  66. package/dist/components/variables/DateTime.shared.mjs +1 -1
  67. package/dist/components/variables/DateTime.shared.mjs.map +1 -1
  68. package/dist/components/variables/Num.shared.cjs +1 -1
  69. package/dist/components/variables/Num.shared.cjs.map +1 -1
  70. package/dist/components/variables/Num.shared.mjs +1 -1
  71. package/dist/components/variables/Num.shared.mjs.map +1 -1
  72. package/dist/components/variables/RelativeTime.shared.cjs +1 -1
  73. package/dist/components/variables/RelativeTime.shared.cjs.map +1 -1
  74. package/dist/components/variables/RelativeTime.shared.mjs +1 -1
  75. package/dist/components/variables/RelativeTime.shared.mjs.map +1 -1
  76. package/dist/components-rsc.cjs +1 -1
  77. package/dist/components-rsc.d.ts +2 -13
  78. package/dist/components-rsc.mjs +1 -1
  79. package/dist/components.cjs +1 -1
  80. package/dist/components.d.ts +1 -2
  81. package/dist/components.mjs +1 -1
  82. package/dist/condition-store/singleton-operations.cjs +1 -1
  83. package/dist/condition-store/singleton-operations.cjs.map +1 -1
  84. package/dist/condition-store/singleton-operations.d.ts +1 -1
  85. package/dist/condition-store/singleton-operations.d.ts.map +1 -1
  86. package/dist/condition-store/singleton-operations.mjs +1 -1
  87. package/dist/condition-store/singleton-operations.mjs.map +1 -1
  88. package/dist/context/InternalGTProvider.cjs +1 -1
  89. package/dist/context/InternalGTProvider.cjs.map +1 -1
  90. package/dist/context/InternalGTProvider.d.ts +6 -13
  91. package/dist/context/InternalGTProvider.d.ts.map +1 -1
  92. package/dist/context/InternalGTProvider.mjs +1 -1
  93. package/dist/context/InternalGTProvider.mjs.map +1 -1
  94. package/dist/context/context.cjs +1 -1
  95. package/dist/context/context.cjs.map +1 -1
  96. package/dist/context/context.mjs +1 -1
  97. package/dist/context/context.mjs.map +1 -1
  98. package/dist/functions/helpers/getTranslationsSnapshot.cjs +1 -1
  99. package/dist/functions/helpers/getTranslationsSnapshot.cjs.map +1 -1
  100. package/dist/functions/helpers/getTranslationsSnapshot.d.ts +2 -2
  101. package/dist/functions/helpers/getTranslationsSnapshot.mjs +1 -1
  102. package/dist/functions/helpers/getTranslationsSnapshot.mjs.map +1 -1
  103. package/dist/functions/translation/t.cjs +1 -1
  104. package/dist/functions/translation/t.cjs.map +1 -1
  105. package/dist/functions/translation/t.d.ts +2 -1
  106. package/dist/functions/translation/t.d.ts.map +1 -1
  107. package/dist/functions/translation/t.mjs +1 -1
  108. package/dist/functions/translation/t.mjs.map +1 -1
  109. package/dist/hooks/external-store/useTrackedTranslationResolver.cjs.map +1 -1
  110. package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
  111. package/dist/hooks/external-store.cjs.map +1 -1
  112. package/dist/hooks/external-store.mjs.map +1 -1
  113. package/dist/hooks/i18n-config.cjs.map +1 -1
  114. package/dist/hooks/i18n-config.d.ts +1 -1
  115. package/dist/hooks/i18n-config.mjs.map +1 -1
  116. package/dist/hooks/useGT.cjs.map +1 -1
  117. package/dist/hooks/useGT.d.ts +1 -1
  118. package/dist/hooks/useGT.mjs.map +1 -1
  119. package/dist/hooks/useInternalLocaleSelector.cjs.map +1 -1
  120. package/dist/hooks/useInternalLocaleSelector.d.ts +1 -1
  121. package/dist/hooks/useInternalLocaleSelector.d.ts.map +1 -1
  122. package/dist/hooks/useInternalLocaleSelector.mjs.map +1 -1
  123. package/dist/hooks/useInternalRegionSelector.cjs +1 -1
  124. package/dist/hooks/useInternalRegionSelector.cjs.map +1 -1
  125. package/dist/hooks/useInternalRegionSelector.d.ts +3 -5
  126. package/dist/hooks/useInternalRegionSelector.d.ts.map +1 -1
  127. package/dist/hooks/useInternalRegionSelector.mjs +1 -1
  128. package/dist/hooks/useInternalRegionSelector.mjs.map +1 -1
  129. package/dist/hooks/useMessages.cjs +1 -1
  130. package/dist/hooks/useMessages.cjs.map +1 -1
  131. package/dist/hooks/useMessages.d.ts +1 -1
  132. package/dist/hooks/useMessages.mjs +1 -1
  133. package/dist/hooks/useMessages.mjs.map +1 -1
  134. package/dist/hooks/utils/getFormatLocales.cjs +1 -1
  135. package/dist/hooks/utils/getFormatLocales.cjs.map +1 -1
  136. package/dist/hooks/utils/getFormatLocales.mjs +1 -1
  137. package/dist/hooks/utils/getFormatLocales.mjs.map +1 -1
  138. package/dist/hooks/utils/getShouldTranslate.cjs +1 -1
  139. package/dist/hooks/utils/getShouldTranslate.cjs.map +1 -1
  140. package/dist/hooks/utils/getShouldTranslate.mjs +1 -1
  141. package/dist/hooks/utils/getShouldTranslate.mjs.map +1 -1
  142. package/dist/hooks/utils/missing-translation.cjs +1 -1
  143. package/dist/hooks/utils/missing-translation.cjs.map +1 -1
  144. package/dist/hooks/utils/missing-translation.d.ts +3 -5
  145. package/dist/hooks/utils/missing-translation.d.ts.map +1 -1
  146. package/dist/hooks/utils/missing-translation.mjs +1 -1
  147. package/dist/hooks/utils/missing-translation.mjs.map +1 -1
  148. package/dist/hooks/utils.cjs +1 -1
  149. package/dist/hooks/utils.cjs.map +1 -1
  150. package/dist/hooks/utils.d.ts +1 -2
  151. package/dist/hooks/utils.d.ts.map +1 -1
  152. package/dist/hooks/utils.mjs +1 -1
  153. package/dist/hooks/utils.mjs.map +1 -1
  154. package/dist/hooks.cjs +1 -1
  155. package/dist/hooks.d.ts +1 -2
  156. package/dist/hooks.mjs +1 -1
  157. package/dist/i18n-cache/ReactI18nCache.cjs.map +1 -1
  158. package/dist/i18n-cache/ReactI18nCache.d.ts +2 -3
  159. package/dist/i18n-cache/ReactI18nCache.d.ts.map +1 -1
  160. package/dist/i18n-cache/ReactI18nCache.mjs.map +1 -1
  161. package/dist/i18n-cache/singleton-operations.cjs.map +1 -1
  162. package/dist/i18n-cache/singleton-operations.d.ts.map +1 -1
  163. package/dist/i18n-cache/singleton-operations.mjs.map +1 -1
  164. package/dist/i18n-store/I18nStore.cjs +1 -1
  165. package/dist/i18n-store/I18nStore.cjs.map +1 -1
  166. package/dist/i18n-store/I18nStore.d.ts +4 -23
  167. package/dist/i18n-store/I18nStore.d.ts.map +1 -1
  168. package/dist/i18n-store/I18nStore.mjs +1 -1
  169. package/dist/i18n-store/I18nStore.mjs.map +1 -1
  170. package/dist/i18n-store/singleton-operations.cjs +1 -1
  171. package/dist/i18n-store/singleton-operations.cjs.map +1 -1
  172. package/dist/i18n-store/singleton-operations.mjs +1 -1
  173. package/dist/i18n-store/singleton-operations.mjs.map +1 -1
  174. package/dist/i18n-store/storeTypes.d.ts +3 -10
  175. package/dist/i18n-store/storeTypes.d.ts.map +1 -1
  176. package/dist/i18n-store/useI18nStore.cjs +1 -1
  177. package/dist/i18n-store/useI18nStore.cjs.map +1 -1
  178. package/dist/i18n-store/useI18nStore.mjs +1 -1
  179. package/dist/i18n-store/useI18nStore.mjs.map +1 -1
  180. package/dist/i18n-store/utils/runtimeTranslationErrors.cjs +2 -0
  181. package/dist/i18n-store/utils/runtimeTranslationErrors.cjs.map +1 -0
  182. package/dist/i18n-store/utils/runtimeTranslationErrors.mjs +2 -0
  183. package/dist/i18n-store/utils/runtimeTranslationErrors.mjs.map +1 -0
  184. package/dist/i18n-store/utils/translations.cjs.map +1 -1
  185. package/dist/i18n-store/utils/translations.mjs.map +1 -1
  186. package/dist/pure.cjs +1 -1
  187. package/dist/pure.d.ts +4 -8
  188. package/dist/pure.mjs +1 -1
  189. package/dist/setup/i18nConfig.cjs +1 -1
  190. package/dist/setup/i18nConfig.cjs.map +1 -1
  191. package/dist/setup/i18nConfig.d.ts +1 -2
  192. package/dist/setup/i18nConfig.d.ts.map +1 -1
  193. package/dist/setup/i18nConfig.mjs +1 -1
  194. package/dist/setup/i18nConfig.mjs.map +1 -1
  195. package/dist/unstable/t.cjs +1 -1
  196. package/dist/unstable/t.cjs.map +1 -1
  197. package/dist/unstable/t.mjs +1 -1
  198. package/dist/unstable/t.mjs.map +1 -1
  199. package/dist/unstable.cjs +1 -1
  200. package/dist/unstable.d.ts +1 -2
  201. package/dist/unstable.mjs +1 -1
  202. package/dist/utils/internal/addGTIdentifier.cjs +1 -1
  203. package/dist/utils/internal/addGTIdentifier.cjs.map +1 -1
  204. package/dist/utils/internal/addGTIdentifier.mjs +1 -1
  205. package/dist/utils/internal/addGTIdentifier.mjs.map +1 -1
  206. package/dist/utils/internal/removeInjectedT.cjs +1 -1
  207. package/dist/utils/internal/removeInjectedT.cjs.map +1 -1
  208. package/dist/utils/internal/removeInjectedT.mjs +1 -1
  209. package/dist/utils/internal/removeInjectedT.mjs.map +1 -1
  210. package/dist/utils/internal/writeChildrenAsObjects.cjs +1 -1
  211. package/dist/utils/internal/writeChildrenAsObjects.cjs.map +1 -1
  212. package/dist/utils/internal/writeChildrenAsObjects.mjs +1 -1
  213. package/dist/utils/internal/writeChildrenAsObjects.mjs.map +1 -1
  214. package/dist/utils/plurals/getPluralBranch.cjs +1 -1
  215. package/dist/utils/plurals/getPluralBranch.cjs.map +1 -1
  216. package/dist/utils/plurals/getPluralBranch.mjs +1 -1
  217. package/dist/utils/plurals/getPluralBranch.mjs.map +1 -1
  218. package/dist/utils/rendering/createRenderPipeline.cjs.map +1 -1
  219. package/dist/utils/rendering/createRenderPipeline.mjs.map +1 -1
  220. package/dist/utils/rendering/createRenderVariable.cjs +1 -1
  221. package/dist/utils/rendering/createRenderVariable.cjs.map +1 -1
  222. package/dist/utils/rendering/createRenderVariable.mjs +1 -1
  223. package/dist/utils/rendering/createRenderVariable.mjs.map +1 -1
  224. package/dist/utils/rendering/renderDefaultChildren.shared.cjs +1 -1
  225. package/dist/utils/rendering/renderDefaultChildren.shared.cjs.map +1 -1
  226. package/dist/utils/rendering/renderDefaultChildren.shared.mjs +1 -1
  227. package/dist/utils/rendering/renderDefaultChildren.shared.mjs.map +1 -1
  228. package/dist/utils/rendering/renderPreparedT.shared.cjs.map +1 -1
  229. package/dist/utils/rendering/renderPreparedT.shared.d.ts +1 -1
  230. package/dist/utils/rendering/renderPreparedT.shared.mjs.map +1 -1
  231. package/dist/utils/rendering/renderTranslatedChildren.shared.cjs +1 -1
  232. package/dist/utils/rendering/renderTranslatedChildren.shared.cjs.map +1 -1
  233. package/dist/utils/rendering/renderTranslatedChildren.shared.d.ts.map +1 -1
  234. package/dist/utils/rendering/renderTranslatedChildren.shared.mjs +1 -1
  235. package/dist/utils/rendering/renderTranslatedChildren.shared.mjs.map +1 -1
  236. package/dist/utils/translation/prepareT.shared.cjs +1 -1
  237. package/dist/utils/translation/prepareT.shared.cjs.map +1 -1
  238. package/dist/utils/translation/prepareT.shared.d.ts +3 -3
  239. package/dist/utils/translation/prepareT.shared.d.ts.map +1 -1
  240. package/dist/utils/translation/prepareT.shared.mjs +1 -1
  241. package/dist/utils/translation/prepareT.shared.mjs.map +1 -1
  242. package/dist/utils/translation/usePrepareT.cjs +1 -1
  243. package/dist/utils/translation/usePrepareT.cjs.map +1 -1
  244. package/dist/utils/translation/usePrepareT.mjs +1 -1
  245. package/dist/utils/translation/usePrepareT.mjs.map +1 -1
  246. package/dist/utils/types.d.ts +6 -6
  247. package/dist/utils/types.d.ts.map +1 -1
  248. package/dist/utils/variables/_getVariableProps.cjs.map +1 -1
  249. package/dist/utils/variables/_getVariableProps.mjs.map +1 -1
  250. package/package.json +14 -4
  251. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs +0 -2
  252. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs.map +0 -1
  253. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs +0 -2
  254. package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs.map +0 -1
  255. package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs +0 -2
  256. package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs.map +0 -1
  257. package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs +0 -2
  258. package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs.map +0 -1
  259. package/dist/hooks/useTranslations.cjs +0 -2
  260. package/dist/hooks/useTranslations.cjs.map +0 -1
  261. package/dist/hooks/useTranslations.d.ts +0 -10
  262. package/dist/hooks/useTranslations.d.ts.map +0 -1
  263. package/dist/hooks/useTranslations.mjs +0 -2
  264. package/dist/hooks/useTranslations.mjs.map +0 -1
  265. package/dist/i18n-store/utils/dictionaries.cjs +0 -2
  266. package/dist/i18n-store/utils/dictionaries.cjs.map +0 -1
  267. package/dist/i18n-store/utils/dictionaries.mjs +0 -2
  268. package/dist/i18n-store/utils/dictionaries.mjs.map +0 -1
  269. package/dist/setup/cookieNames.d.ts +0 -2
  270. package/dist/setup/cookieNames.mjs +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,120 @@
1
1
  # @generaltranslation/react-core
2
2
 
3
+ ## 12.0.0-samsara.9
4
+
5
+ ### Major Changes
6
+
7
+ - 016ace7: Remove the `devApiKey` option. One `apiKey` now covers both uses: in development it enables hot reload translation, and in production it lets server code translate at runtime. Pass your key as `apiKey` wherever you passed `devApiKey`, for example `initializeGT({ apiKey })` in gt-node.
8
+
9
+ gt-react ignores an `apiKey` that reaches production browser code and logs a warning, because anyone can read a key from a browser bundle. Translate at runtime on your server instead.
10
+
11
+ - cf7029c: Move the dictionary (key-based) API to `/compat` subpaths. `useTranslations()`, `getTranslations()`, `initializeGTDictionary()` and the `Dictionary*` types now come from `gt-react/compat`, `gt-react-native/compat`, `gt-next/compat` (its export conditions mirror `gt-next`), `gt-next/compat/server` (server-only `getTranslations()`, like `gt-next/server`) and `gt-tanstack-start/compat`. The old exports are removed without stubs, the root `GTProvider` no longer accepts `dictionaries`, `onMissingDictionaryEntry` or `onMissingDictionaryObj`, and `initializeGT()`/`initializeGTSPA()` no longer accept `dictionary` or `loadDictionary`.
12
+
13
+ Each `/compat` entry exports its own `GTProvider`, which takes everything the root `GTProvider` takes plus those dictionary props, so moving the provider changes only its import. `useTranslations()` reads dictionaries only from it and, under the root `GTProvider`, throws an error that names the `/compat` entry. `initializeGTDictionary()` takes `cacheExpiryTime` like `initializeGT()` and no longer inherits it. In gt-next, the App Router `GTProvider` from `gt-next/compat` also loads the request locale's dictionaries and streams them to client components, as `GTProvider` did; in the Pages Router, `withGTServerSideProps()` and `withGTStaticProps()` from `gt-next/compat` add `dictionaries` to page props for it. In gt-tanstack-start, `setupRouterGTIntegration({ router })` from `gt-tanstack-start/compat` also loads the request locale's dictionary before render and hydrates the browser from that snapshot. Dictionary dev hot reload keeps working.
14
+
15
+ Apps that only use the native APIs no longer ship any dictionary code. gt-next requires the `gt-next/internal/_dictionary` and `_load-dictionary` aliases only from `gt-next/compat` modules, and the gt-tanstack-start Vite plugin serves the dictionary from its own `internal/_compat-config` virtual module, so your dictionary file is bundled only when you import a `/compat` entry. The webpack rule that parses gt-next's ESM dist as `javascript/auto` now detects the dist through `internal/_load-translations.mjs`. The `dictionary` and `loadDictionaryPath` options of `withGTConfig()`, `gt.config.json` and the Vite plugin are unchanged. gt-next no longer treats a `[defaultLocale].json` or `[languageCode].json` file (for example `en.json`) as the dictionary; name the file `dictionary.json` or set the `dictionary` option.
16
+
17
+ `@generaltranslation/react-core` keeps the dictionary internals behind `@generaltranslation/react-core/compat`: `InternalGTProvider` no longer accepts `dictionaries` or `onMissingDictionary*`, `internalInitializeGTSRA()` no longer accepts `dictionary` or `loadDictionary`, and the unused legacy `Dictionary` types are removed. The gt-next `GTProvider` type no longer declares the unused `id` prop.
18
+
19
+ Migration:
20
+
21
+ | Before | After |
22
+ | ------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | `import { useTranslations } from 'gt-react'` | `import { useTranslations } from 'gt-react/compat'` |
24
+ | `import { GTProvider } from 'gt-react'` with `dictionaries`, `onMissingDictionaryEntry` or `onMissingDictionaryObj` | `import { GTProvider } from 'gt-react/compat'`, which takes the same props |
25
+ | `initializeGT({ …, dictionary, loadDictionary })`, `initializeGTSPA({ …, dictionary, loadDictionary })` (gt-react) | `initializeGT({ … })` / `initializeGTSPA({ … })`, then `initializeGTDictionary({ dictionary, loadDictionary, cacheExpiryTime })` from `gt-react/compat`. Pass the `cacheExpiryTime` the dictionaries used before: the one you pass to `initializeGT()`, or `null` where `initializeGT()` defaulted it to `null` (gt-react's browser `initializeGT()`); without it, loaded dictionaries expire after the default 60 seconds |
26
+ | `import { useTranslations } from 'gt-react-native'` | `import { useTranslations } from 'gt-react-native/compat'` |
27
+ | `<GTProvider dictionaries={…}>`, `initializeGT({ …, dictionary, loadDictionary })` (gt-react-native) | `GTProvider` and `initializeGTDictionary({ dictionary, loadDictionary, cacheExpiryTime })` from `gt-react-native/compat`, with the `cacheExpiryTime` you pass to `initializeGT()` |
28
+ | `import { useTranslations } from 'gt-next'` | `import { useTranslations } from 'gt-next/compat'` |
29
+ | `import { getTranslations } from 'gt-next/server'` | `import { getTranslations } from 'gt-next/compat/server'` |
30
+ | gt-next `GTProvider` streamed dictionaries to client components | import `GTProvider` from `gt-next/compat`. In the Pages Router, also import `withGTServerSideProps` / `withGTStaticProps` from `gt-next/compat`, which add `dictionaries` to page props |
31
+ | `import { useTranslations, getTranslations } from 'gt-tanstack-start'` | `import { useTranslations, getTranslations } from 'gt-tanstack-start/compat'`, and import `setupRouterGTIntegration` from `gt-tanstack-start/compat` instead of `gt-tanstack-start` |
32
+
33
+ - 943c094: `@generaltranslation/react-core/pure` no longer re-exports names that `gt-i18n`, `generaltranslation`, or `@generaltranslation/format` own. Import them from their owner:
34
+ - `msg`, `decodeMsg`, `decodeOptions`, `mFallback`, `gtFallback`, `getDefaultLocale`, `getLocaleProperties`, `getLocales`, `resolveCanonicalLocale`, `getVersionId`: import from `gt-i18n`.
35
+ - `derive`, `declareVar`, `decodeVars`: import from `generaltranslation` (or `gt-i18n`).
36
+ - `ReadonlyConditionStore`: import from `gt-i18n/internal`.
37
+ - `defaultLocaleCookieName`, `defaultRegionCookieName`, `defaultEnableI18nCookieName`, `defaultResetLocaleCookieName`: import from `gt-i18n/internal/cookies`.
38
+ - Types `GTTranslationOptions`, `GTFunctionType`, `MFunctionType`, `RuntimeTranslationOptions`: import from `gt-i18n`.
39
+ - Type `GTProp`: import from `@generaltranslation/format`.
40
+
41
+ `@generaltranslation/react-core/unstable` now exports only `t`, `useGT`, and `useMessages`. Import the message helpers (`msg`, `mFallback`, `derive`, `plural`, `select`, `selectordinal`, `part`, `number`, `n`, `date`) and their types from `gt-i18n/unstable`.
42
+
43
+ `gt-react`, `gt-react-native`, `gt-next`, and `gt-tanstack-start` still export the same user-facing names.
44
+
45
+ - 943c094: Each name is now exported from one entry:
46
+ - `@generaltranslation/react-core/components-rsc` no longer re-exports what `@generaltranslation/react-core/pure` exports: `t`, `getTranslationsSnapshot`, `getFormatLocales`, `createRenderPipeline`, `RenderPipeline`, `getReactI18nCache`, `setReactI18nCache`, `internalInitializeGTSRA`, `getReadonlyConditionStore`, `RelativeTimeFormatOptions` and `RenderVariable`. Import them from `@generaltranslation/react-core/pure`.
47
+ - `I18nStore` is no longer exported from `@generaltranslation/react-core/components`. Import it from `@generaltranslation/react-core/pure`.
48
+
49
+ - 13dae8a: Remove the remaining backward compatibility:
50
+ - `<T>` no longer reads `$context`, `$id`, `$maxChars`, `$requiresReview`, `$format`, or `$_hash`; use `context`, `id`, `maxChars`, `requiresReview`.
51
+ - `<LocaleSelector>` drops `customNames`; use `customMapping={{ [locale]: { name } }}`.
52
+ - gt-next: `parseLocale()` no longer detects the locale from request headers, cookies, or `Accept-Language` when Next.js provides none; it uses Next.js `defaultLocale` (or the GT default) and warns, like `withGTStaticProps`. Configure Next.js `i18n`.
53
+ - gt-next and gt-tanstack-start: `experimentalCompilerOptions.compileTimeHash: false` no longer switches the compiler off; use `experimentalCompilerOptions.type: 'none'`.
54
+ - gt-next: runtime translation requests no longer send `projectId`, `timeout`, `publish`, `fast`, or `sourceLocale` in request `metadata`.
55
+ - gt-react-native: locale detection drops the fallbacks for unsupported runtimes (Android < 24 and Internet Explorer's `navigator.userLanguage`).
56
+
57
+ ### Patch Changes
58
+
59
+ - 96f428a: Remove duplicate and unused type exports.
60
+ - `import type { UseTranslationsFunction } from 'gt-react/compat'` (also `gt-react-native/compat` and `gt-tanstack-start/compat`): use `TFunctionType` from the same entry. From `gt-next/compat`, use `TFunctionType` from `gt-next/compat/server`; from `@generaltranslation/react-core/compat`, use `TFunctionType` from `gt-i18n/internal/compat`.
61
+ - `@generaltranslation/react-core/pure` no longer exports the `OnMissingTranslation` and `VariableProps` types.
62
+ - `@generaltranslation/react-core/components-rsc` no longer exports the `RenderDefaultChildrenArgs`, `RenderPreparedTParams` and `RenderTranslatedChildrenArgs` types.
63
+ - `I18nCacheConfig` from `gt-i18n/internal` no longer has `projectId`, `apiKey` and `runtimeUrl`; `I18nCache` never read them.
64
+
65
+ - cf7029c: Move the dictionary (compat) internals to their own internal subpaths, `gt-i18n/internal/compat` and `@generaltranslation/react-core/compat`, so CommonJS builds of the native entries no longer load the dictionary runtime. `gt-i18n/internal` and `@generaltranslation/react-core/{pure,hooks,components}` no longer export it. No public API change.
66
+ - 63b6748: `withGTConfig()` props, `createNextMiddleware()` options and `RenderMethod` now take their types from the `gt.config.json` schemas: the shared keys from `GTConfig`, and gt-next's routing keys (`pathConfig`, `pathRegex`, `prefixDefaultLocale` and the others) from gt-next's own schema, so they match what `gt.config.json` accepts. No behavior changes.
67
+ - 82999f0: Remove the internal `setup/cookieNames` pass-through and other internal re-exports.
68
+ - ea429a2: `@generaltranslation/react-core/pure` exports the `RenderMethod` type. `RegionSelectorProps` now derives its region options from `InternalRegionSelectorOptions`; the accepted props are unchanged.
69
+ - 2d7f9bd: Remove runtime checks that TypeScript already guarantees and duplicated locale resolution. gt-react's browser condition store now resolves the locale once on initialization and server updates, and gt-vue's `initializeGTSPA()` builds its locale matcher once instead of on every lookup. Translation hashes do not change.
70
+
71
+ Two observable changes:
72
+ - `generaltranslation`: runtime translation results from the General Translation API are no longer shape-checked on the client; their type comes from the generated API client. A successful result whose `translation` did not match its `dataFormat` used to become `{ success: false, error: 'Invalid translation returned', code: 500 }`; it is now returned as the service sent it. Failed requests, missing entries (`'No translation returned'`) and network errors behave as before.
73
+ - `gt-tanstack-start`: request locales are now resolved against the configuration that `initializeGT()` already loaded, instead of a copy rebuilt on every request. That configuration always includes `defaultLocale` among the supported locales, so with `defaultLocale: 'en'`, `locales: ['fr']` and `Accept-Language: en, fr`, the request locale is now `en` (previously `fr`), matching path-based locale detection.
74
+
75
+ - 44a3832: - gt-vue's `<Num>`, `<Currency>` and `<DateTime>` format through `generaltranslation`'s formatters, as gt-react's do. They reuse one `Intl` formatter per locale and options, where they built a new one on every render, and they print what gt-react prints: Latin digits and the Gregorian calendar, so `<Num :value="1234.5"/>` in `ar-EG` is `1,234.5`, not `١٬٢٣٤٫٥`. A `<DateTime>` without a `timeZone` is still in the host's.
76
+ - The region selector builds one `Intl.Collator` to sort its regions, not one per comparison.
77
+ - Updated dependencies [96f428a]
78
+ - Updated dependencies [96f428a]
79
+ - Updated dependencies [cf7029c]
80
+ - Updated dependencies [2d7f9bd]
81
+ - Updated dependencies [ba09ee2]
82
+ - Updated dependencies [ba09ee2]
83
+ - Updated dependencies [63b6748]
84
+ - Updated dependencies [ea429a2]
85
+ - Updated dependencies [82999f0]
86
+ - Updated dependencies [ba09ee2]
87
+ - Updated dependencies [ba09ee2]
88
+ - Updated dependencies [943c094]
89
+ - Updated dependencies [016ace7]
90
+ - Updated dependencies [ba09ee2]
91
+ - Updated dependencies [82999f0]
92
+ - Updated dependencies [96f428a]
93
+ - Updated dependencies [3832c15]
94
+ - Updated dependencies [2d7f9bd]
95
+ - Updated dependencies [943c094]
96
+ - Updated dependencies [cf7029c]
97
+ - Updated dependencies [82999f0]
98
+ - Updated dependencies [63b6748]
99
+ - Updated dependencies [13dae8a]
100
+ - Updated dependencies [2d7f9bd]
101
+ - Updated dependencies [943c094]
102
+ - Updated dependencies [a191c9a]
103
+ - Updated dependencies [2d7f9bd]
104
+ - Updated dependencies [1a5e9ae]
105
+ - Updated dependencies [e29f6f9]
106
+ - generaltranslation@10.0.0-samsara.9
107
+ - gt-i18n@2.0.0-samsara.9
108
+ - @generaltranslation/format@1.0.0-samsara.9
109
+
110
+ ## 12.0.0-samsara.8
111
+
112
+ ### Patch Changes
113
+
114
+ - generaltranslation@10.0.0-samsara.8
115
+ - @generaltranslation/format@1.0.0-samsara.8
116
+ - gt-i18n@2.0.0-samsara.8
117
+
3
118
  ## 12.0.0-samsara.7
4
119
 
5
120
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../i18n-store/utils/subscriptions.cjs`),t=require(`../i18n-store/utils/runtimeTranslationErrors.cjs`),n=require(`./dictionaries.cjs`);let r=require(`gt-i18n/internal/compat`);function i(){return(0,r.isDictionaryManagerInitialized)()||(0,r.initializeDictionaryManager)({cacheExpiryTime:null}),(0,r.getDictionaryManager)()}function a(){return(0,r.isDictionaryManagerInitialized)()?(0,r.getDictionaryManager)():void 0}var o=class{dictionaryEntryListeners=new Set;dictionaryObjectListeners=new Set;logRuntimeTranslationError=t.createRuntimeTranslationErrorLogger();updateDictionaries=e=>{Object.keys(e).length!==0&&i().updateDictionaries(e)};translateDictionaryEntry=e=>{a()?.lookupDictionaryWithFallback(e.locale,e.id).then(()=>{this.emitDictionaryEvent(e)}).catch(e=>this.logRuntimeTranslationError(e))};translateDictionaryObject=e=>{a()?.lookupDictionaryObjWithFallback(e.locale,e.id).then(()=>{this.emitDictionaryEvent(e)}).catch(e=>this.logRuntimeTranslationError(e))};subscribeToDictionaryEntryEvents=t=>e.subscribeToSet(this.dictionaryEntryListeners,t);subscribeToDictionaryObjectEvents=t=>e.subscribeToSet(this.dictionaryObjectListeners,t);getDictionaryEntrySnapshot=(e,t)=>n.lookupDictionaryEntry(t,e)??a()?.lookupDictionary(e.locale,e.id);getDictionaryObjectSnapshot=(e,t)=>n.lookupDictionaryObject(t,e)??a()?.lookupDictionaryObj(e.locale,e.id);emitDictionaryEvent(e){this.dictionaryEntryListeners.forEach(t=>t(e)),this.dictionaryObjectListeners.forEach(t=>{t(e)})}};exports.CompatStore=o;
2
+ //# sourceMappingURL=CompatStore.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompatStore.cjs","names":["createRuntimeTranslationErrorLogger","subscribeToSet","lookupDictionaryEntry","lookupDictionaryObject"],"sources":["../../src/compat/CompatStore.ts"],"sourcesContent":["import type { Locale } from 'gt-i18n/internal';\nimport {\n getDictionaryManager,\n initializeDictionaryManager,\n isDictionaryManagerInitialized,\n type Dictionary,\n} from 'gt-i18n/internal/compat';\nimport type { Unsubscribe } from '../i18n-store/storeTypes';\nimport { subscribeToSet } from '../i18n-store/utils/subscriptions';\nimport { createRuntimeTranslationErrorLogger } from '../i18n-store/utils/runtimeTranslationErrors';\nimport { lookupDictionaryEntry, lookupDictionaryObject } from './dictionaries';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n DictionaryStoreListener,\n} from './types';\n\n/**\n * Runtimes that only receive dictionaries through provider snapshots (such as\n * the gt-next client) never initialize a DictionaryManager. Create one without\n * a loader; its entries cannot be refreshed, so they never expire.\n */\nfunction getOrCreateDictionaryManager() {\n if (!isDictionaryManagerInitialized()) {\n initializeDictionaryManager({ cacheExpiryTime: null });\n }\n return getDictionaryManager();\n}\n\n/**\n * Render-time reads and server-side translations must not create a manager:\n * an empty one would stop gt-next from seeding the bundled dictionary later.\n * Only updateDictionaries() (a client effect) creates one.\n */\nfunction getExistingDictionaryManager() {\n return isDictionaryManagerInitialized() ? getDictionaryManager() : undefined;\n}\n\n/**\n * Dictionary counterpart of I18nStore: syncs DictionaryManager updates with\n * renders and drives dictionary dev hot reload.\n */\nexport class CompatStore {\n // ----- Listener Sets ----- //\n\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private logRuntimeTranslationError = createRuntimeTranslationErrorLogger();\n\n // ========== Dictionary Updates ========== //\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n if (Object.keys(dictionaries).length === 0) return;\n getOrCreateDictionaryManager().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n // Without a manager there is no source dictionary to translate from.\n getExistingDictionaryManager()\n ?.lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getExistingDictionaryManager()\n ?.lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary>\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getExistingDictionaryManager()?.lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary>\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getExistingDictionaryManager()?.lookupDictionaryObj(\n lookup.locale,\n lookup.id\n )\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"6OAuBA,SAAS,GAA+B,CAItC,OAHI,EAAA,EAAA,iCAAiC,GACnC,EAAA,EAAA,6BAA4B,CAAE,gBAAiB,KAAM,CAAC,EAExD,EAAA,EAAA,uBAA6B,CAQ/B,SAAS,GAA+B,CACtC,OAAA,EAAA,EAAA,iCAAuC,EAAA,EAAA,EAAA,uBAAyB,CAAG,IAAA,GAOrE,IAAa,EAAb,KAAyB,CAGvB,yBAAmC,IAAI,IACvC,0BAAoC,IAAI,IACxC,2BAAqCA,EAAAA,qCAAqC,CAI1E,mBAAsB,GAAmD,CACnE,OAAO,KAAK,EAAa,CAAC,SAAW,GACzC,GAA8B,CAAC,mBAAmB,EAAa,EAKjE,yBAA4B,GAAmC,CAE7D,GAA8B,EAC1B,6BAA6B,EAAO,OAAQ,EAAO,GAAG,CACvD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAG7D,0BAA6B,GAAmC,CAC9D,GAA8B,EAC1B,gCAAgC,EAAO,OAAQ,EAAO,GAAG,CAC1D,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAS7D,iCACE,GAEOC,EAAAA,eAAe,KAAK,yBAA0B,EAAS,CAGhE,kCACE,GAEOA,EAAAA,eAAe,KAAK,0BAA2B,EAAS,CAKjE,4BACE,EACA,IAGEC,EAAAA,sBAAsB,EAAsB,EAAO,EACnD,GAA8B,EAAE,iBAAiB,EAAO,OAAQ,EAAO,GAAG,CAI9E,6BACE,EACA,IAGEC,EAAAA,uBAAuB,EAAsB,EAAO,EACpD,GAA8B,EAAE,oBAC9B,EAAO,OACP,EAAO,GACR,CAML,oBAA4B,EAA+B,CACzD,KAAK,yBAAyB,QAAS,GAAa,EAAS,EAAM,CAAC,CACpE,KAAK,0BAA0B,QAAS,GAAa,CACnD,EAAS,EAAM,EACf"}
@@ -0,0 +1,26 @@
1
+ import { Unsubscribe } from "../i18n-store/storeTypes.js";
2
+ import { DictionaryEntrySnapshot, DictionaryLookup, DictionaryObjectSnapshot, DictionaryStoreListener } from "./types.js";
3
+ import { Locale } from "gt-i18n/internal";
4
+ import { Dictionary } from "gt-i18n/internal/compat";
5
+
6
+ //#region src/compat/CompatStore.d.ts
7
+ /**
8
+ * Dictionary counterpart of I18nStore: syncs DictionaryManager updates with
9
+ * renders and drives dictionary dev hot reload.
10
+ */
11
+ declare class CompatStore {
12
+ private dictionaryEntryListeners;
13
+ private dictionaryObjectListeners;
14
+ private logRuntimeTranslationError;
15
+ updateDictionaries: (dictionaries: Record<Locale, Dictionary>) => void;
16
+ translateDictionaryEntry: (lookup: DictionaryLookup) => void;
17
+ translateDictionaryObject: (lookup: DictionaryLookup) => void;
18
+ subscribeToDictionaryEntryEvents: (listener: DictionaryStoreListener) => Unsubscribe;
19
+ subscribeToDictionaryObjectEvents: (listener: DictionaryStoreListener) => Unsubscribe;
20
+ getDictionaryEntrySnapshot: (lookup: DictionaryLookup, dictionariesSnapshot: Record<Locale, Dictionary>) => DictionaryEntrySnapshot;
21
+ getDictionaryObjectSnapshot: (lookup: DictionaryLookup, dictionariesSnapshot: Record<Locale, Dictionary>) => DictionaryObjectSnapshot;
22
+ private emitDictionaryEvent;
23
+ }
24
+ //#endregion
25
+ export { CompatStore };
26
+ //# sourceMappingURL=CompatStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompatStore.d.ts","names":[],"sources":["../../src/compat/CompatStore.ts"],"mappings":";;;;;;;;AA2CA;;cAAa,WAAA;EAAA,QAGH,wBAAA;EAAA,QACA,yBAAA;EAAA,QACA,0BAAA;EAIR,kBAAA,GAAsB,YAAA,EAAc,MAAA,CAAO,MAAA,EAAQ,UAAA;EAOnD,wBAAA,GAA4B,MAAA,EAAQ,gBAAA;EAUpC,yBAAA,GAA6B,MAAA,EAAQ,gBAAA;EAerC,gCAAA,GACE,QAAA,EAAU,uBAAA,KACT,WAAA;EAIH,iCAAA,GACE,QAAA,EAAU,uBAAA,KACT,WAAA;EAMH,0BAAA,GACE,MAAA,EAAQ,gBAAA,EACR,oBAAA,EAAsB,MAAA,CAAO,MAAA,EAAQ,UAAA,MACpC,uBAAA;EAOH,2BAAA,GACE,MAAA,EAAQ,gBAAA,EACR,oBAAA,EAAsB,MAAA,CAAO,MAAA,EAAQ,UAAA,MACpC,wBAAA;EAAA,QAYK,mBAAA;AAAA"}
@@ -0,0 +1,2 @@
1
+ import{subscribeToSet as e}from"../i18n-store/utils/subscriptions.mjs";import{createRuntimeTranslationErrorLogger as t}from"../i18n-store/utils/runtimeTranslationErrors.mjs";import{lookupDictionaryEntry as n,lookupDictionaryObject as r}from"./dictionaries.mjs";import{getDictionaryManager as i,initializeDictionaryManager as a,isDictionaryManagerInitialized as o}from"gt-i18n/internal/compat";function s(){return o()||a({cacheExpiryTime:null}),i()}function c(){return o()?i():void 0}var l=class{dictionaryEntryListeners=new Set;dictionaryObjectListeners=new Set;logRuntimeTranslationError=t();updateDictionaries=e=>{Object.keys(e).length!==0&&s().updateDictionaries(e)};translateDictionaryEntry=e=>{c()?.lookupDictionaryWithFallback(e.locale,e.id).then(()=>{this.emitDictionaryEvent(e)}).catch(e=>this.logRuntimeTranslationError(e))};translateDictionaryObject=e=>{c()?.lookupDictionaryObjWithFallback(e.locale,e.id).then(()=>{this.emitDictionaryEvent(e)}).catch(e=>this.logRuntimeTranslationError(e))};subscribeToDictionaryEntryEvents=t=>e(this.dictionaryEntryListeners,t);subscribeToDictionaryObjectEvents=t=>e(this.dictionaryObjectListeners,t);getDictionaryEntrySnapshot=(e,t)=>n(t,e)??c()?.lookupDictionary(e.locale,e.id);getDictionaryObjectSnapshot=(e,t)=>r(t,e)??c()?.lookupDictionaryObj(e.locale,e.id);emitDictionaryEvent(e){this.dictionaryEntryListeners.forEach(t=>t(e)),this.dictionaryObjectListeners.forEach(t=>{t(e)})}};export{l as CompatStore};
2
+ //# sourceMappingURL=CompatStore.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompatStore.mjs","names":[],"sources":["../../src/compat/CompatStore.ts"],"sourcesContent":["import type { Locale } from 'gt-i18n/internal';\nimport {\n getDictionaryManager,\n initializeDictionaryManager,\n isDictionaryManagerInitialized,\n type Dictionary,\n} from 'gt-i18n/internal/compat';\nimport type { Unsubscribe } from '../i18n-store/storeTypes';\nimport { subscribeToSet } from '../i18n-store/utils/subscriptions';\nimport { createRuntimeTranslationErrorLogger } from '../i18n-store/utils/runtimeTranslationErrors';\nimport { lookupDictionaryEntry, lookupDictionaryObject } from './dictionaries';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n DictionaryStoreListener,\n} from './types';\n\n/**\n * Runtimes that only receive dictionaries through provider snapshots (such as\n * the gt-next client) never initialize a DictionaryManager. Create one without\n * a loader; its entries cannot be refreshed, so they never expire.\n */\nfunction getOrCreateDictionaryManager() {\n if (!isDictionaryManagerInitialized()) {\n initializeDictionaryManager({ cacheExpiryTime: null });\n }\n return getDictionaryManager();\n}\n\n/**\n * Render-time reads and server-side translations must not create a manager:\n * an empty one would stop gt-next from seeding the bundled dictionary later.\n * Only updateDictionaries() (a client effect) creates one.\n */\nfunction getExistingDictionaryManager() {\n return isDictionaryManagerInitialized() ? getDictionaryManager() : undefined;\n}\n\n/**\n * Dictionary counterpart of I18nStore: syncs DictionaryManager updates with\n * renders and drives dictionary dev hot reload.\n */\nexport class CompatStore {\n // ----- Listener Sets ----- //\n\n private dictionaryEntryListeners = new Set<DictionaryStoreListener>();\n private dictionaryObjectListeners = new Set<DictionaryStoreListener>();\n private logRuntimeTranslationError = createRuntimeTranslationErrorLogger();\n\n // ========== Dictionary Updates ========== //\n\n updateDictionaries = (dictionaries: Record<Locale, Dictionary>): void => {\n if (Object.keys(dictionaries).length === 0) return;\n getOrCreateDictionaryManager().updateDictionaries(dictionaries);\n };\n\n // ========== runtime translation ========== //\n\n translateDictionaryEntry = (lookup: DictionaryLookup): void => {\n // Without a manager there is no source dictionary to translate from.\n getExistingDictionaryManager()\n ?.lookupDictionaryWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n translateDictionaryObject = (lookup: DictionaryLookup): void => {\n getExistingDictionaryManager()\n ?.lookupDictionaryObjWithFallback(lookup.locale, lookup.id)\n .then(() => {\n this.emitDictionaryEvent(lookup);\n })\n .catch((error) => this.logRuntimeTranslationError(error));\n };\n\n // ========== UseSyncExternalStore ========== //\n\n // ----- Subscriptions ----- //\n\n // Keep subscription methods as arrow fields so hooks can pass them by\n // reference without losing access to this store instance.\n subscribeToDictionaryEntryEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryEntryListeners, listener);\n };\n\n subscribeToDictionaryObjectEvents = (\n listener: DictionaryStoreListener\n ): Unsubscribe => {\n return subscribeToSet(this.dictionaryObjectListeners, listener);\n };\n\n // ----- Snapshots ----- //\n\n getDictionaryEntrySnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary>\n ): DictionaryEntrySnapshot => {\n return (\n lookupDictionaryEntry(dictionariesSnapshot, lookup) ??\n getExistingDictionaryManager()?.lookupDictionary(lookup.locale, lookup.id)\n );\n };\n\n getDictionaryObjectSnapshot = (\n lookup: DictionaryLookup,\n dictionariesSnapshot: Record<Locale, Dictionary>\n ): DictionaryObjectSnapshot => {\n return (\n lookupDictionaryObject(dictionariesSnapshot, lookup) ??\n getExistingDictionaryManager()?.lookupDictionaryObj(\n lookup.locale,\n lookup.id\n )\n );\n };\n\n // ----- Listener Utilities ----- //\n\n private emitDictionaryEvent(event: DictionaryLookup): void {\n this.dictionaryEntryListeners.forEach((listener) => listener(event));\n this.dictionaryObjectListeners.forEach((listener) => {\n listener(event);\n });\n }\n}\n"],"mappings":"yYAuBA,SAAS,GAA+B,CAItC,OAHK,GAAgC,EACnC,EAA4B,CAAE,gBAAiB,KAAM,CAAC,CAEjD,GAAsB,CAQ/B,SAAS,GAA+B,CACtC,OAAO,GAAgC,CAAG,GAAsB,CAAG,IAAA,GAOrE,IAAa,EAAb,KAAyB,CAGvB,yBAAmC,IAAI,IACvC,0BAAoC,IAAI,IACxC,2BAAqC,GAAqC,CAI1E,mBAAsB,GAAmD,CACnE,OAAO,KAAK,EAAa,CAAC,SAAW,GACzC,GAA8B,CAAC,mBAAmB,EAAa,EAKjE,yBAA4B,GAAmC,CAE7D,GAA8B,EAC1B,6BAA6B,EAAO,OAAQ,EAAO,GAAG,CACvD,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAG7D,0BAA6B,GAAmC,CAC9D,GAA8B,EAC1B,gCAAgC,EAAO,OAAQ,EAAO,GAAG,CAC1D,SAAW,CACV,KAAK,oBAAoB,EAAO,EAChC,CACD,MAAO,GAAU,KAAK,2BAA2B,EAAM,CAAC,EAS7D,iCACE,GAEO,EAAe,KAAK,yBAA0B,EAAS,CAGhE,kCACE,GAEO,EAAe,KAAK,0BAA2B,EAAS,CAKjE,4BACE,EACA,IAGE,EAAsB,EAAsB,EAAO,EACnD,GAA8B,EAAE,iBAAiB,EAAO,OAAQ,EAAO,GAAG,CAI9E,6BACE,EACA,IAGE,EAAuB,EAAsB,EAAO,EACpD,GAA8B,EAAE,oBAC9B,EAAO,OACP,EAAO,GACR,CAML,oBAA4B,EAA+B,CACzD,KAAK,yBAAyB,QAAS,GAAa,EAAS,EAAM,CAAC,CACpE,KAAK,0BAA0B,QAAS,GAAa,CACnD,EAAS,EAAM,EACf"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`gt-i18n/internal`),t=require(`generaltranslation/diagnostics`),n=require(`react`);const r=(0,e.createGlobalSingleton)({namespace:`reactCore`,key:`dictionaryContext`,source:`@generaltranslation/react-core`,notInitialized:()=>(0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read DictionaryContext before it has been initialized`})});function i(){return r.isInitialized()||r.set((0,n.createContext)(void 0)),r.get()}const a=(0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`useTranslations() was called outside a GTProvider from a /compat entry`,why:`only the /compat GTProvider supplies the dictionaries useTranslations() reads`,fix:`Render GTProvider from your GT package's /compat entry, such as 'gt-react/compat', 'gt-next/compat' or 'gt-react-native/compat', instead of the one from the package root. In gt-tanstack-start, call setupRouterGTIntegration({ router }) from 'gt-tanstack-start/compat'`});function o(){let e=(0,n.useContext)(i());if(!e)throw Error(a);return e}exports.getDictionaryContext=i,exports.useDictionaryContext=o;
2
+ //# sourceMappingURL=DictionaryContext.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DictionaryContext.cjs","names":[],"sources":["../../src/compat/DictionaryContext.ts"],"sourcesContent":["import { createGlobalSingleton, type Locale } from 'gt-i18n/internal';\nimport type { Dictionary } from 'gt-i18n/internal/compat';\nimport { createDiagnosticMessage } from 'generaltranslation/diagnostics';\nimport { createContext, useContext, type Context } from 'react';\nimport type { CompatStore } from './CompatStore';\nimport type { OnMissingDictionaryEntry, OnMissingDictionaryObj } from './types';\n\ntype DictionaryContextType = {\n /**\n * Dictionaries streamed from the server, keyed by locale\n */\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * CompatStore syncs DictionaryManager updates with renders\n */\n compatStore: CompatStore;\n /**\n * Custom override behavior on missing dictionary entries\n * Used for server triggering dictionary hmr b/c no access to useEffect\n */\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst dictionaryContextSingleton = createGlobalSingleton<\n Context<DictionaryContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'dictionaryContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Cannot read DictionaryContext before it has been initialized',\n }),\n});\n\nexport function getDictionaryContext(): Context<\n DictionaryContextType | undefined\n> {\n // Lazily create the React context once and share it across instances.\n if (!dictionaryContextSingleton.isInitialized()) {\n dictionaryContextSingleton.set(\n createContext<DictionaryContextType | undefined>(undefined)\n );\n }\n return dictionaryContextSingleton.get();\n}\n\nconst missingDictionaryProviderError = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'useTranslations() was called outside a GTProvider from a /compat entry',\n why: 'only the /compat GTProvider supplies the dictionaries useTranslations() reads',\n fix: \"Render GTProvider from your GT package's /compat entry, such as 'gt-react/compat', 'gt-next/compat' or 'gt-react-native/compat', instead of the one from the package root. In gt-tanstack-start, call setupRouterGTIntegration({ router }) from 'gt-tanstack-start/compat'\",\n});\n\nexport function useDictionaryContext(): DictionaryContextType {\n const context = useContext(getDictionaryContext());\n if (!context) throw new Error(missingDictionaryProviderError);\n return context;\n}\n"],"mappings":"8IAwBA,MAAM,GAAA,EAAA,EAAA,uBAEJ,CACA,UAAW,YACX,IAAK,oBACL,OAAQ,iCACR,oBAAA,EAAA,EAAA,yBAC0B,CACtB,OAAQ,iCACR,SAAU,QACV,aACE,+DACH,CAAC,CACL,CAAC,CAEF,SAAgB,GAEd,CAOA,OALK,EAA2B,eAAe,EAC7C,EAA2B,KAAA,EAAA,EAAA,eACwB,IAAA,GAAU,CAC5D,CAEI,EAA2B,KAAK,CAGzC,MAAM,GAAA,EAAA,EAAA,yBAAyD,CAC7D,OAAQ,iCACR,SAAU,QACV,aACE,yEACF,IAAK,gFACL,IAAK,6QACN,CAAC,CAEF,SAAgB,GAA8C,CAC5D,IAAM,GAAA,EAAA,EAAA,YAAqB,GAAsB,CAAC,CAClD,GAAI,CAAC,EAAS,MAAU,MAAM,EAA+B,CAC7D,OAAO"}
@@ -0,0 +1,2 @@
1
+ import{createGlobalSingleton as e}from"gt-i18n/internal";import{createDiagnosticMessage as t}from"generaltranslation/diagnostics";import{createContext as n,useContext as r}from"react";const i=e({namespace:`reactCore`,key:`dictionaryContext`,source:`@generaltranslation/react-core`,notInitialized:()=>t({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read DictionaryContext before it has been initialized`})});function a(){return i.isInitialized()||i.set(n(void 0)),i.get()}const o=t({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`useTranslations() was called outside a GTProvider from a /compat entry`,why:`only the /compat GTProvider supplies the dictionaries useTranslations() reads`,fix:`Render GTProvider from your GT package's /compat entry, such as 'gt-react/compat', 'gt-next/compat' or 'gt-react-native/compat', instead of the one from the package root. In gt-tanstack-start, call setupRouterGTIntegration({ router }) from 'gt-tanstack-start/compat'`});function s(){let e=r(a());if(!e)throw Error(o);return e}export{a as getDictionaryContext,s as useDictionaryContext};
2
+ //# sourceMappingURL=DictionaryContext.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DictionaryContext.mjs","names":[],"sources":["../../src/compat/DictionaryContext.ts"],"sourcesContent":["import { createGlobalSingleton, type Locale } from 'gt-i18n/internal';\nimport type { Dictionary } from 'gt-i18n/internal/compat';\nimport { createDiagnosticMessage } from 'generaltranslation/diagnostics';\nimport { createContext, useContext, type Context } from 'react';\nimport type { CompatStore } from './CompatStore';\nimport type { OnMissingDictionaryEntry, OnMissingDictionaryObj } from './types';\n\ntype DictionaryContextType = {\n /**\n * Dictionaries streamed from the server, keyed by locale\n */\n dictionariesSnapshot: Record<Locale, Dictionary>;\n /**\n * CompatStore syncs DictionaryManager updates with renders\n */\n compatStore: CompatStore;\n /**\n * Custom override behavior on missing dictionary entries\n * Used for server triggering dictionary hmr b/c no access to useEffect\n */\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst dictionaryContextSingleton = createGlobalSingleton<\n Context<DictionaryContextType | undefined>\n>({\n namespace: 'reactCore',\n key: 'dictionaryContext',\n source: '@generaltranslation/react-core',\n notInitialized: () =>\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'Cannot read DictionaryContext before it has been initialized',\n }),\n});\n\nexport function getDictionaryContext(): Context<\n DictionaryContextType | undefined\n> {\n // Lazily create the React context once and share it across instances.\n if (!dictionaryContextSingleton.isInitialized()) {\n dictionaryContextSingleton.set(\n createContext<DictionaryContextType | undefined>(undefined)\n );\n }\n return dictionaryContextSingleton.get();\n}\n\nconst missingDictionaryProviderError = createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened:\n 'useTranslations() was called outside a GTProvider from a /compat entry',\n why: 'only the /compat GTProvider supplies the dictionaries useTranslations() reads',\n fix: \"Render GTProvider from your GT package's /compat entry, such as 'gt-react/compat', 'gt-next/compat' or 'gt-react-native/compat', instead of the one from the package root. In gt-tanstack-start, call setupRouterGTIntegration({ router }) from 'gt-tanstack-start/compat'\",\n});\n\nexport function useDictionaryContext(): DictionaryContextType {\n const context = useContext(getDictionaryContext());\n if (!context) throw new Error(missingDictionaryProviderError);\n return context;\n}\n"],"mappings":"wLAwBA,MAAM,EAA6B,EAEjC,CACA,UAAW,YACX,IAAK,oBACL,OAAQ,iCACR,mBACE,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aACE,+DACH,CAAC,CACL,CAAC,CAEF,SAAgB,GAEd,CAOA,OALK,EAA2B,eAAe,EAC7C,EAA2B,IACzB,EAAiD,IAAA,GAAU,CAC5D,CAEI,EAA2B,KAAK,CAGzC,MAAM,EAAiC,EAAwB,CAC7D,OAAQ,iCACR,SAAU,QACV,aACE,yEACF,IAAK,gFACL,IAAK,6QACN,CAAC,CAEF,SAAgB,GAA8C,CAC5D,IAAM,EAAU,EAAW,GAAsB,CAAC,CAClD,GAAI,CAAC,EAAS,MAAU,MAAM,EAA+B,CAC7D,OAAO"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./CompatStore.cjs`),t=require(`./DictionaryContext.cjs`);let n=require(`react/jsx-runtime`),r=require(`react`);const i=t.getDictionaryContext(),a={};function o({children:t,dictionaries:o=a,compatStore:s,onMissingDictionaryEntry:c,onMissingDictionaryObj:l}){let u=(0,r.useRef)(null);s==null&&u.current==null&&(u.current=new e.CompatStore);let d=s??u.current,f=(0,r.useMemo)(()=>({dictionariesSnapshot:o,compatStore:d,onMissingDictionaryEntry:c,onMissingDictionaryObj:l}),[o,d,c,l]);return(0,r.useEffect)(()=>{d.updateDictionaries(o)},[o,d]),(0,n.jsx)(i.Provider,{value:f,children:t})}exports.DictionaryProvider=o;
2
+ //# sourceMappingURL=DictionaryProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DictionaryProvider.cjs","names":["getDictionaryContext","CompatStore"],"sources":["../../src/compat/DictionaryProvider.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, type ReactNode } from 'react';\nimport type { Dictionary } from 'gt-i18n/internal/compat';\nimport type { Locale } from 'gt-i18n/internal';\nimport { CompatStore } from './CompatStore';\nimport { getDictionaryContext } from './DictionaryContext';\nimport type { OnMissingDictionaryEntry, OnMissingDictionaryObj } from './types';\n\nexport type DictionaryProviderProps = {\n children?: ReactNode;\n // For streaming dictionaries from the server\n dictionaries?: Record<Locale, Dictionary>;\n // Defaults to a store owned by this provider\n compatStore?: CompatStore;\n // Custom override missing dictionary behavior for dev hot reload\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst DictionaryContext = getDictionaryContext();\nconst EMPTY_DICTIONARIES: Record<Locale, Dictionary> = {};\n\n/**\n * Shared dictionary provider logic for the key-based (compat) API. Not\n * user-facing: runtime packages wrap it with their own loading.\n */\nexport function DictionaryProvider({\n children,\n dictionaries = EMPTY_DICTIONARIES,\n compatStore: compatStoreProp,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n}: DictionaryProviderProps) {\n const ownStoreRef = useRef<CompatStore | null>(null);\n if (compatStoreProp == null && ownStoreRef.current == null) {\n ownStoreRef.current = new CompatStore();\n }\n const compatStore = compatStoreProp ?? ownStoreRef.current!;\n\n const value = useMemo(\n () => ({\n dictionariesSnapshot: dictionaries,\n compatStore,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n }),\n [\n dictionaries,\n compatStore,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n ]\n );\n\n // Update the dictionary manager with data from the server, do not emit events\n useEffect(() => {\n compatStore.updateDictionaries(dictionaries);\n }, [dictionaries, compatStore]);\n\n return (\n <DictionaryContext.Provider value={value}>\n {children}\n </DictionaryContext.Provider>\n );\n}\n"],"mappings":"6KAkBA,MAAM,EAAoBA,EAAAA,sBAAsB,CAC1C,EAAiD,EAAE,CAMzD,SAAgB,EAAmB,CACjC,WACA,eAAe,EACf,YAAa,EACb,2BACA,0BAC0B,CAC1B,IAAM,GAAA,EAAA,EAAA,QAAyC,KAAK,CAChD,GAAmB,MAAQ,EAAY,SAAW,OACpD,EAAY,QAAU,IAAIC,EAAAA,aAE5B,IAAM,EAAc,GAAmB,EAAY,QAE7C,GAAA,EAAA,EAAA,cACG,CACL,qBAAsB,EACtB,cACA,2BACA,yBACD,EACD,CACE,EACA,EACA,EACA,EACD,CACF,CAOD,OAJA,EAAA,EAAA,eAAgB,CACd,EAAY,mBAAmB,EAAa,EAC3C,CAAC,EAAc,EAAY,CAAC,EAG7B,EAAA,EAAA,KAAC,EAAkB,SAAnB,CAAmC,QAChC,WAC0B,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { OnMissingDictionaryEntry, OnMissingDictionaryObj } from "./types.js";
2
+ import { CompatStore } from "./CompatStore.js";
3
+ import { Locale } from "gt-i18n/internal";
4
+ import { Dictionary } from "gt-i18n/internal/compat";
5
+ import * as _$react_jsx_runtime0 from "react/jsx-runtime";
6
+ import { ReactNode } from "react";
7
+
8
+ //#region src/compat/DictionaryProvider.d.ts
9
+ type DictionaryProviderProps = {
10
+ children?: ReactNode;
11
+ dictionaries?: Record<Locale, Dictionary>;
12
+ compatStore?: CompatStore;
13
+ onMissingDictionaryEntry?: OnMissingDictionaryEntry;
14
+ onMissingDictionaryObj?: OnMissingDictionaryObj;
15
+ };
16
+ /**
17
+ * Shared dictionary provider logic for the key-based (compat) API. Not
18
+ * user-facing: runtime packages wrap it with their own loading.
19
+ */
20
+ declare function DictionaryProvider({
21
+ children,
22
+ dictionaries,
23
+ compatStore: compatStoreProp,
24
+ onMissingDictionaryEntry,
25
+ onMissingDictionaryObj
26
+ }: DictionaryProviderProps): _$react_jsx_runtime0.JSX.Element;
27
+ //#endregion
28
+ export { DictionaryProvider, DictionaryProviderProps };
29
+ //# sourceMappingURL=DictionaryProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DictionaryProvider.d.ts","names":[],"sources":["../../src/compat/DictionaryProvider.tsx"],"mappings":";;;;;;;;KAOY,uBAAA;EACV,QAAA,GAAW,SAAA;EAEX,YAAA,GAAe,MAAA,CAAO,MAAA,EAAQ,UAAA;EAE9B,WAAA,GAAc,WAAA;EAEd,wBAAA,GAA2B,wBAAA;EAC3B,sBAAA,GAAyB,sBAAA;AAAA;;;;;iBAUX,kBAAA,CAAA;EACd,QAAA;EACA,YAAA;EACA,WAAA,EAAa,eAAA;EACb,wBAAA;EACA;AAAA,GACC,uBAAA,GAAuB,oBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,2 @@
1
+ import{CompatStore as e}from"./CompatStore.mjs";import{getDictionaryContext as t}from"./DictionaryContext.mjs";import{jsx as n}from"react/jsx-runtime";import{useEffect as r,useMemo as i,useRef as a}from"react";const o=t(),s={};function c({children:t,dictionaries:c=s,compatStore:l,onMissingDictionaryEntry:u,onMissingDictionaryObj:d}){let f=a(null);l==null&&f.current==null&&(f.current=new e);let p=l??f.current,m=i(()=>({dictionariesSnapshot:c,compatStore:p,onMissingDictionaryEntry:u,onMissingDictionaryObj:d}),[c,p,u,d]);return r(()=>{p.updateDictionaries(c)},[c,p]),n(o.Provider,{value:m,children:t})}export{c as DictionaryProvider};
2
+ //# sourceMappingURL=DictionaryProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DictionaryProvider.mjs","names":[],"sources":["../../src/compat/DictionaryProvider.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, type ReactNode } from 'react';\nimport type { Dictionary } from 'gt-i18n/internal/compat';\nimport type { Locale } from 'gt-i18n/internal';\nimport { CompatStore } from './CompatStore';\nimport { getDictionaryContext } from './DictionaryContext';\nimport type { OnMissingDictionaryEntry, OnMissingDictionaryObj } from './types';\n\nexport type DictionaryProviderProps = {\n children?: ReactNode;\n // For streaming dictionaries from the server\n dictionaries?: Record<Locale, Dictionary>;\n // Defaults to a store owned by this provider\n compatStore?: CompatStore;\n // Custom override missing dictionary behavior for dev hot reload\n onMissingDictionaryEntry?: OnMissingDictionaryEntry;\n onMissingDictionaryObj?: OnMissingDictionaryObj;\n};\n\nconst DictionaryContext = getDictionaryContext();\nconst EMPTY_DICTIONARIES: Record<Locale, Dictionary> = {};\n\n/**\n * Shared dictionary provider logic for the key-based (compat) API. Not\n * user-facing: runtime packages wrap it with their own loading.\n */\nexport function DictionaryProvider({\n children,\n dictionaries = EMPTY_DICTIONARIES,\n compatStore: compatStoreProp,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n}: DictionaryProviderProps) {\n const ownStoreRef = useRef<CompatStore | null>(null);\n if (compatStoreProp == null && ownStoreRef.current == null) {\n ownStoreRef.current = new CompatStore();\n }\n const compatStore = compatStoreProp ?? ownStoreRef.current!;\n\n const value = useMemo(\n () => ({\n dictionariesSnapshot: dictionaries,\n compatStore,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n }),\n [\n dictionaries,\n compatStore,\n onMissingDictionaryEntry,\n onMissingDictionaryObj,\n ]\n );\n\n // Update the dictionary manager with data from the server, do not emit events\n useEffect(() => {\n compatStore.updateDictionaries(dictionaries);\n }, [dictionaries, compatStore]);\n\n return (\n <DictionaryContext.Provider value={value}>\n {children}\n </DictionaryContext.Provider>\n );\n}\n"],"mappings":"kNAkBA,MAAM,EAAoB,GAAsB,CAC1C,EAAiD,EAAE,CAMzD,SAAgB,EAAmB,CACjC,WACA,eAAe,EACf,YAAa,EACb,2BACA,0BAC0B,CAC1B,IAAM,EAAc,EAA2B,KAAK,CAChD,GAAmB,MAAQ,EAAY,SAAW,OACpD,EAAY,QAAU,IAAI,GAE5B,IAAM,EAAc,GAAmB,EAAY,QAE7C,EAAQ,OACL,CACL,qBAAsB,EACtB,cACA,2BACA,yBACD,EACD,CACE,EACA,EACA,EACA,EACD,CACF,CAOD,OAJA,MAAgB,CACd,EAAY,mBAAmB,EAAa,EAC3C,CAAC,EAAc,EAAY,CAAC,CAG7B,EAAC,EAAkB,SAAnB,CAAmC,QAChC,WAC0B,CAAA"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`gt-i18n/internal/compat`);function t(t,n){return(0,e.getDictionaryEntry)(r(t,n))}function n(e,t){return r(e,t)}function r(t,{locale:n,id:r}){let a=t[n];if(!a)return;if(!r)return a;let o=a;for(let t of r.split(`.`)){if(!i(t)||!(0,e.isDictionaryValue)(o)||!Object.prototype.hasOwnProperty.call(o,t))return;o=o[t]}return o}function i(e){return e!==`__proto__`&&e!==`constructor`&&e!==`prototype`}exports.lookupDictionaryEntry=t,exports.lookupDictionaryObject=n;
2
+ //# sourceMappingURL=dictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionaries.cjs","names":[],"sources":["../../src/compat/dictionaries.ts"],"sourcesContent":["import type { Locale } from 'gt-i18n/internal';\nimport {\n getDictionaryEntry,\n isDictionaryValue,\n type Dictionary,\n type DictionaryObject,\n} from 'gt-i18n/internal/compat';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from './types';\n\nexport function lookupDictionaryEntry(\n dictionariesSnapshot: Record<Locale, Dictionary>,\n lookup: DictionaryLookup\n): DictionaryEntrySnapshot {\n return getDictionaryEntry(\n lookupDictionaryValue(dictionariesSnapshot, lookup)\n );\n}\n\nexport function lookupDictionaryObject(\n dictionariesSnapshot: Record<Locale, Dictionary>,\n lookup: DictionaryLookup\n): DictionaryObjectSnapshot {\n return lookupDictionaryValue(dictionariesSnapshot, lookup);\n}\n\nfunction lookupDictionaryValue(\n dictionariesSnapshot: Record<Locale, Dictionary>,\n { locale, id }: DictionaryLookup\n): DictionaryObjectSnapshot {\n const dictionary = dictionariesSnapshot[locale];\n if (!dictionary) return undefined;\n if (!id) return dictionary;\n\n let current: DictionaryObject | undefined = dictionary;\n for (const segment of id.split('.')) {\n if (!isSafeDictionaryPathSegment(segment)) return undefined;\n if (!isDictionaryValue(current)) return undefined;\n if (!Object.prototype.hasOwnProperty.call(current, segment)) {\n return undefined;\n }\n current = current[segment];\n }\n return current;\n}\n\nfunction isSafeDictionaryPathSegment(segment: string): boolean {\n return (\n segment !== '__proto__' &&\n segment !== 'constructor' &&\n segment !== 'prototype'\n );\n}\n"],"mappings":"sFAaA,SAAgB,EACd,EACA,EACyB,CACzB,OAAA,EAAA,EAAA,oBACE,EAAsB,EAAsB,EAAO,CACpD,CAGH,SAAgB,EACd,EACA,EAC0B,CAC1B,OAAO,EAAsB,EAAsB,EAAO,CAG5D,SAAS,EACP,EACA,CAAE,SAAQ,MACgB,CAC1B,IAAM,EAAa,EAAqB,GACxC,GAAI,CAAC,EAAY,OACjB,GAAI,CAAC,EAAI,OAAO,EAEhB,IAAI,EAAwC,EAC5C,IAAK,IAAM,KAAW,EAAG,MAAM,IAAI,CAAE,CAGnC,GAFI,CAAC,EAA4B,EAAQ,EACrC,EAAA,EAAA,EAAA,mBAAmB,EAAQ,EAC3B,CAAC,OAAO,UAAU,eAAe,KAAK,EAAS,EAAQ,CACzD,OAEF,EAAU,EAAQ,GAEpB,OAAO,EAGT,SAAS,EAA4B,EAA0B,CAC7D,OACE,IAAY,aACZ,IAAY,eACZ,IAAY"}
@@ -0,0 +1,2 @@
1
+ import{getDictionaryEntry as e,isDictionaryValue as t}from"gt-i18n/internal/compat";function n(t,n){return e(i(t,n))}function r(e,t){return i(e,t)}function i(e,{locale:n,id:r}){let i=e[n];if(!i)return;if(!r)return i;let o=i;for(let e of r.split(`.`)){if(!a(e)||!t(o)||!Object.prototype.hasOwnProperty.call(o,e))return;o=o[e]}return o}function a(e){return e!==`__proto__`&&e!==`constructor`&&e!==`prototype`}export{n as lookupDictionaryEntry,r as lookupDictionaryObject};
2
+ //# sourceMappingURL=dictionaries.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionaries.mjs","names":[],"sources":["../../src/compat/dictionaries.ts"],"sourcesContent":["import type { Locale } from 'gt-i18n/internal';\nimport {\n getDictionaryEntry,\n isDictionaryValue,\n type Dictionary,\n type DictionaryObject,\n} from 'gt-i18n/internal/compat';\nimport type {\n DictionaryEntrySnapshot,\n DictionaryLookup,\n DictionaryObjectSnapshot,\n} from './types';\n\nexport function lookupDictionaryEntry(\n dictionariesSnapshot: Record<Locale, Dictionary>,\n lookup: DictionaryLookup\n): DictionaryEntrySnapshot {\n return getDictionaryEntry(\n lookupDictionaryValue(dictionariesSnapshot, lookup)\n );\n}\n\nexport function lookupDictionaryObject(\n dictionariesSnapshot: Record<Locale, Dictionary>,\n lookup: DictionaryLookup\n): DictionaryObjectSnapshot {\n return lookupDictionaryValue(dictionariesSnapshot, lookup);\n}\n\nfunction lookupDictionaryValue(\n dictionariesSnapshot: Record<Locale, Dictionary>,\n { locale, id }: DictionaryLookup\n): DictionaryObjectSnapshot {\n const dictionary = dictionariesSnapshot[locale];\n if (!dictionary) return undefined;\n if (!id) return dictionary;\n\n let current: DictionaryObject | undefined = dictionary;\n for (const segment of id.split('.')) {\n if (!isSafeDictionaryPathSegment(segment)) return undefined;\n if (!isDictionaryValue(current)) return undefined;\n if (!Object.prototype.hasOwnProperty.call(current, segment)) {\n return undefined;\n }\n current = current[segment];\n }\n return current;\n}\n\nfunction isSafeDictionaryPathSegment(segment: string): boolean {\n return (\n segment !== '__proto__' &&\n segment !== 'constructor' &&\n segment !== 'prototype'\n );\n}\n"],"mappings":"oFAaA,SAAgB,EACd,EACA,EACyB,CACzB,OAAO,EACL,EAAsB,EAAsB,EAAO,CACpD,CAGH,SAAgB,EACd,EACA,EAC0B,CAC1B,OAAO,EAAsB,EAAsB,EAAO,CAG5D,SAAS,EACP,EACA,CAAE,SAAQ,MACgB,CAC1B,IAAM,EAAa,EAAqB,GACxC,GAAI,CAAC,EAAY,OACjB,GAAI,CAAC,EAAI,OAAO,EAEhB,IAAI,EAAwC,EAC5C,IAAK,IAAM,KAAW,EAAG,MAAM,IAAI,CAAE,CAGnC,GAFI,CAAC,EAA4B,EAAQ,EACrC,CAAC,EAAkB,EAAQ,EAC3B,CAAC,OAAO,UAAU,eAAe,KAAK,EAAS,EAAQ,CACzD,OAEF,EAAU,EAAQ,GAEpB,OAAO,EAGT,SAAS,EAA4B,EAA0B,CAC7D,OACE,IAAY,aACZ,IAAY,eACZ,IAAY"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/utils.cjs`),t=require(`../hooks/utils/missing-translation.cjs`),n=require(`./DictionaryContext.cjs`);let r=require(`react`),i=require(`gt-i18n/internal/compat`);const a=()=>{},o=()=>{};function s(){let{compatStore:r}=n.useDictionaryContext();return t.useDevHotReloadQueue(e.useShouldTranslate(),({type:e,lookup:t})=>{switch(e){case`dictionaryEntry`:r.translateDictionaryEntry(t);break;case`dictionaryObject`:r.translateDictionaryObject(t);break}})}function c(){return a}function l(){let e=n.useDictionaryContext().onMissingDictionaryEntry,t=s();return(0,r.useCallback)(n=>{e?e(n):t((0,i.getDictionaryListenerKey)(n),{type:`dictionaryEntry`,lookup:n})},[e,t])}function u(){return o}function d(){let e=n.useDictionaryContext().onMissingDictionaryObj,t=s();return(0,r.useCallback)(n=>{e?e(n):t((0,i.getDictionaryListenerKey)(n),{type:`dictionaryObject`,lookup:n})},[e,t])}const f=process.env.NODE_ENV===`production`?c:l,p=process.env.NODE_ENV===`production`?u:d;exports.useHandleMissingDictionaryEntry=f,exports.useHandleMissingDictionaryObject=p;
2
+ //# sourceMappingURL=missing-dictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"missing-dictionary.cjs","names":["useDictionaryContext","useDevHotReloadQueue","useShouldTranslate"],"sources":["../../src/compat/missing-dictionary.ts"],"sourcesContent":["import { getDictionaryListenerKey } from 'gt-i18n/internal/compat';\nimport { useCallback } from 'react';\nimport { useShouldTranslate } from '../hooks/utils';\nimport { useDevHotReloadQueue } from '../hooks/utils/missing-translation';\nimport { useDictionaryContext } from './DictionaryContext';\nimport type {\n DictionaryLookup,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from './types';\n\ntype PendingDictionaryLookup = {\n type: 'dictionaryEntry' | 'dictionaryObject';\n lookup: DictionaryLookup;\n};\n\n/**\n * Dictionary counterpart of the native missing-translation handlers. Runtimes\n * that cannot run effects (server) pass their own onMissingDictionary*\n * callbacks through DictionaryProvider; otherwise misses are queued and\n * translated after commit.\n */\n\nconst noopOnMissingDictionaryEntry: OnMissingDictionaryEntry = () => {};\nconst noopOnMissingDictionaryObj: OnMissingDictionaryObj = () => {};\n\nfunction useDictionaryHotReloadQueue() {\n const { compatStore } = useDictionaryContext();\n return useDevHotReloadQueue<PendingDictionaryLookup>(\n useShouldTranslate(),\n ({ type, lookup }) => {\n switch (type) {\n case 'dictionaryEntry':\n compatStore.translateDictionaryEntry(lookup);\n break;\n case 'dictionaryObject':\n compatStore.translateDictionaryObject(lookup);\n break;\n }\n }\n );\n}\n\nfunction useHandleMissingDictionaryEntryProd(): OnMissingDictionaryEntry {\n return noopOnMissingDictionaryEntry;\n}\n\nfunction useHandleMissingDictionaryEntryDev(): OnMissingDictionaryEntry {\n const customHandleMissing = useDictionaryContext().onMissingDictionaryEntry;\n const pureHandleMissing = useDictionaryHotReloadQueue();\n\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryEntry',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nfunction useHandleMissingDictionaryObjectProd(): OnMissingDictionaryObj {\n return noopOnMissingDictionaryObj;\n}\n\nfunction useHandleMissingDictionaryObjectDev(): OnMissingDictionaryObj {\n const customHandleMissing = useDictionaryContext().onMissingDictionaryObj;\n const pureHandleMissing = useDictionaryHotReloadQueue();\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryObject',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nexport const useHandleMissingDictionaryEntry: () => OnMissingDictionaryEntry =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryEntryProd\n : useHandleMissingDictionaryEntryDev;\n\nexport const useHandleMissingDictionaryObject: () => OnMissingDictionaryObj =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryObjectProd\n : useHandleMissingDictionaryObjectDev;\n"],"mappings":"wOAuBA,MAAM,MAA+D,GAC/D,MAA2D,GAEjE,SAAS,GAA8B,CACrC,GAAM,CAAE,eAAgBA,EAAAA,sBAAsB,CAC9C,OAAOC,EAAAA,qBACLC,EAAAA,oBAAoB,EACnB,CAAE,OAAM,YAAa,CACpB,OAAQ,EAAR,CACE,IAAK,kBACH,EAAY,yBAAyB,EAAO,CAC5C,MACF,IAAK,mBACH,EAAY,0BAA0B,EAAO,CAC7C,QAGP,CAGH,SAAS,GAAgE,CACvE,OAAO,EAGT,SAAS,GAA+D,CACtE,IAAM,EAAsBF,EAAAA,sBAAsB,CAAC,yBAC7C,EAAoB,GAA6B,CAEvD,OAAA,EAAA,EAAA,aACG,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,GAAA,EAAA,EAAA,0BAA2C,EAAO,CAAE,CAClD,KAAM,kBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,SAAS,GAA+D,CACtE,OAAO,EAGT,SAAS,GAA8D,CACrE,IAAM,EAAsBA,EAAAA,sBAAsB,CAAC,uBAC7C,EAAoB,GAA6B,CACvD,OAAA,EAAA,EAAA,aACG,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,GAAA,EAAA,EAAA,0BAA2C,EAAO,CAAE,CAClD,KAAM,mBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,MAAa,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EACX,QAAQ,IAAI,WAAa,aACrB,EACA"}
@@ -0,0 +1,2 @@
1
+ import{useShouldTranslate as e}from"../hooks/utils.mjs";import{useDevHotReloadQueue as t}from"../hooks/utils/missing-translation.mjs";import{useDictionaryContext as n}from"./DictionaryContext.mjs";import{useCallback as r}from"react";import{getDictionaryListenerKey as i}from"gt-i18n/internal/compat";const a=()=>{},o=()=>{};function s(){let{compatStore:r}=n();return t(e(),({type:e,lookup:t})=>{switch(e){case`dictionaryEntry`:r.translateDictionaryEntry(t);break;case`dictionaryObject`:r.translateDictionaryObject(t);break}})}function c(){return a}function l(){let e=n().onMissingDictionaryEntry,t=s();return r(n=>{e?e(n):t(i(n),{type:`dictionaryEntry`,lookup:n})},[e,t])}function u(){return o}function d(){let e=n().onMissingDictionaryObj,t=s();return r(n=>{e?e(n):t(i(n),{type:`dictionaryObject`,lookup:n})},[e,t])}const f=process.env.NODE_ENV===`production`?c:l,p=process.env.NODE_ENV===`production`?u:d;export{f as useHandleMissingDictionaryEntry,p as useHandleMissingDictionaryObject};
2
+ //# sourceMappingURL=missing-dictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"missing-dictionary.mjs","names":[],"sources":["../../src/compat/missing-dictionary.ts"],"sourcesContent":["import { getDictionaryListenerKey } from 'gt-i18n/internal/compat';\nimport { useCallback } from 'react';\nimport { useShouldTranslate } from '../hooks/utils';\nimport { useDevHotReloadQueue } from '../hooks/utils/missing-translation';\nimport { useDictionaryContext } from './DictionaryContext';\nimport type {\n DictionaryLookup,\n OnMissingDictionaryEntry,\n OnMissingDictionaryObj,\n} from './types';\n\ntype PendingDictionaryLookup = {\n type: 'dictionaryEntry' | 'dictionaryObject';\n lookup: DictionaryLookup;\n};\n\n/**\n * Dictionary counterpart of the native missing-translation handlers. Runtimes\n * that cannot run effects (server) pass their own onMissingDictionary*\n * callbacks through DictionaryProvider; otherwise misses are queued and\n * translated after commit.\n */\n\nconst noopOnMissingDictionaryEntry: OnMissingDictionaryEntry = () => {};\nconst noopOnMissingDictionaryObj: OnMissingDictionaryObj = () => {};\n\nfunction useDictionaryHotReloadQueue() {\n const { compatStore } = useDictionaryContext();\n return useDevHotReloadQueue<PendingDictionaryLookup>(\n useShouldTranslate(),\n ({ type, lookup }) => {\n switch (type) {\n case 'dictionaryEntry':\n compatStore.translateDictionaryEntry(lookup);\n break;\n case 'dictionaryObject':\n compatStore.translateDictionaryObject(lookup);\n break;\n }\n }\n );\n}\n\nfunction useHandleMissingDictionaryEntryProd(): OnMissingDictionaryEntry {\n return noopOnMissingDictionaryEntry;\n}\n\nfunction useHandleMissingDictionaryEntryDev(): OnMissingDictionaryEntry {\n const customHandleMissing = useDictionaryContext().onMissingDictionaryEntry;\n const pureHandleMissing = useDictionaryHotReloadQueue();\n\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryEntry',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nfunction useHandleMissingDictionaryObjectProd(): OnMissingDictionaryObj {\n return noopOnMissingDictionaryObj;\n}\n\nfunction useHandleMissingDictionaryObjectDev(): OnMissingDictionaryObj {\n const customHandleMissing = useDictionaryContext().onMissingDictionaryObj;\n const pureHandleMissing = useDictionaryHotReloadQueue();\n return useCallback(\n (lookup: DictionaryLookup) => {\n if (customHandleMissing) {\n customHandleMissing(lookup);\n } else {\n pureHandleMissing(getDictionaryListenerKey(lookup), {\n type: 'dictionaryObject',\n lookup,\n });\n }\n },\n [customHandleMissing, pureHandleMissing]\n );\n}\n\nexport const useHandleMissingDictionaryEntry: () => OnMissingDictionaryEntry =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryEntryProd\n : useHandleMissingDictionaryEntryDev;\n\nexport const useHandleMissingDictionaryObject: () => OnMissingDictionaryObj =\n process.env.NODE_ENV === 'production'\n ? useHandleMissingDictionaryObjectProd\n : useHandleMissingDictionaryObjectDev;\n"],"mappings":"4SAuBA,MAAM,MAA+D,GAC/D,MAA2D,GAEjE,SAAS,GAA8B,CACrC,GAAM,CAAE,eAAgB,GAAsB,CAC9C,OAAO,EACL,GAAoB,EACnB,CAAE,OAAM,YAAa,CACpB,OAAQ,EAAR,CACE,IAAK,kBACH,EAAY,yBAAyB,EAAO,CAC5C,MACF,IAAK,mBACH,EAAY,0BAA0B,EAAO,CAC7C,QAGP,CAGH,SAAS,GAAgE,CACvE,OAAO,EAGT,SAAS,GAA+D,CACtE,IAAM,EAAsB,GAAsB,CAAC,yBAC7C,EAAoB,GAA6B,CAEvD,OAAO,EACJ,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,EAAkB,EAAyB,EAAO,CAAE,CAClD,KAAM,kBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,SAAS,GAA+D,CACtE,OAAO,EAGT,SAAS,GAA8D,CACrE,IAAM,EAAsB,GAAsB,CAAC,uBAC7C,EAAoB,GAA6B,CACvD,OAAO,EACJ,GAA6B,CACxB,EACF,EAAoB,EAAO,CAE3B,EAAkB,EAAyB,EAAO,CAAE,CAClD,KAAM,mBACN,SACD,CAAC,EAGN,CAAC,EAAqB,EAAkB,CACzC,CAGH,MAAa,EACX,QAAQ,IAAI,WAAa,aACrB,EACA,EAEO,EACX,QAAQ,IAAI,WAAa,aACrB,EACA"}
@@ -0,0 +1,15 @@
1
+ import { DictionaryEntry, DictionaryObject } from "gt-i18n/internal/compat";
2
+
3
+ //#region src/compat/types.d.ts
4
+ type DictionaryLookup = {
5
+ locale: string;
6
+ id: string;
7
+ };
8
+ type DictionaryStoreListener = (event: DictionaryLookup) => void;
9
+ type DictionaryEntrySnapshot = DictionaryEntry | undefined;
10
+ type DictionaryObjectSnapshot = DictionaryObject | undefined;
11
+ type OnMissingDictionaryEntry = (lookup: DictionaryLookup) => void;
12
+ type OnMissingDictionaryObj = (lookup: DictionaryLookup) => void;
13
+ //#endregion
14
+ export { DictionaryEntrySnapshot, DictionaryLookup, DictionaryObjectSnapshot, DictionaryStoreListener, OnMissingDictionaryEntry, OnMissingDictionaryObj };
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/compat/types.ts"],"mappings":";;;KAKY,gBAAA;EACV,MAAA;EACA,EAAA;AAAA;AAAA,KAGU,uBAAA,IAA2B,KAAA,EAAO,gBAAA;AAAA,KAElC,uBAAA,GAA0B,eAAA;AAAA,KAC1B,wBAAA,GAA2B,gBAAA;AAAA,KAE3B,wBAAA,IAA4B,MAAA,EAAQ,gBAAA;AAAA,KAEpC,sBAAA,IAA0B,MAAA,EAAQ,gBAAA"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/external-store/useSubscribeToTrackedLookups.cjs`),t=require(`./DictionaryContext.cjs`),n=require(`./missing-dictionary.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`),a=require(`gt-i18n/internal/compat`);function o(){let{dictionariesSnapshot:o,compatStore:s}=t.useDictionaryContext(),c=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),l=n.useHandleMissingDictionaryObject(),u=(0,i.useRef)(null);return u.current??=new Set,(0,i.useCallback)(e=>{let t=(0,a.getDictionaryListenerKey)(e);c&&u.current.add(t);let n=s.getDictionaryObjectSnapshot(e,o);return n==null&&c&&l(e),n},[s,o,c,l,e.useSubscribeToTrackedLookups(u,s.subscribeToDictionaryObjectEvents,a.getDictionaryListenerKey)])}exports.useTrackedDictionaryObjResolver=o;
2
+ //# sourceMappingURL=useTrackedDictionaryObjResolver.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTrackedDictionaryObjResolver.cjs","names":["useDictionaryContext","useHandleMissingDictionaryObject","useSubscribeToTrackedLookups","getDictionaryListenerKey"],"sources":["../../src/compat/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { getDictionaryListenerKey } from 'gt-i18n/internal/compat';\nimport type { DictionaryLookup, DictionaryObjectSnapshot } from './types';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from './missing-dictionary';\nimport { useDictionaryContext } from './DictionaryContext';\nimport { useSubscribeToTrackedLookups } from '../hooks/external-store/useSubscribeToTrackedLookups';\n\ntype TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const { dictionariesSnapshot, compatStore } = useDictionaryContext();\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 const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n compatStore.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 = compatStore.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 // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n compatStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"8RAaA,SAAgB,GAAgE,CAC9E,GAAM,CAAE,uBAAsB,eAAgBA,EAAAA,sBAAsB,CAC9D,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,KAW/B,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAY,4BACnC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAGT,CACE,EACA,EACA,EACA,EAjC0BC,EAAAA,6BAC5B,EACA,EAAY,kCACZC,EAAAA,yBA+BuB,CACtB,CACF"}
@@ -0,0 +1,2 @@
1
+ import{useSubscribeToTrackedLookups as e}from"../hooks/external-store/useSubscribeToTrackedLookups.mjs";import{useDictionaryContext as t}from"./DictionaryContext.mjs";import{useHandleMissingDictionaryObject as n}from"./missing-dictionary.mjs";import{getI18nConfig as r}from"gt-i18n/internal";import{useCallback as i,useRef as a}from"react";import{getDictionaryListenerKey as o}from"gt-i18n/internal/compat";function s(){let{dictionariesSnapshot:s,compatStore:c}=t(),l=process.env.NODE_ENV!==`production`&&r().isDevHotReloadEnabled(),u=n(),d=a(null);return d.current??=new Set,i(e=>{let t=o(e);l&&d.current.add(t);let n=c.getDictionaryObjectSnapshot(e,s);return n==null&&l&&u(e),n},[c,s,l,u,e(d,c.subscribeToDictionaryObjectEvents,o)])}export{s as useTrackedDictionaryObjResolver};
2
+ //# sourceMappingURL=useTrackedDictionaryObjResolver.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTrackedDictionaryObjResolver.mjs","names":[],"sources":["../../src/compat/useTrackedDictionaryObjResolver.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { getDictionaryListenerKey } from 'gt-i18n/internal/compat';\nimport type { DictionaryLookup, DictionaryObjectSnapshot } from './types';\nimport { useCallback, useRef } from 'react';\nimport { useHandleMissingDictionaryObject } from './missing-dictionary';\nimport { useDictionaryContext } from './DictionaryContext';\nimport { useSubscribeToTrackedLookups } from '../hooks/external-store/useSubscribeToTrackedLookups';\n\ntype TrackedDictionaryObjResolver = (\n lookup: DictionaryLookup\n) => DictionaryObjectSnapshot;\n\n// TODO: rename to useTrackedDictionaryObjectResolver\nexport function useTrackedDictionaryObjResolver(): TrackedDictionaryObjResolver {\n const { dictionariesSnapshot, compatStore } = useDictionaryContext();\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 const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n compatStore.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 = compatStore.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 // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n compatStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryObj,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"uZAaA,SAAgB,GAAgE,CAC9E,GAAM,CAAE,uBAAsB,eAAgB,GAAsB,CAC9D,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAAyB,GAAkC,CAE3D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAWxB,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAmB,EAAY,4BACnC,EACA,EACD,CAOD,OAJI,GAAoB,MAAQ,GAC9B,EAAuB,EAAO,CAGzB,GAGT,CACE,EACA,EACA,EACA,EAjC0B,EAC5B,EACA,EAAY,kCACZ,EA+BuB,CACtB,CACF"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/external-store/useSubscribeToTrackedLookups.cjs`),t=require(`./DictionaryContext.cjs`),n=require(`./missing-dictionary.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`),a=require(`gt-i18n/internal/compat`);function o(){let{dictionariesSnapshot:o,compatStore:s}=t.useDictionaryContext(),c=process.env.NODE_ENV!==`production`&&(0,r.getI18nConfig)().isDevHotReloadEnabled(),l=n.useHandleMissingDictionaryEntry(),u=(0,i.useRef)(null);return u.current??=new Set,(0,i.useCallback)(e=>{let t=(0,a.getDictionaryListenerKey)(e);c&&u.current.add(t);let n=s.getDictionaryEntrySnapshot(e,o);return n==null&&c&&l(e),n},[s,o,c,l,e.useSubscribeToTrackedLookups(u,s.subscribeToDictionaryEntryEvents,a.getDictionaryListenerKey)])}exports.useTrackedDictionaryResolver=o;
2
+ //# sourceMappingURL=useTrackedDictionaryResolver.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTrackedDictionaryResolver.cjs","names":["useDictionaryContext","useHandleMissingDictionaryEntry","useSubscribeToTrackedLookups","getDictionaryListenerKey"],"sources":["../../src/compat/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport type { DictionaryEntrySnapshot, DictionaryLookup } from './types';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { getDictionaryListenerKey } from 'gt-i18n/internal/compat';\nimport { useHandleMissingDictionaryEntry } from './missing-dictionary';\nimport { useDictionaryContext } from './DictionaryContext';\nimport { useSubscribeToTrackedLookups } from '../hooks/external-store/useSubscribeToTrackedLookups';\n\ntype TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const { dictionariesSnapshot, compatStore } = useDictionaryContext();\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 const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n compatStore.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 = compatStore.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 // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n compatStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"8RAaA,SAAgB,GAA+D,CAC7E,GAAM,CAAE,uBAAsB,eAAgBA,EAAAA,sBAAsB,CAC9D,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,KAW/B,EAAA,EAAA,aACG,GAA6B,CAE5B,IAAM,GAAA,EAAA,EAAA,0BAAqC,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAY,2BAClC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAGT,CACE,EACA,EACA,EACA,EAjC0BC,EAAAA,6BAC5B,EACA,EAAY,iCACZC,EAAAA,yBA+BuB,CACtB,CACF"}
@@ -0,0 +1,2 @@
1
+ import{useSubscribeToTrackedLookups as e}from"../hooks/external-store/useSubscribeToTrackedLookups.mjs";import{useDictionaryContext as t}from"./DictionaryContext.mjs";import{useHandleMissingDictionaryEntry as n}from"./missing-dictionary.mjs";import{getI18nConfig as r}from"gt-i18n/internal";import{useCallback as i,useRef as a}from"react";import{getDictionaryListenerKey as o}from"gt-i18n/internal/compat";function s(){let{dictionariesSnapshot:s,compatStore:c}=t(),l=process.env.NODE_ENV!==`production`&&r().isDevHotReloadEnabled(),u=n(),d=a(null);return d.current??=new Set,i(e=>{let t=o(e);l&&d.current.add(t);let n=c.getDictionaryEntrySnapshot(e,s);return n==null&&l&&u(e),n},[c,s,l,u,e(d,c.subscribeToDictionaryEntryEvents,o)])}export{s as useTrackedDictionaryResolver};
2
+ //# sourceMappingURL=useTrackedDictionaryResolver.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTrackedDictionaryResolver.mjs","names":[],"sources":["../../src/compat/useTrackedDictionaryResolver.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport type { DictionaryEntrySnapshot, DictionaryLookup } from './types';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { getDictionaryListenerKey } from 'gt-i18n/internal/compat';\nimport { useHandleMissingDictionaryEntry } from './missing-dictionary';\nimport { useDictionaryContext } from './DictionaryContext';\nimport { useSubscribeToTrackedLookups } from '../hooks/external-store/useSubscribeToTrackedLookups';\n\ntype TrackedDictionaryEntryResolver = (\n lookup: DictionaryLookup\n) => DictionaryEntrySnapshot;\n\n// TODO: rename to useTrackedDictionaryEntryResolver\nexport function useTrackedDictionaryResolver(): TrackedDictionaryEntryResolver {\n const { dictionariesSnapshot, compatStore } = useDictionaryContext();\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 const trackedLookupsVersion = useSubscribeToTrackedLookups(\n trackedKeysRef,\n compatStore.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 = compatStore.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 // trackedLookupsVersion: change identity when a tracked entry arrives\n [\n compatStore,\n dictionariesSnapshot,\n devHotReloadEnabled,\n onMissingDictionaryEntry,\n trackedLookupsVersion,\n ]\n );\n}\n"],"mappings":"sZAaA,SAAgB,GAA+D,CAC7E,GAAM,CAAE,uBAAsB,eAAgB,GAAsB,CAC9D,EACJ,QAAQ,IAAI,WAAa,cACzB,GAAe,CAAC,uBAAuB,CACnC,EAA2B,GAAiC,CAE5D,EAAiB,EAA2B,KAAK,CAavD,MAZA,CACE,EAAe,UAAU,IAAI,IAWxB,EACJ,GAA6B,CAE5B,IAAM,EAAY,EAAyB,EAAO,CAC9C,GACF,EAAe,QAAS,IAAI,EAAU,CAIxC,IAAM,EAAkB,EAAY,2BAClC,EACA,EACD,CAOD,OAJI,GAAmB,MAAQ,GAC7B,EAAyB,EAAO,CAG3B,GAGT,CACE,EACA,EACA,EACA,EAjC0B,EAC5B,EACA,EAAY,iCACZ,EA+BuB,CACtB,CACF"}
@@ -0,0 +1,2 @@
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../hooks/condition-store.cjs`),t=require(`../hooks/i18n-config.cjs`),n=require(`../hooks/utils.cjs`),r=require(`../hooks/useGT.cjs`),i=require(`./useTrackedDictionaryResolver.cjs`),a=require(`./useTrackedDictionaryObjResolver.cjs`);let o=require(`gt-i18n/internal`),s=require(`react`),c=require(`gt-i18n/internal/compat`);function l(a){let l=e.useLocale(),f=t.useDefaultLocale(),p=n.useShouldTranslate(),m=r.useGT(),h=i.useTrackedDictionaryResolver(),g=u(a),_=(0,s.useCallback)((e,t={})=>{let n=d(a,e),r=h({locale:f,id:n});if(r===void 0)throw Error(`Dictionary entry ${n} cannot be found`);let i=(0,c.resolveDictionaryLookupOptions)(r.options);if(!p)return m(r.entry,{...i,...(0,o.extractVariables)(t),$locale:f});let s=h({locale:l,id:n});return s?.entry==null?m(r.entry,{...i,...(0,o.extractVariables)(t),$locale:l}):(0,c.renderDictionaryEntry)({sourceLocale:f,targetLocale:l,sourceEntry:r,target:s.entry,dictionaryOptions:i,options:t})},[f,m,a,l,h,p]);return(0,s.useMemo)(()=>Object.assign((e,t)=>_(e,t),{obj:g}),[_,g])}function u(i){let o=e.useLocale(),l=t.useDefaultLocale(),u=n.useShouldTranslate(),f=r.useGT(),p=a.useTrackedDictionaryObjResolver();return(0,s.useCallback)(e=>{let t=d(i,e),n=p({locale:l,id:t});if(n===void 0)throw Error(`Dictionary entry ${t} cannot be found`);let r;return u&&(r=p({locale:o,id:t})),(0,c.renderDictionaryObject)({sourceObject:n,targetObject:r,translate:(e,t)=>f(e.entry,{...t,$locale:u?o:l})})},[l,i,o,p,u,f])}function d(e,t){return e?`${e}.${t}`:t}exports.useTranslations=l;
2
+ //# sourceMappingURL=useTranslations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.cjs","names":["useLocale","useDefaultLocale","useShouldTranslate","useGT","useTrackedDictionaryResolver","useTrackedDictionaryObjResolver"],"sources":["../../src/compat/useTranslations.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport { extractVariables } from 'gt-i18n/internal';\nimport {\n renderDictionaryEntry,\n renderDictionaryObject,\n resolveDictionaryLookupOptions,\n type DictionaryObjectTranslation,\n type TFunctionType,\n} from 'gt-i18n/internal/compat';\nimport { useLocale } from '../hooks/condition-store';\nimport { useGT } from '../hooks/useGT';\nimport type { TranslationVariables } from 'gt-i18n';\nimport { useDefaultLocale } from '../hooks/i18n-config';\nimport { useShouldTranslate } from '../hooks/utils';\nimport { useTrackedDictionaryResolver } from './useTrackedDictionaryResolver';\nimport { useTrackedDictionaryObjResolver } from './useTrackedDictionaryObjResolver';\n\n// ===== Hook ===== //\n\nexport function useTranslations(rootId?: string): TFunctionType {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const gt = useGT();\n const resolveDictionaryEntry = useTrackedDictionaryResolver();\n const translateObject = useTranslationsObj(rootId);\n\n const translateEntry = useCallback(\n (suffix: string, options: TranslationVariables = {}) => {\n const id = getId(rootId, suffix);\n\n const sourceEntry = resolveDictionaryEntry({\n locale: defaultLocale,\n id,\n });\n if (sourceEntry === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const sourceOptions = resolveDictionaryLookupOptions(sourceEntry.options);\n if (!shouldTranslate) {\n return gt(sourceEntry.entry, {\n ...sourceOptions,\n ...extractVariables(options),\n $locale: defaultLocale,\n });\n }\n\n const targetEntry = resolveDictionaryEntry({ locale, id });\n if (targetEntry?.entry != null) {\n return renderDictionaryEntry({\n sourceLocale: defaultLocale,\n targetLocale: locale,\n sourceEntry,\n target: targetEntry.entry,\n dictionaryOptions: sourceOptions,\n options,\n });\n }\n\n return gt(sourceEntry.entry, {\n ...sourceOptions,\n ...extractVariables(options),\n $locale: locale,\n });\n },\n [defaultLocale, gt, rootId, locale, resolveDictionaryEntry, shouldTranslate]\n );\n\n // Wrap instead of mutating translateEntry, so the returned function changes\n // identity when either translateEntry or translateObject changes\n return useMemo(\n () =>\n Object.assign(\n (suffix: string, options?: TranslationVariables) =>\n translateEntry(suffix, options),\n { obj: translateObject }\n ),\n [translateEntry, translateObject]\n );\n}\n\nfunction useTranslationsObj(rootId?: string): UseTranslationsObjFunction {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const gt = useGT();\n const resolveDictionaryObject = useTrackedDictionaryObjResolver();\n\n return useCallback(\n (suffix: string) => {\n const entryId = getId(rootId, suffix);\n const sourceObject = resolveDictionaryObject({\n locale: defaultLocale,\n id: entryId,\n });\n if (sourceObject === undefined) {\n throw new Error(`Dictionary entry ${entryId} cannot be found`);\n }\n\n let targetObject = undefined;\n if (shouldTranslate) {\n const targetLookup = { locale, id: entryId };\n targetObject = resolveDictionaryObject(targetLookup);\n }\n\n return renderDictionaryObject({\n sourceObject,\n targetObject,\n translate: (sourceEntry, dictionaryOptions) =>\n gt(sourceEntry.entry, {\n ...dictionaryOptions,\n $locale: shouldTranslate ? locale : defaultLocale,\n }),\n });\n },\n [\n defaultLocale,\n rootId,\n locale,\n resolveDictionaryObject,\n shouldTranslate,\n gt,\n ]\n );\n}\n\n// ===== Lookup Helpers ===== //\n\nfunction getId(prefix: string | undefined, suffix: string): string {\n return prefix ? `${prefix}.${suffix}` : suffix;\n}\n\n// ===== Types ===== //\n\ntype UseTranslationsObjFunction = (id: string) => DictionaryObjectTranslation;\n"],"mappings":"gYAmBA,SAAgB,EAAgB,EAAgC,CAC9D,IAAM,EAASA,EAAAA,WAAW,CACpB,EAAgBC,EAAAA,kBAAkB,CAClC,EAAkBC,EAAAA,oBAAoB,CACtC,EAAKC,EAAAA,OAAO,CACZ,EAAyBC,EAAAA,8BAA8B,CACvD,EAAkB,EAAmB,EAAO,CAE5C,GAAA,EAAA,EAAA,cACH,EAAgB,EAAgC,EAAE,GAAK,CACtD,IAAM,EAAK,EAAM,EAAQ,EAAO,CAE1B,EAAc,EAAuB,CACzC,OAAQ,EACR,KACD,CAAC,CACF,GAAI,IAAgB,IAAA,GAClB,MAAU,MAAM,oBAAoB,EAAG,kBAAkB,CAE3D,IAAM,GAAA,EAAA,EAAA,gCAA+C,EAAY,QAAQ,CACzE,GAAI,CAAC,EACH,OAAO,EAAG,EAAY,MAAO,CAC3B,GAAG,EACH,IAAA,EAAA,EAAA,kBAAoB,EAAQ,CAC5B,QAAS,EACV,CAAC,CAGJ,IAAM,EAAc,EAAuB,CAAE,SAAQ,KAAI,CAAC,CAY1D,OAXI,GAAa,OAAS,KAWnB,EAAG,EAAY,MAAO,CAC3B,GAAG,EACH,IAAA,EAAA,EAAA,kBAAoB,EAAQ,CAC5B,QAAS,EACV,CAAC,EAdA,EAAA,EAAA,uBAA6B,CAC3B,aAAc,EACd,aAAc,EACd,cACA,OAAQ,EAAY,MACpB,kBAAmB,EACnB,UACD,CAAC,EASN,CAAC,EAAe,EAAI,EAAQ,EAAQ,EAAwB,EAAgB,CAC7E,CAID,OAAA,EAAA,EAAA,aAEI,OAAO,QACJ,EAAgB,IACf,EAAe,EAAQ,EAAQ,CACjC,CAAE,IAAK,EAAiB,CACzB,CACH,CAAC,EAAgB,EAAgB,CAClC,CAGH,SAAS,EAAmB,EAA6C,CACvE,IAAM,EAASJ,EAAAA,WAAW,CACpB,EAAgBC,EAAAA,kBAAkB,CAClC,EAAkBC,EAAAA,oBAAoB,CACtC,EAAKC,EAAAA,OAAO,CACZ,EAA0BE,EAAAA,iCAAiC,CAEjE,OAAA,EAAA,EAAA,aACG,GAAmB,CAClB,IAAM,EAAU,EAAM,EAAQ,EAAO,CAC/B,EAAe,EAAwB,CAC3C,OAAQ,EACR,GAAI,EACL,CAAC,CACF,GAAI,IAAiB,IAAA,GACnB,MAAU,MAAM,oBAAoB,EAAQ,kBAAkB,CAGhE,IAAI,EAMJ,OALI,IAEF,EAAe,EAAwB,CADhB,SAAQ,GAAI,EACgB,CAAC,GAGtD,EAAA,EAAA,wBAA8B,CAC5B,eACA,eACA,WAAY,EAAa,IACvB,EAAG,EAAY,MAAO,CACpB,GAAG,EACH,QAAS,EAAkB,EAAS,EACrC,CAAC,CACL,CAAC,EAEJ,CACE,EACA,EACA,EACA,EACA,EACA,EACD,CACF,CAKH,SAAS,EAAM,EAA4B,EAAwB,CACjE,OAAO,EAAS,GAAG,EAAO,GAAG,IAAW"}
@@ -0,0 +1,7 @@
1
+ import { TFunctionType } from "gt-i18n/internal/compat";
2
+
3
+ //#region src/compat/useTranslations.d.ts
4
+ declare function useTranslations(rootId?: string): TFunctionType;
5
+ //#endregion
6
+ export { useTranslations };
7
+ //# sourceMappingURL=useTranslations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.d.ts","names":[],"sources":["../../src/compat/useTranslations.ts"],"mappings":";;;iBAmBgB,eAAA,CAAgB,MAAA,YAAkB,aAAA"}
@@ -0,0 +1,2 @@
1
+ import{useLocale as e}from"../hooks/condition-store.mjs";import{useDefaultLocale as t}from"../hooks/i18n-config.mjs";import{useShouldTranslate as n}from"../hooks/utils.mjs";import{useGT as r}from"../hooks/useGT.mjs";import{useTrackedDictionaryResolver as i}from"./useTrackedDictionaryResolver.mjs";import{useTrackedDictionaryObjResolver as a}from"./useTrackedDictionaryObjResolver.mjs";import{extractVariables as o}from"gt-i18n/internal";import{useCallback as s,useMemo as c}from"react";import{renderDictionaryEntry as l,renderDictionaryObject as u,resolveDictionaryLookupOptions as d}from"gt-i18n/internal/compat";function f(a){let u=e(),f=t(),h=n(),g=r(),_=i(),v=p(a),y=s((e,t={})=>{let n=m(a,e),r=_({locale:f,id:n});if(r===void 0)throw Error(`Dictionary entry ${n} cannot be found`);let i=d(r.options);if(!h)return g(r.entry,{...i,...o(t),$locale:f});let s=_({locale:u,id:n});return s?.entry==null?g(r.entry,{...i,...o(t),$locale:u}):l({sourceLocale:f,targetLocale:u,sourceEntry:r,target:s.entry,dictionaryOptions:i,options:t})},[f,g,a,u,_,h]);return c(()=>Object.assign((e,t)=>y(e,t),{obj:v}),[y,v])}function p(i){let o=e(),c=t(),l=n(),d=r(),f=a();return s(e=>{let t=m(i,e),n=f({locale:c,id:t});if(n===void 0)throw Error(`Dictionary entry ${t} cannot be found`);let r;return l&&(r=f({locale:o,id:t})),u({sourceObject:n,targetObject:r,translate:(e,t)=>d(e.entry,{...t,$locale:l?o:c})})},[c,i,o,f,l,d])}function m(e,t){return e?`${e}.${t}`:t}export{f as useTranslations};
2
+ //# sourceMappingURL=useTranslations.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.mjs","names":[],"sources":["../../src/compat/useTranslations.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport { extractVariables } from 'gt-i18n/internal';\nimport {\n renderDictionaryEntry,\n renderDictionaryObject,\n resolveDictionaryLookupOptions,\n type DictionaryObjectTranslation,\n type TFunctionType,\n} from 'gt-i18n/internal/compat';\nimport { useLocale } from '../hooks/condition-store';\nimport { useGT } from '../hooks/useGT';\nimport type { TranslationVariables } from 'gt-i18n';\nimport { useDefaultLocale } from '../hooks/i18n-config';\nimport { useShouldTranslate } from '../hooks/utils';\nimport { useTrackedDictionaryResolver } from './useTrackedDictionaryResolver';\nimport { useTrackedDictionaryObjResolver } from './useTrackedDictionaryObjResolver';\n\n// ===== Hook ===== //\n\nexport function useTranslations(rootId?: string): TFunctionType {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const gt = useGT();\n const resolveDictionaryEntry = useTrackedDictionaryResolver();\n const translateObject = useTranslationsObj(rootId);\n\n const translateEntry = useCallback(\n (suffix: string, options: TranslationVariables = {}) => {\n const id = getId(rootId, suffix);\n\n const sourceEntry = resolveDictionaryEntry({\n locale: defaultLocale,\n id,\n });\n if (sourceEntry === undefined) {\n throw new Error(`Dictionary entry ${id} cannot be found`);\n }\n const sourceOptions = resolveDictionaryLookupOptions(sourceEntry.options);\n if (!shouldTranslate) {\n return gt(sourceEntry.entry, {\n ...sourceOptions,\n ...extractVariables(options),\n $locale: defaultLocale,\n });\n }\n\n const targetEntry = resolveDictionaryEntry({ locale, id });\n if (targetEntry?.entry != null) {\n return renderDictionaryEntry({\n sourceLocale: defaultLocale,\n targetLocale: locale,\n sourceEntry,\n target: targetEntry.entry,\n dictionaryOptions: sourceOptions,\n options,\n });\n }\n\n return gt(sourceEntry.entry, {\n ...sourceOptions,\n ...extractVariables(options),\n $locale: locale,\n });\n },\n [defaultLocale, gt, rootId, locale, resolveDictionaryEntry, shouldTranslate]\n );\n\n // Wrap instead of mutating translateEntry, so the returned function changes\n // identity when either translateEntry or translateObject changes\n return useMemo(\n () =>\n Object.assign(\n (suffix: string, options?: TranslationVariables) =>\n translateEntry(suffix, options),\n { obj: translateObject }\n ),\n [translateEntry, translateObject]\n );\n}\n\nfunction useTranslationsObj(rootId?: string): UseTranslationsObjFunction {\n const locale = useLocale();\n const defaultLocale = useDefaultLocale();\n const shouldTranslate = useShouldTranslate();\n const gt = useGT();\n const resolveDictionaryObject = useTrackedDictionaryObjResolver();\n\n return useCallback(\n (suffix: string) => {\n const entryId = getId(rootId, suffix);\n const sourceObject = resolveDictionaryObject({\n locale: defaultLocale,\n id: entryId,\n });\n if (sourceObject === undefined) {\n throw new Error(`Dictionary entry ${entryId} cannot be found`);\n }\n\n let targetObject = undefined;\n if (shouldTranslate) {\n const targetLookup = { locale, id: entryId };\n targetObject = resolveDictionaryObject(targetLookup);\n }\n\n return renderDictionaryObject({\n sourceObject,\n targetObject,\n translate: (sourceEntry, dictionaryOptions) =>\n gt(sourceEntry.entry, {\n ...dictionaryOptions,\n $locale: shouldTranslate ? locale : defaultLocale,\n }),\n });\n },\n [\n defaultLocale,\n rootId,\n locale,\n resolveDictionaryObject,\n shouldTranslate,\n gt,\n ]\n );\n}\n\n// ===== Lookup Helpers ===== //\n\nfunction getId(prefix: string | undefined, suffix: string): string {\n return prefix ? `${prefix}.${suffix}` : suffix;\n}\n\n// ===== Types ===== //\n\ntype UseTranslationsObjFunction = (id: string) => DictionaryObjectTranslation;\n"],"mappings":"umBAmBA,SAAgB,EAAgB,EAAgC,CAC9D,IAAM,EAAS,GAAW,CACpB,EAAgB,GAAkB,CAClC,EAAkB,GAAoB,CACtC,EAAK,GAAO,CACZ,EAAyB,GAA8B,CACvD,EAAkB,EAAmB,EAAO,CAE5C,EAAiB,GACpB,EAAgB,EAAgC,EAAE,GAAK,CACtD,IAAM,EAAK,EAAM,EAAQ,EAAO,CAE1B,EAAc,EAAuB,CACzC,OAAQ,EACR,KACD,CAAC,CACF,GAAI,IAAgB,IAAA,GAClB,MAAU,MAAM,oBAAoB,EAAG,kBAAkB,CAE3D,IAAM,EAAgB,EAA+B,EAAY,QAAQ,CACzE,GAAI,CAAC,EACH,OAAO,EAAG,EAAY,MAAO,CAC3B,GAAG,EACH,GAAG,EAAiB,EAAQ,CAC5B,QAAS,EACV,CAAC,CAGJ,IAAM,EAAc,EAAuB,CAAE,SAAQ,KAAI,CAAC,CAY1D,OAXI,GAAa,OAAS,KAWnB,EAAG,EAAY,MAAO,CAC3B,GAAG,EACH,GAAG,EAAiB,EAAQ,CAC5B,QAAS,EACV,CAAC,CAdO,EAAsB,CAC3B,aAAc,EACd,aAAc,EACd,cACA,OAAQ,EAAY,MACpB,kBAAmB,EACnB,UACD,CAAC,EASN,CAAC,EAAe,EAAI,EAAQ,EAAQ,EAAwB,EAAgB,CAC7E,CAID,OAAO,MAEH,OAAO,QACJ,EAAgB,IACf,EAAe,EAAQ,EAAQ,CACjC,CAAE,IAAK,EAAiB,CACzB,CACH,CAAC,EAAgB,EAAgB,CAClC,CAGH,SAAS,EAAmB,EAA6C,CACvE,IAAM,EAAS,GAAW,CACpB,EAAgB,GAAkB,CAClC,EAAkB,GAAoB,CACtC,EAAK,GAAO,CACZ,EAA0B,GAAiC,CAEjE,OAAO,EACJ,GAAmB,CAClB,IAAM,EAAU,EAAM,EAAQ,EAAO,CAC/B,EAAe,EAAwB,CAC3C,OAAQ,EACR,GAAI,EACL,CAAC,CACF,GAAI,IAAiB,IAAA,GACnB,MAAU,MAAM,oBAAoB,EAAQ,kBAAkB,CAGhE,IAAI,EAMJ,OALI,IAEF,EAAe,EAAwB,CADhB,SAAQ,GAAI,EACgB,CAAC,EAG/C,EAAuB,CAC5B,eACA,eACA,WAAY,EAAa,IACvB,EAAG,EAAY,MAAO,CACpB,GAAG,EACH,QAAS,EAAkB,EAAS,EACrC,CAAC,CACL,CAAC,EAEJ,CACE,EACA,EACA,EACA,EACA,EACA,EACD,CACF,CAKH,SAAS,EAAM,EAA4B,EAAwB,CACjE,OAAO,EAAS,GAAG,EAAO,GAAG,IAAW"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./compat/CompatStore.cjs`),t=require(`./compat/DictionaryProvider.cjs`),n=require(`./compat/useTranslations.cjs`);exports.CompatStore=e.CompatStore,exports.DictionaryProvider=t.DictionaryProvider,exports.useTranslations=n.useTranslations;
@@ -0,0 +1 @@
1
+ export * from './compat.js';
@@ -0,0 +1,4 @@
1
+ import { CompatStore } from "./compat/CompatStore.js";
2
+ import { DictionaryProvider, DictionaryProviderProps } from "./compat/DictionaryProvider.js";
3
+ import { useTranslations } from "./compat/useTranslations.js";
4
+ export { CompatStore, DictionaryProvider, type DictionaryProviderProps, useTranslations };
@@ -0,0 +1 @@
1
+ import{CompatStore as e}from"./compat/CompatStore.mjs";import{DictionaryProvider as t}from"./compat/DictionaryProvider.mjs";import{useTranslations as n}from"./compat/useTranslations.mjs";export{e as CompatStore,t as DictionaryProvider,n as useTranslations};
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/_rolldown/runtime.cjs`);let t=require(`react/jsx-runtime`),n=require(`react`);n=e.__toESM(n);function r(e){return e?e.charAt(0).toUpperCase()+(e.length>1?e.slice(1):``):``}function i(e){if(!e)return;let t={};for(let n in e)t[n]={name:e[n]};return t}function a({locale:e,locales:n,customNames:a,customMapping:o=i(a),setLocale:s,getLocaleProperties:c,...l}){let u=e=>{if(o&&o[e]){if(typeof o[e]==`string`)return o[e];if(o[e].name)return o[e].name}return r(c(e).nativeNameWithRegionCode)};return!n||n.length===0||!s?null:(0,t.jsxs)(`select`,{name:`generaltranslation-locale`,"aria-label":`General Translation locale selector`,...l,value:e||``,onChange:e=>s(e.target.value),children:[!e&&(0,t.jsx)(`option`,{value:``}),n.map(e=>(0,t.jsx)(`option`,{value:e,suppressHydrationWarning:!0,children:u(e)},e))]})}exports.InternalLocaleSelector=a;
1
+ const e=require(`../../_virtual/_rolldown/runtime.cjs`);let t=require(`react/jsx-runtime`),n=require(`react`);n=e.__toESM(n);function r(e){return e?e.charAt(0).toUpperCase()+(e.length>1?e.slice(1):``):``}function i({locale:e,locales:n,customMapping:i,setLocale:a,getLocaleProperties:o,...s}){let c=e=>{if(i&&i[e]){if(typeof i[e]==`string`)return i[e];if(i[e].name)return i[e].name}return r(o(e).nativeNameWithRegionCode)};return!n||n.length===0||!a?null:(0,t.jsxs)(`select`,{name:`generaltranslation-locale`,"aria-label":`General Translation locale selector`,...s,value:e||``,onChange:e=>a(e.target.value),children:[!e&&(0,t.jsx)(`option`,{value:``}),n.map(e=>(0,t.jsx)(`option`,{value:e,suppressHydrationWarning:!0,children:c(e)},e))]})}exports.InternalLocaleSelector=i;
2
2
  //# sourceMappingURL=InternalLocaleSelector.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"InternalLocaleSelector.cjs","names":[],"sources":["../../../src/components/helpers/InternalLocaleSelector.tsx"],"sourcesContent":["import React from 'react';\nimport { CustomMapping, LocaleProperties } from 'generaltranslation/types';\n\n/**\n * Capitalizes the first letter of a string if applicable.\n * For strings that do not use capitalization, it returns the string unchanged.\n * @param {string} str - The string to capitalize.\n * @returns {string} The string with the first letter capitalized if applicable.\n */\nfunction capitalizeName(str: string): string {\n if (!str) return '';\n return str.charAt(0).toUpperCase() + (str.length > 1 ? str.slice(1) : '');\n}\n\n/**\n * Internal helper to convert deprecated customNames prop to the new customMapping format.\n * Used for backward compatibility with previous LocaleSelector API.\n * @param {object} customNames - Mapping of locale to display name.\n * @returns {CustomMapping | undefined} The converted mapping or undefined.\n * @internal\n */\nfunction _convertCustomNamesToMapping(\n customNames?: { [key: string]: string } | undefined\n): CustomMapping | undefined {\n if (!customNames) return undefined;\n const result: CustomMapping = {};\n for (const locale in customNames) {\n result[locale] = { name: customNames[locale] };\n }\n return result;\n}\n\n/**\n * A dropdown component that allows users to select a locale.\n * @param {string} locale - The currently selected locale.\n * @param {string[]} locales - The list of all available locales.\n * @param {function} setLocale - Function to update the current locale.\n * @param {function} getLocaleProperties - Function to retrieve properties for a given locale.\n * @param {object} [customNames] - (deprecated) An optional object to map locales to custom names. Use `customMapping` instead.\n * @param {CustomMapping} [customMapping] - An optional object to map locales to custom display names, emojis, or other properties.\n * @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.\n *\n * @internal\n */\nexport function InternalLocaleSelector({\n locale,\n locales,\n customNames,\n customMapping = _convertCustomNamesToMapping(customNames),\n setLocale,\n getLocaleProperties,\n ...props\n}: {\n locale: string;\n locales: string[];\n customNames?: { [key: string]: string };\n customMapping?: CustomMapping;\n setLocale: (locale: string) => void;\n getLocaleProperties: (locale: string) => LocaleProperties;\n [key: string]: any;\n}): React.JSX.Element | null {\n // Get display name\n const getDisplayName = (locale: string) => {\n if (customMapping && customMapping[locale]) {\n if (typeof customMapping[locale] === 'string')\n return customMapping[locale];\n if (customMapping[locale].name) return customMapping[locale].name;\n }\n return capitalizeName(getLocaleProperties(locale).nativeNameWithRegionCode);\n };\n\n // If no locales are returned, just render nothing or handle gracefully\n if (!locales || locales.length === 0 || !setLocale) {\n return null;\n }\n\n return (\n <select\n name='generaltranslation-locale'\n aria-label='General Translation locale selector'\n {...props}\n // Fallback to an empty string if currentLocale is undefined\n value={locale || ''}\n onChange={(e) => setLocale(e.target.value)}\n >\n {/* Optional fallback for when no locale is set */}\n {!locale && <option value='' />}\n\n {locales.map((locale) => (\n <option key={locale} value={locale} suppressHydrationWarning>\n {getDisplayName(locale)}\n </option>\n ))}\n </select>\n );\n}\n"],"mappings":"6HASA,SAAS,EAAe,EAAqB,CAE3C,OADK,EACE,EAAI,OAAO,EAAE,CAAC,aAAa,EAAI,EAAI,OAAS,EAAI,EAAI,MAAM,EAAE,CAAG,IADrD,GAWnB,SAAS,EACP,EAC2B,CAC3B,GAAI,CAAC,EAAa,OAClB,IAAM,EAAwB,EAAE,CAChC,IAAK,IAAM,KAAU,EACnB,EAAO,GAAU,CAAE,KAAM,EAAY,GAAS,CAEhD,OAAO,EAeT,SAAgB,EAAuB,CACrC,SACA,UACA,cACA,gBAAgB,EAA6B,EAAY,CACzD,YACA,sBACA,GAAG,GASwB,CAE3B,IAAM,EAAkB,GAAmB,CACzC,GAAI,GAAiB,EAAc,GAAS,CAC1C,GAAI,OAAO,EAAc,IAAY,SACnC,OAAO,EAAc,GACvB,GAAI,EAAc,GAAQ,KAAM,OAAO,EAAc,GAAQ,KAE/D,OAAO,EAAe,EAAoB,EAAO,CAAC,yBAAyB,EAQ7E,MAJI,CAAC,GAAW,EAAQ,SAAW,GAAK,CAAC,EAChC,MAIP,EAAA,EAAA,MAAC,SAAD,CACE,KAAK,4BACL,aAAW,sCACX,GAAI,EAEJ,MAAO,GAAU,GACjB,SAAW,GAAM,EAAU,EAAE,OAAO,MAAM,UAN5C,CASG,CAAC,IAAU,EAAA,EAAA,KAAC,SAAD,CAAQ,MAAM,GAAK,CAAA,CAE9B,EAAQ,IAAK,IACZ,EAAA,EAAA,KAAC,SAAD,CAAqB,MAAO,EAAQ,yBAAA,YACjC,EAAe,EAAO,CAChB,CAFI,EAEJ,CACT,CACK"}
1
+ {"version":3,"file":"InternalLocaleSelector.cjs","names":[],"sources":["../../../src/components/helpers/InternalLocaleSelector.tsx"],"sourcesContent":["import React from 'react';\nimport type {\n CustomMapping,\n LocaleProperties,\n} from '@generaltranslation/format';\n\n/**\n * Capitalizes the first letter of a string if applicable.\n * For strings that do not use capitalization, it returns the string unchanged.\n * @param {string} str - The string to capitalize.\n * @returns {string} The string with the first letter capitalized if applicable.\n */\nfunction capitalizeName(str: string): string {\n if (!str) return '';\n return str.charAt(0).toUpperCase() + (str.length > 1 ? str.slice(1) : '');\n}\n\n/**\n * A dropdown component that allows users to select a locale.\n * @param {string} locale - The currently selected locale.\n * @param {string[]} locales - The list of all available locales.\n * @param {function} setLocale - Function to update the current locale.\n * @param {function} getLocaleProperties - Function to retrieve properties for a given locale.\n * @param {CustomMapping} [customMapping] - An optional object to map locales to custom display names, emojis, or other properties.\n * @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.\n *\n * @internal\n */\nexport function InternalLocaleSelector({\n locale,\n locales,\n customMapping,\n setLocale,\n getLocaleProperties,\n ...props\n}: {\n locale: string;\n locales: string[];\n customMapping?: CustomMapping;\n setLocale: (locale: string) => void;\n getLocaleProperties: (locale: string) => LocaleProperties;\n [key: string]: any;\n}): React.JSX.Element | null {\n // Get display name\n const getDisplayName = (locale: string) => {\n if (customMapping && customMapping[locale]) {\n if (typeof customMapping[locale] === 'string')\n return customMapping[locale];\n if (customMapping[locale].name) return customMapping[locale].name;\n }\n return capitalizeName(getLocaleProperties(locale).nativeNameWithRegionCode);\n };\n\n // If no locales are returned, just render nothing or handle gracefully\n if (!locales || locales.length === 0 || !setLocale) {\n return null;\n }\n\n return (\n <select\n name='generaltranslation-locale'\n aria-label='General Translation locale selector'\n {...props}\n // Fallback to an empty string if currentLocale is undefined\n value={locale || ''}\n onChange={(e) => setLocale(e.target.value)}\n >\n {/* Optional fallback for when no locale is set */}\n {!locale && <option value='' />}\n\n {locales.map((locale) => (\n <option key={locale} value={locale} suppressHydrationWarning>\n {getDisplayName(locale)}\n </option>\n ))}\n </select>\n );\n}\n"],"mappings":"6HAYA,SAAS,EAAe,EAAqB,CAE3C,OADK,EACE,EAAI,OAAO,EAAE,CAAC,aAAa,EAAI,EAAI,OAAS,EAAI,EAAI,MAAM,EAAE,CAAG,IADrD,GAenB,SAAgB,EAAuB,CACrC,SACA,UACA,gBACA,YACA,sBACA,GAAG,GAQwB,CAE3B,IAAM,EAAkB,GAAmB,CACzC,GAAI,GAAiB,EAAc,GAAS,CAC1C,GAAI,OAAO,EAAc,IAAY,SACnC,OAAO,EAAc,GACvB,GAAI,EAAc,GAAQ,KAAM,OAAO,EAAc,GAAQ,KAE/D,OAAO,EAAe,EAAoB,EAAO,CAAC,yBAAyB,EAQ7E,MAJI,CAAC,GAAW,EAAQ,SAAW,GAAK,CAAC,EAChC,MAIP,EAAA,EAAA,MAAC,SAAD,CACE,KAAK,4BACL,aAAW,sCACX,GAAI,EAEJ,MAAO,GAAU,GACjB,SAAW,GAAM,EAAU,EAAE,OAAO,MAAM,UAN5C,CASG,CAAC,IAAU,EAAA,EAAA,KAAC,SAAD,CAAQ,MAAM,GAAK,CAAA,CAE9B,EAAQ,IAAK,IACZ,EAAA,EAAA,KAAC,SAAD,CAAqB,MAAO,EAAQ,yBAAA,YACjC,EAAe,EAAO,CAChB,CAFI,EAEJ,CACT,CACK"}