@lingo.dev/compiler 0.1.0

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 (300) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +192 -0
  3. package/build/_virtual/rolldown_runtime.cjs +29 -0
  4. package/build/_virtual/rolldown_runtime.mjs +7 -0
  5. package/build/index.cjs +0 -0
  6. package/build/index.d.cts +2 -0
  7. package/build/index.d.mts +2 -0
  8. package/build/index.mjs +1 -0
  9. package/build/metadata/manager.cjs +131 -0
  10. package/build/metadata/manager.mjs +123 -0
  11. package/build/metadata/manager.mjs.map +1 -0
  12. package/build/plugin/build-translator.cjs +198 -0
  13. package/build/plugin/build-translator.mjs +196 -0
  14. package/build/plugin/build-translator.mjs.map +1 -0
  15. package/build/plugin/cleanup.cjs +20 -0
  16. package/build/plugin/cleanup.mjs +20 -0
  17. package/build/plugin/cleanup.mjs.map +1 -0
  18. package/build/plugin/next-compiler-loader.cjs +41 -0
  19. package/build/plugin/next-compiler-loader.d.cts +12 -0
  20. package/build/plugin/next-compiler-loader.d.cts.map +1 -0
  21. package/build/plugin/next-compiler-loader.d.mts +13 -0
  22. package/build/plugin/next-compiler-loader.d.mts.map +1 -0
  23. package/build/plugin/next-compiler-loader.mjs +42 -0
  24. package/build/plugin/next-compiler-loader.mjs.map +1 -0
  25. package/build/plugin/next-config-loader.cjs +13 -0
  26. package/build/plugin/next-config-loader.d.cts +8 -0
  27. package/build/plugin/next-config-loader.d.cts.map +1 -0
  28. package/build/plugin/next-config-loader.d.mts +9 -0
  29. package/build/plugin/next-config-loader.d.mts.map +1 -0
  30. package/build/plugin/next-config-loader.mjs +14 -0
  31. package/build/plugin/next-config-loader.mjs.map +1 -0
  32. package/build/plugin/next-locale-client-loader.cjs +9 -0
  33. package/build/plugin/next-locale-client-loader.d.cts +8 -0
  34. package/build/plugin/next-locale-client-loader.d.cts.map +1 -0
  35. package/build/plugin/next-locale-client-loader.d.mts +9 -0
  36. package/build/plugin/next-locale-client-loader.d.mts.map +1 -0
  37. package/build/plugin/next-locale-client-loader.mjs +10 -0
  38. package/build/plugin/next-locale-client-loader.mjs.map +1 -0
  39. package/build/plugin/next-locale-server-loader.cjs +9 -0
  40. package/build/plugin/next-locale-server-loader.d.cts +8 -0
  41. package/build/plugin/next-locale-server-loader.d.cts.map +1 -0
  42. package/build/plugin/next-locale-server-loader.d.mts +9 -0
  43. package/build/plugin/next-locale-server-loader.d.mts.map +1 -0
  44. package/build/plugin/next-locale-server-loader.mjs +10 -0
  45. package/build/plugin/next-locale-server-loader.mjs.map +1 -0
  46. package/build/plugin/next.cjs +220 -0
  47. package/build/plugin/next.d.cts +9 -0
  48. package/build/plugin/next.d.cts.map +1 -0
  49. package/build/plugin/next.d.mts +9 -0
  50. package/build/plugin/next.d.mts.map +1 -0
  51. package/build/plugin/next.mjs +222 -0
  52. package/build/plugin/next.mjs.map +1 -0
  53. package/build/plugin/transform/babel-compat.cjs +13 -0
  54. package/build/plugin/transform/babel-compat.mjs +10 -0
  55. package/build/plugin/transform/babel-compat.mjs.map +1 -0
  56. package/build/plugin/transform/index.cjs +44 -0
  57. package/build/plugin/transform/index.mjs +42 -0
  58. package/build/plugin/transform/index.mjs.map +1 -0
  59. package/build/plugin/transform/metadata.cjs +142 -0
  60. package/build/plugin/transform/metadata.mjs +141 -0
  61. package/build/plugin/transform/metadata.mjs.map +1 -0
  62. package/build/plugin/transform/parse-override.cjs +145 -0
  63. package/build/plugin/transform/parse-override.mjs +144 -0
  64. package/build/plugin/transform/parse-override.mjs.map +1 -0
  65. package/build/plugin/transform/process-file.cjs +391 -0
  66. package/build/plugin/transform/process-file.mjs +390 -0
  67. package/build/plugin/transform/process-file.mjs.map +1 -0
  68. package/build/plugin/transform/use-i18n.cjs +8 -0
  69. package/build/plugin/transform/use-i18n.mjs +7 -0
  70. package/build/plugin/transform/use-i18n.mjs.map +1 -0
  71. package/build/plugin/transform/utils.cjs +205 -0
  72. package/build/plugin/transform/utils.mjs +192 -0
  73. package/build/plugin/transform/utils.mjs.map +1 -0
  74. package/build/plugin/unplugin.cjs +188 -0
  75. package/build/plugin/unplugin.d.cts +8 -0
  76. package/build/plugin/unplugin.d.cts.map +1 -0
  77. package/build/plugin/unplugin.d.mts +8 -0
  78. package/build/plugin/unplugin.d.mts.map +1 -0
  79. package/build/plugin/unplugin.mjs +186 -0
  80. package/build/plugin/unplugin.mjs.map +1 -0
  81. package/build/plugin/vite.cjs +28 -0
  82. package/build/plugin/vite.d.cts +9 -0
  83. package/build/plugin/vite.d.cts.map +1 -0
  84. package/build/plugin/vite.d.mts +9 -0
  85. package/build/plugin/vite.d.mts.map +1 -0
  86. package/build/plugin/vite.mjs +29 -0
  87. package/build/plugin/vite.mjs.map +1 -0
  88. package/build/plugin/webpack.cjs +27 -0
  89. package/build/plugin/webpack.d.cts +8 -0
  90. package/build/plugin/webpack.d.cts.map +1 -0
  91. package/build/plugin/webpack.d.mts +8 -0
  92. package/build/plugin/webpack.d.mts.map +1 -0
  93. package/build/plugin/webpack.mjs +28 -0
  94. package/build/plugin/webpack.mjs.map +1 -0
  95. package/build/react/client/index.cjs +9 -0
  96. package/build/react/client/index.d.cts +5 -0
  97. package/build/react/client/index.d.mts +5 -0
  98. package/build/react/client/index.mjs +6 -0
  99. package/build/react/client/useTranslation.cjs +71 -0
  100. package/build/react/client/useTranslation.d.cts +42 -0
  101. package/build/react/client/useTranslation.d.cts.map +1 -0
  102. package/build/react/client/useTranslation.d.mts +42 -0
  103. package/build/react/client/useTranslation.d.mts.map +1 -0
  104. package/build/react/client/useTranslation.mjs +71 -0
  105. package/build/react/client/useTranslation.mjs.map +1 -0
  106. package/build/react/next/client.cjs +25 -0
  107. package/build/react/next/client.d.cts +9 -0
  108. package/build/react/next/client.d.cts.map +1 -0
  109. package/build/react/next/client.d.mts +9 -0
  110. package/build/react/next/client.d.mts.map +1 -0
  111. package/build/react/next/client.mjs +24 -0
  112. package/build/react/next/client.mjs.map +1 -0
  113. package/build/react/next/cookie-locale-resolver.cjs +29 -0
  114. package/build/react/next/cookie-locale-resolver.d.cts +33 -0
  115. package/build/react/next/cookie-locale-resolver.d.cts.map +1 -0
  116. package/build/react/next/cookie-locale-resolver.d.mts +33 -0
  117. package/build/react/next/cookie-locale-resolver.d.mts.map +1 -0
  118. package/build/react/next/cookie-locale-resolver.mjs +29 -0
  119. package/build/react/next/cookie-locale-resolver.mjs.map +1 -0
  120. package/build/react/next/server.cjs +21 -0
  121. package/build/react/next/server.d.cts +13 -0
  122. package/build/react/next/server.d.cts.map +1 -0
  123. package/build/react/next/server.d.mts +14 -0
  124. package/build/react/next/server.d.mts.map +1 -0
  125. package/build/react/next/server.mjs +20 -0
  126. package/build/react/next/server.mjs.map +1 -0
  127. package/build/react/server/ServerLingoProvider.cjs +19 -0
  128. package/build/react/server/ServerLingoProvider.d.cts +12 -0
  129. package/build/react/server/ServerLingoProvider.d.cts.map +1 -0
  130. package/build/react/server/ServerLingoProvider.d.mts +12 -0
  131. package/build/react/server/ServerLingoProvider.d.mts.map +1 -0
  132. package/build/react/server/ServerLingoProvider.mjs +19 -0
  133. package/build/react/server/ServerLingoProvider.mjs.map +1 -0
  134. package/build/react/server/index.cjs +7 -0
  135. package/build/react/server/index.d.cts +4 -0
  136. package/build/react/server/index.d.mts +4 -0
  137. package/build/react/server/index.mjs +5 -0
  138. package/build/react/server/useTranslation.cjs +60 -0
  139. package/build/react/server/useTranslation.d.cts +36 -0
  140. package/build/react/server/useTranslation.d.cts.map +1 -0
  141. package/build/react/server/useTranslation.d.mts +36 -0
  142. package/build/react/server/useTranslation.d.mts.map +1 -0
  143. package/build/react/server/useTranslation.mjs +60 -0
  144. package/build/react/server/useTranslation.mjs.map +1 -0
  145. package/build/react/server-only/index.cjs +42 -0
  146. package/build/react/server-only/index.d.cts +38 -0
  147. package/build/react/server-only/index.d.cts.map +1 -0
  148. package/build/react/server-only/index.d.mts +38 -0
  149. package/build/react/server-only/index.d.mts.map +1 -0
  150. package/build/react/server-only/index.mjs +42 -0
  151. package/build/react/server-only/index.mjs.map +1 -0
  152. package/build/react/server-only/translations.cjs +85 -0
  153. package/build/react/server-only/translations.mjs +85 -0
  154. package/build/react/server-only/translations.mjs.map +1 -0
  155. package/build/react/shared/LingoContext.cjs +14 -0
  156. package/build/react/shared/LingoContext.d.cts +41 -0
  157. package/build/react/shared/LingoContext.d.cts.map +1 -0
  158. package/build/react/shared/LingoContext.d.mts +41 -0
  159. package/build/react/shared/LingoContext.d.mts.map +1 -0
  160. package/build/react/shared/LingoContext.mjs +13 -0
  161. package/build/react/shared/LingoContext.mjs.map +1 -0
  162. package/build/react/shared/LingoProvider.cjs +274 -0
  163. package/build/react/shared/LingoProvider.d.cts +76 -0
  164. package/build/react/shared/LingoProvider.d.cts.map +1 -0
  165. package/build/react/shared/LingoProvider.d.mts +76 -0
  166. package/build/react/shared/LingoProvider.d.mts.map +1 -0
  167. package/build/react/shared/LingoProvider.mjs +274 -0
  168. package/build/react/shared/LingoProvider.mjs.map +1 -0
  169. package/build/react/shared/LocaleSwitcher.cjs +61 -0
  170. package/build/react/shared/LocaleSwitcher.d.cts +71 -0
  171. package/build/react/shared/LocaleSwitcher.d.cts.map +1 -0
  172. package/build/react/shared/LocaleSwitcher.d.mts +71 -0
  173. package/build/react/shared/LocaleSwitcher.d.mts.map +1 -0
  174. package/build/react/shared/LocaleSwitcher.mjs +61 -0
  175. package/build/react/shared/LocaleSwitcher.mjs.map +1 -0
  176. package/build/react/shared/render-rich-text.cjs +55 -0
  177. package/build/react/shared/render-rich-text.d.cts +17 -0
  178. package/build/react/shared/render-rich-text.d.cts.map +1 -0
  179. package/build/react/shared/render-rich-text.d.mts +17 -0
  180. package/build/react/shared/render-rich-text.d.mts.map +1 -0
  181. package/build/react/shared/render-rich-text.mjs +54 -0
  182. package/build/react/shared/render-rich-text.mjs.map +1 -0
  183. package/build/react/shared/utils.cjs +34 -0
  184. package/build/react/shared/utils.mjs +35 -0
  185. package/build/react/shared/utils.mjs.map +1 -0
  186. package/build/react/types.d.cts +16 -0
  187. package/build/react/types.d.cts.map +1 -0
  188. package/build/react/types.d.mts +16 -0
  189. package/build/react/types.d.mts.map +1 -0
  190. package/build/translation-server/logger.cjs +37 -0
  191. package/build/translation-server/logger.mjs +37 -0
  192. package/build/translation-server/logger.mjs.map +1 -0
  193. package/build/translation-server/translation-server.cjs +547 -0
  194. package/build/translation-server/translation-server.mjs +544 -0
  195. package/build/translation-server/translation-server.mjs.map +1 -0
  196. package/build/translation-server/ws-events.cjs +15 -0
  197. package/build/translation-server/ws-events.mjs +15 -0
  198. package/build/translation-server/ws-events.mjs.map +1 -0
  199. package/build/translators/api.cjs +12 -0
  200. package/build/translators/api.mjs +12 -0
  201. package/build/translators/api.mjs.map +1 -0
  202. package/build/translators/cache-factory.cjs +26 -0
  203. package/build/translators/cache-factory.mjs +27 -0
  204. package/build/translators/cache-factory.mjs.map +1 -0
  205. package/build/translators/lingo/model-factory.cjs +179 -0
  206. package/build/translators/lingo/model-factory.mjs +174 -0
  207. package/build/translators/lingo/model-factory.mjs.map +1 -0
  208. package/build/translators/lingo/prompt.cjs +43 -0
  209. package/build/translators/lingo/prompt.mjs +43 -0
  210. package/build/translators/lingo/prompt.mjs.map +1 -0
  211. package/build/translators/lingo/service.cjs +152 -0
  212. package/build/translators/lingo/service.mjs +152 -0
  213. package/build/translators/lingo/service.mjs.map +1 -0
  214. package/build/translators/lingo/shots.cjs +28 -0
  215. package/build/translators/lingo/shots.mjs +28 -0
  216. package/build/translators/lingo/shots.mjs.map +1 -0
  217. package/build/translators/local-cache.cjs +115 -0
  218. package/build/translators/local-cache.mjs +113 -0
  219. package/build/translators/local-cache.mjs.map +1 -0
  220. package/build/translators/parse-xml.cjs +109 -0
  221. package/build/translators/parse-xml.mjs +108 -0
  222. package/build/translators/parse-xml.mjs.map +1 -0
  223. package/build/translators/pluralization/icu-validator.cjs +36 -0
  224. package/build/translators/pluralization/icu-validator.mjs +36 -0
  225. package/build/translators/pluralization/icu-validator.mjs.map +1 -0
  226. package/build/translators/pluralization/pattern-detector.cjs +25 -0
  227. package/build/translators/pluralization/pattern-detector.mjs +25 -0
  228. package/build/translators/pluralization/pattern-detector.mjs.map +1 -0
  229. package/build/translators/pluralization/prompt.cjs +98 -0
  230. package/build/translators/pluralization/prompt.mjs +98 -0
  231. package/build/translators/pluralization/prompt.mjs.map +1 -0
  232. package/build/translators/pluralization/service.cjs +247 -0
  233. package/build/translators/pluralization/service.mjs +247 -0
  234. package/build/translators/pluralization/service.mjs.map +1 -0
  235. package/build/translators/pluralization/shots.cjs +53 -0
  236. package/build/translators/pluralization/shots.mjs +53 -0
  237. package/build/translators/pluralization/shots.mjs.map +1 -0
  238. package/build/translators/pluralization/types.d.cts +17 -0
  239. package/build/translators/pluralization/types.d.cts.map +1 -0
  240. package/build/translators/pluralization/types.d.mts +17 -0
  241. package/build/translators/pluralization/types.d.mts.map +1 -0
  242. package/build/translators/pseudotranslator/index.cjs +129 -0
  243. package/build/translators/pseudotranslator/index.mjs +129 -0
  244. package/build/translators/pseudotranslator/index.mjs.map +1 -0
  245. package/build/translators/translation-service.cjs +182 -0
  246. package/build/translators/translation-service.mjs +183 -0
  247. package/build/translators/translation-service.mjs.map +1 -0
  248. package/build/translators/translator-factory.cjs +49 -0
  249. package/build/translators/translator-factory.mjs +50 -0
  250. package/build/translators/translator-factory.mjs.map +1 -0
  251. package/build/types.d.cts +161 -0
  252. package/build/types.d.cts.map +1 -0
  253. package/build/types.d.mts +161 -0
  254. package/build/types.d.mts.map +1 -0
  255. package/build/utils/config-factory.cjs +58 -0
  256. package/build/utils/config-factory.mjs +58 -0
  257. package/build/utils/config-factory.mjs.map +1 -0
  258. package/build/utils/hash.cjs +17 -0
  259. package/build/utils/hash.mjs +16 -0
  260. package/build/utils/hash.mjs.map +1 -0
  261. package/build/utils/is-valid-locale.cjs +14 -0
  262. package/build/utils/is-valid-locale.mjs +14 -0
  263. package/build/utils/is-valid-locale.mjs.map +1 -0
  264. package/build/utils/logger.cjs +51 -0
  265. package/build/utils/logger.mjs +50 -0
  266. package/build/utils/logger.mjs.map +1 -0
  267. package/build/utils/path-helpers.cjs +49 -0
  268. package/build/utils/path-helpers.mjs +47 -0
  269. package/build/utils/path-helpers.mjs.map +1 -0
  270. package/build/utils/timeout.cjs +42 -0
  271. package/build/utils/timeout.mjs +41 -0
  272. package/build/utils/timeout.mjs.map +1 -0
  273. package/build/virtual/code-generator.cjs +54 -0
  274. package/build/virtual/code-generator.mjs +53 -0
  275. package/build/virtual/code-generator.mjs.map +1 -0
  276. package/build/virtual/config.cjs +10 -0
  277. package/build/virtual/config.d.cts +9 -0
  278. package/build/virtual/config.d.cts.map +1 -0
  279. package/build/virtual/config.d.mts +9 -0
  280. package/build/virtual/config.d.mts.map +1 -0
  281. package/build/virtual/config.mjs +8 -0
  282. package/build/virtual/config.mjs.map +1 -0
  283. package/build/virtual/locale/client.cjs +23 -0
  284. package/build/virtual/locale/client.d.cts +19 -0
  285. package/build/virtual/locale/client.d.cts.map +1 -0
  286. package/build/virtual/locale/client.d.mts +19 -0
  287. package/build/virtual/locale/client.d.mts.map +1 -0
  288. package/build/virtual/locale/client.mjs +22 -0
  289. package/build/virtual/locale/client.mjs.map +1 -0
  290. package/build/virtual/locale/server.cjs +13 -0
  291. package/build/virtual/locale/server.d.cts +13 -0
  292. package/build/virtual/locale/server.d.cts.map +1 -0
  293. package/build/virtual/locale/server.d.mts +13 -0
  294. package/build/virtual/locale/server.d.mts.map +1 -0
  295. package/build/virtual/locale/server.mjs +13 -0
  296. package/build/virtual/locale/server.mjs.map +1 -0
  297. package/build/widget/lingo-dev-widget.cjs +228 -0
  298. package/build/widget/lingo-dev-widget.mjs +229 -0
  299. package/build/widget/lingo-dev-widget.mjs.map +1 -0
  300. package/package.json +189 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslation.mjs","names":["useTranslation: TranslationHook"],"sources":["../../../src/react/client/useTranslation.ts"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect } from \"react\";\nimport { logger } from \"../../utils/logger\";\nimport {\n renderRichText,\n type RichTextParams,\n} from \"../shared/render-rich-text\";\nimport type { TranslationHook } from \"../types\";\nimport { useLingoContext } from \"../shared/LingoContext\";\n\n/**\n * useTranslation Hook\n *\n * Returns a translation function `t(hash, source, params?)` that:\n * - Returns original text for source locale\n * - Returns translated text for target locales\n * - Supports rich text with variable and component placeholders\n * - Automatically requests missing translations\n * - Falls back to source text while loading\n *\n * This hook is automatically injected by the Babel plugin.\n * You typically don't need to call it manually.\n *\n * @param hashes - Static list of all translation hashes used in this component (injected at build time)\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * export function Welcome() {\n * const t = useTranslation(['hash_abc123', 'hash_def456']);\n *\n * return (\n * <div>\n * <h1>{t('hash_abc123', 'Welcome')}</h1>\n * <p>{t('hash_def456', 'Hello {name}', { name: 'Alice' })}</p>\n * <p>{t('hash_def789', 'Click <a0>here</a0>', {\n * a0: (chunks) => <a href=\"/home\">{chunks}</a>\n * })}</p>\n * </div>\n * );\n * }\n * ```\n */\nexport const useTranslation: TranslationHook = (hashes: string[]) => {\n const { translations, registerHashes, locale, sourceLocale } =\n useLingoContext();\n\n useEffect(() => {\n logger.debug(`Registering ${hashes.length} hashes for component`);\n\n registerHashes(hashes);\n }, [hashes, registerHashes, locale, sourceLocale]);\n\n return {\n t: useCallback(\n (hash: string, source: string, params?: RichTextParams): ReactNode => {\n logger.debug(\n `Client. The translations for locale ${locale} are: ${JSON.stringify(translations)}`,\n );\n const text = translations[hash] || source;\n\n if (!params) {\n return text;\n }\n\n return renderRichText(text, params, locale);\n },\n [translations, locale, sourceLocale],\n ),\n locale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAaA,kBAAmC,WAAqB;CACnE,MAAM,EAAE,cAAc,gBAAgB,QAAQ,iBAC5C,iBAAiB;AAEnB,iBAAgB;AACd,SAAO,MAAM,eAAe,OAAO,OAAO,uBAAuB;AAEjE,iBAAe,OAAO;IACrB;EAAC;EAAQ;EAAgB;EAAQ;EAAa,CAAC;AAElD,QAAO;EACL,GAAG,aACA,MAAc,QAAgB,WAAuC;AACpE,UAAO,MACL,uCAAuC,OAAO,QAAQ,KAAK,UAAU,aAAa,GACnF;GACD,MAAM,OAAO,aAAa,SAAS;AAEnC,OAAI,CAAC,OACH,QAAO;AAGT,UAAO,eAAe,MAAM,QAAQ,OAAO;KAE7C;GAAC;GAAc;GAAQ;GAAa,CACrC;EACD;EACD"}
@@ -0,0 +1,25 @@
1
+ "use client";
2
+
3
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
4
+ const require_logger = require('../../utils/logger.cjs');
5
+ const require_LingoProvider = require('../shared/LingoProvider.cjs');
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ let next_navigation = require("next/navigation");
8
+
9
+ //#region src/react/next/client.tsx
10
+ const createNextCookieLocaleResolver = () => {
11
+ return (locale) => {
12
+ require_logger.logger.warn("Is not supposed to run on client");
13
+ return locale;
14
+ };
15
+ };
16
+ const LingoProvider = (props) => {
17
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_LingoProvider.LingoProvider, {
18
+ ...props,
19
+ router: (0, next_navigation.useRouter)()
20
+ });
21
+ };
22
+
23
+ //#endregion
24
+ exports.LingoProvider = LingoProvider;
25
+ exports.createNextCookieLocaleResolver = createNextCookieLocaleResolver;
@@ -0,0 +1,9 @@
1
+ import { LingoProviderProps } from "../shared/LingoProvider.cjs";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
+
4
+ //#region src/react/next/client.d.ts
5
+ declare const createNextCookieLocaleResolver: () => (locale: string) => string;
6
+ declare const LingoProvider: (props: LingoProviderProps) => react_jsx_runtime0.JSX.Element;
7
+ //#endregion
8
+ export { LingoProvider, type LingoProviderProps, createNextCookieLocaleResolver };
9
+ //# sourceMappingURL=client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../../../src/react/next/client.tsx"],"sourcesContent":[],"mappings":";;;;cAUa;cAOA,uBAAwB,uBAAkB,kBAAA,CAAA,GAAA,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { LingoProviderProps } from "../shared/LingoProvider.mjs";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
+
4
+ //#region src/react/next/client.d.ts
5
+ declare const createNextCookieLocaleResolver: () => (locale: string) => string;
6
+ declare const LingoProvider: (props: LingoProviderProps) => react_jsx_runtime0.JSX.Element;
7
+ //#endregion
8
+ export { LingoProvider, type LingoProviderProps, createNextCookieLocaleResolver };
9
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.mts","names":[],"sources":["../../../src/react/next/client.tsx"],"sourcesContent":[],"mappings":";;;;cAUa;cAOA,uBAAwB,uBAAkB,kBAAA,CAAA,GAAA,CAAA"}
@@ -0,0 +1,24 @@
1
+ "use client";
2
+
3
+ import { logger } from "../../utils/logger.mjs";
4
+ import { LingoProvider as LingoProvider$1 } from "../shared/LingoProvider.mjs";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { useRouter } from "next/navigation";
7
+
8
+ //#region src/react/next/client.tsx
9
+ const createNextCookieLocaleResolver = () => {
10
+ return (locale) => {
11
+ logger.warn("Is not supposed to run on client");
12
+ return locale;
13
+ };
14
+ };
15
+ const LingoProvider = (props) => {
16
+ return /* @__PURE__ */ jsx(LingoProvider$1, {
17
+ ...props,
18
+ router: useRouter()
19
+ });
20
+ };
21
+
22
+ //#endregion
23
+ export { LingoProvider, createNextCookieLocaleResolver };
24
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":["BaseLingoProvider"],"sources":["../../../src/react/next/client.tsx"],"sourcesContent":["\"use client\";\nimport {\n LingoProvider as BaseLingoProvider,\n type LingoProviderProps,\n} from \"../shared/LingoProvider\";\nimport { useRouter } from \"next/navigation\";\nimport { logger } from \"../../utils/logger\";\n\nexport type { LingoProviderProps };\n\nexport const createNextCookieLocaleResolver = () => {\n return (locale: string) => {\n logger.warn(\"Is not supposed to run on client\");\n return locale;\n };\n};\n\nexport const LingoProvider = (props: LingoProviderProps) => {\n // So far we are just injecting the router to reload server components when the locale changes.\n return <BaseLingoProvider {...props} router={useRouter()} />;\n};\n"],"mappings":";;;;;;;;AAUA,MAAa,uCAAuC;AAClD,SAAQ,WAAmB;AACzB,SAAO,KAAK,mCAAmC;AAC/C,SAAO;;;AAIX,MAAa,iBAAiB,UAA8B;AAE1D,QAAO,oBAACA;EAAkB,GAAI;EAAO,QAAQ,WAAW;GAAI"}
@@ -0,0 +1,29 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../../utils/logger.cjs');
3
+ let next_headers = require("next/headers");
4
+
5
+ //#region src/react/next/cookie-locale-resolver.ts
6
+ /**
7
+ * Create Next.js locale resolver
8
+ *
9
+ * This resolver reads the locale from Next.js cookies.
10
+ * It does NOT fetch translations - that's handled separately by the core translation service.
11
+ *
12
+ * @param config - Configuration options
13
+ * @returns Locale resolver function
14
+ */
15
+ function createNextCookieLocaleResolver(config) {
16
+ const cookieName = config.cookieConfig.name;
17
+ const defaultLocale = config.defaultLocale;
18
+ return async () => {
19
+ try {
20
+ return (await (0, next_headers.cookies)()).get(cookieName)?.value || defaultLocale;
21
+ } catch (error) {
22
+ if (process.env.DEBUG) require_logger.logger.error(`Error reading locale from Next.js cookies: ${error}\n`);
23
+ return defaultLocale;
24
+ }
25
+ };
26
+ }
27
+
28
+ //#endregion
29
+ exports.createNextCookieLocaleResolver = createNextCookieLocaleResolver;
@@ -0,0 +1,33 @@
1
+ import { CookieConfig } from "../../types.cjs";
2
+ import { LocaleCode } from "lingo.dev/spec";
3
+
4
+ //#region src/react/next/cookie-locale-resolver.d.ts
5
+
6
+ /**
7
+ * Configuration for Next.js locale resolver
8
+ */
9
+ interface NextLocaleResolverConfig {
10
+ /**
11
+ * Cookie configuration (name and maxAge)
12
+ * @default { name: 'locale', maxAge: 31536000 }
13
+ */
14
+ cookieConfig: CookieConfig;
15
+ /**
16
+ * Default locale if cookie is not set
17
+ * @default 'en'
18
+ */
19
+ defaultLocale: LocaleCode;
20
+ }
21
+ /**
22
+ * Create Next.js locale resolver
23
+ *
24
+ * This resolver reads the locale from Next.js cookies.
25
+ * It does NOT fetch translations - that's handled separately by the core translation service.
26
+ *
27
+ * @param config - Configuration options
28
+ * @returns Locale resolver function
29
+ */
30
+ declare function createNextCookieLocaleResolver(config: NextLocaleResolverConfig): () => Promise<string>;
31
+ //#endregion
32
+ export { createNextCookieLocaleResolver };
33
+ //# sourceMappingURL=cookie-locale-resolver.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-locale-resolver.d.cts","names":[],"sources":["../../../src/react/next/cookie-locale-resolver.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAeU,wBAAA;;;;;gBAKM;;;;;iBAMC;;;;;;;;;;;iBAYD,8BAAA,SACN,iCACD"}
@@ -0,0 +1,33 @@
1
+ import { CookieConfig } from "../../types.mjs";
2
+ import { LocaleCode } from "lingo.dev/spec";
3
+
4
+ //#region src/react/next/cookie-locale-resolver.d.ts
5
+
6
+ /**
7
+ * Configuration for Next.js locale resolver
8
+ */
9
+ interface NextLocaleResolverConfig {
10
+ /**
11
+ * Cookie configuration (name and maxAge)
12
+ * @default { name: 'locale', maxAge: 31536000 }
13
+ */
14
+ cookieConfig: CookieConfig;
15
+ /**
16
+ * Default locale if cookie is not set
17
+ * @default 'en'
18
+ */
19
+ defaultLocale: LocaleCode;
20
+ }
21
+ /**
22
+ * Create Next.js locale resolver
23
+ *
24
+ * This resolver reads the locale from Next.js cookies.
25
+ * It does NOT fetch translations - that's handled separately by the core translation service.
26
+ *
27
+ * @param config - Configuration options
28
+ * @returns Locale resolver function
29
+ */
30
+ declare function createNextCookieLocaleResolver(config: NextLocaleResolverConfig): () => Promise<string>;
31
+ //#endregion
32
+ export { createNextCookieLocaleResolver };
33
+ //# sourceMappingURL=cookie-locale-resolver.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-locale-resolver.d.mts","names":[],"sources":["../../../src/react/next/cookie-locale-resolver.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAeU,wBAAA;;;;;gBAKM;;;;;iBAMC;;;;;;;;;;;iBAYD,8BAAA,SACN,iCACD"}
@@ -0,0 +1,29 @@
1
+ import { logger } from "../../utils/logger.mjs";
2
+ import { cookies } from "next/headers";
3
+
4
+ //#region src/react/next/cookie-locale-resolver.ts
5
+ /**
6
+ * Create Next.js locale resolver
7
+ *
8
+ * This resolver reads the locale from Next.js cookies.
9
+ * It does NOT fetch translations - that's handled separately by the core translation service.
10
+ *
11
+ * @param config - Configuration options
12
+ * @returns Locale resolver function
13
+ */
14
+ function createNextCookieLocaleResolver(config) {
15
+ const cookieName = config.cookieConfig.name;
16
+ const defaultLocale = config.defaultLocale;
17
+ return async () => {
18
+ try {
19
+ return (await cookies()).get(cookieName)?.value || defaultLocale;
20
+ } catch (error) {
21
+ if (process.env.DEBUG) logger.error(`Error reading locale from Next.js cookies: ${error}\n`);
22
+ return defaultLocale;
23
+ }
24
+ };
25
+ }
26
+
27
+ //#endregion
28
+ export { createNextCookieLocaleResolver };
29
+ //# sourceMappingURL=cookie-locale-resolver.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-locale-resolver.mjs","names":[],"sources":["../../../src/react/next/cookie-locale-resolver.ts"],"sourcesContent":["/**\n * Next.js-specific locale resolver\n * Reads locale from Next.js cookies\n *\n * This resolver ONLY handles locale resolution - it does NOT fetch translations.\n * Translation fetching is handled by the core translation service (server/translations.ts)\n */\nimport type { CookieConfig } from \"../../types\";\nimport { cookies } from \"next/headers\";\nimport { logger } from \"../../utils/logger\";\nimport type { LocaleCode } from \"lingo.dev/spec\";\n\n/**\n * Configuration for Next.js locale resolver\n */\ninterface NextLocaleResolverConfig {\n /**\n * Cookie configuration (name and maxAge)\n * @default { name: 'locale', maxAge: 31536000 }\n */\n cookieConfig: CookieConfig;\n\n /**\n * Default locale if cookie is not set\n * @default 'en'\n */\n defaultLocale: LocaleCode;\n}\n\n/**\n * Create Next.js locale resolver\n *\n * This resolver reads the locale from Next.js cookies.\n * It does NOT fetch translations - that's handled separately by the core translation service.\n *\n * @param config - Configuration options\n * @returns Locale resolver function\n */\nexport function createNextCookieLocaleResolver(\n config: NextLocaleResolverConfig,\n): () => Promise<string> {\n const cookieName = config.cookieConfig.name;\n const defaultLocale = config.defaultLocale;\n\n return async () => {\n try {\n const cookieStore = await cookies();\n return cookieStore.get(cookieName)?.value || defaultLocale;\n } catch (error) {\n // Fallback on error (e.g., not in Next.js environment, or cookies() failed)\n if (process.env.DEBUG) {\n logger.error(`Error reading locale from Next.js cookies: ${error}\\n`);\n }\n return defaultLocale;\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,SAAgB,+BACd,QACuB;CACvB,MAAM,aAAa,OAAO,aAAa;CACvC,MAAM,gBAAgB,OAAO;AAE7B,QAAO,YAAY;AACjB,MAAI;AAEF,WADoB,MAAM,SAAS,EAChB,IAAI,WAAW,EAAE,SAAS;WACtC,OAAO;AAEd,OAAI,QAAQ,IAAI,MACd,QAAO,MAAM,8CAA8C,MAAM,IAAI;AAEvE,UAAO"}
@@ -0,0 +1,21 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../../utils/logger.cjs');
3
+ const require_react_server_only_index = require('../server-only/index.cjs');
4
+ const require_react_next_client = require('./client.cjs');
5
+ const require_cookie_locale_resolver = require('./cookie-locale-resolver.cjs');
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+
8
+ //#region src/react/next/server.tsx
9
+ async function LingoProvider({ initialLocale, initialTranslations = {}, ...rest }) {
10
+ const { locale, translations } = await require_react_server_only_index.getServerTranslations({ locale: initialLocale });
11
+ require_logger.logger.debug(`Server. LingoProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`);
12
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_react_next_client.LingoProvider, {
13
+ initialLocale: locale,
14
+ initialTranslations: translations,
15
+ ...rest
16
+ });
17
+ }
18
+
19
+ //#endregion
20
+ exports.LingoProvider = LingoProvider;
21
+ exports.createNextCookieLocaleResolver = require_cookie_locale_resolver.createNextCookieLocaleResolver;
@@ -0,0 +1,13 @@
1
+ import { LingoProviderProps } from "../shared/LingoProvider.cjs";
2
+ import { createNextCookieLocaleResolver } from "./cookie-locale-resolver.cjs";
3
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
4
+
5
+ //#region src/react/next/server.d.ts
6
+ declare function LingoProvider({
7
+ initialLocale,
8
+ initialTranslations,
9
+ ...rest
10
+ }: LingoProviderProps): Promise<react_jsx_runtime0.JSX.Element>;
11
+ //#endregion
12
+ export { LingoProvider, createNextCookieLocaleResolver };
13
+ //# sourceMappingURL=server.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.cts","names":[],"sources":["../../../src/react/next/server.tsx"],"sourcesContent":[],"mappings":";;;;;iBAUsB,aAAA;;;;GAInB,qBAAkB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,14 @@
1
+ import { LingoProviderProps } from "../shared/LingoProvider.mjs";
2
+ import "./client.mjs";
3
+ import { createNextCookieLocaleResolver } from "./cookie-locale-resolver.mjs";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
5
+
6
+ //#region src/react/next/server.d.ts
7
+ declare function LingoProvider({
8
+ initialLocale,
9
+ initialTranslations,
10
+ ...rest
11
+ }: LingoProviderProps): Promise<react_jsx_runtime0.JSX.Element>;
12
+ //#endregion
13
+ export { LingoProvider, createNextCookieLocaleResolver };
14
+ //# sourceMappingURL=server.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.mts","names":[],"sources":["../../../src/react/next/server.tsx"],"sourcesContent":[],"mappings":";;;;;;iBAUsB,aAAA;;;;GAInB,qBAAkB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,20 @@
1
+ import { logger } from "../../utils/logger.mjs";
2
+ import { getServerTranslations } from "../server-only/index.mjs";
3
+ import { LingoProvider as LingoProvider$1 } from "./client.mjs";
4
+ import { createNextCookieLocaleResolver } from "./cookie-locale-resolver.mjs";
5
+ import { jsx } from "react/jsx-runtime";
6
+
7
+ //#region src/react/next/server.tsx
8
+ async function LingoProvider({ initialLocale, initialTranslations = {}, ...rest }) {
9
+ const { locale, translations } = await getServerTranslations({ locale: initialLocale });
10
+ logger.debug(`Server. LingoProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`);
11
+ return /* @__PURE__ */ jsx(LingoProvider$1, {
12
+ initialLocale: locale,
13
+ initialTranslations: translations,
14
+ ...rest
15
+ });
16
+ }
17
+
18
+ //#endregion
19
+ export { LingoProvider, createNextCookieLocaleResolver };
20
+ //# sourceMappingURL=server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.mjs","names":["BaseLingoProvider"],"sources":["../../../src/react/next/server.tsx"],"sourcesContent":["import {\n LingoProvider as BaseLingoProvider,\n type LingoProviderProps,\n} from \"./client\";\nimport { getServerTranslations } from \"../server-only\";\nimport { logger } from \"../../utils/logger\";\nimport { createNextCookieLocaleResolver } from \"./cookie-locale-resolver\";\n\nexport { createNextCookieLocaleResolver };\n\nexport async function LingoProvider({\n initialLocale,\n initialTranslations = {},\n ...rest\n}: LingoProviderProps) {\n const { locale, translations } = await getServerTranslations({\n locale: initialLocale,\n });\n\n logger.debug(\n `Server. LingoProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`,\n );\n\n return (\n <BaseLingoProvider\n initialLocale={locale}\n initialTranslations={translations}\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,cAAc,EAClC,eACA,sBAAsB,EAAE,EACxB,GAAG,QACkB;CACrB,MAAM,EAAE,QAAQ,iBAAiB,MAAM,sBAAsB,EAC3D,QAAQ,eACT,CAAC;AAEF,QAAO,MACL,0CAA0C,cAAc,qBAAqB,OAAO,kBAAkB,KAAK,UAAU,aAAa,GACnI;AAED,QACE,oBAACA;EACC,eAAe;EACf,qBAAqB;EACrB,GAAI;GACJ"}
@@ -0,0 +1,19 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../../utils/logger.cjs');
3
+ const require_LingoProvider = require('../shared/LingoProvider.cjs');
4
+ const require_react_server_only_index = require('../server-only/index.cjs');
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+
7
+ //#region src/react/server/ServerLingoProvider.tsx
8
+ async function LingoProvider({ initialLocale, initialTranslations = {}, ...rest }) {
9
+ const { locale, translations } = await require_react_server_only_index.getServerTranslations({ locale: initialLocale });
10
+ require_logger.logger.debug(`Server. LingoProvider. Resolved locale: ${locale}`);
11
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_LingoProvider.LingoProvider, {
12
+ initialLocale: locale,
13
+ initialTranslations: translations,
14
+ ...rest
15
+ });
16
+ }
17
+
18
+ //#endregion
19
+ exports.LingoProvider = LingoProvider;
@@ -0,0 +1,12 @@
1
+ import { LingoProviderProps } from "../shared/LingoProvider.cjs";
2
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
3
+
4
+ //#region src/react/server/ServerLingoProvider.d.ts
5
+ declare function LingoProvider({
6
+ initialLocale,
7
+ initialTranslations,
8
+ ...rest
9
+ }: LingoProviderProps): Promise<react_jsx_runtime3.JSX.Element>;
10
+ //#endregion
11
+ export { LingoProvider };
12
+ //# sourceMappingURL=ServerLingoProvider.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerLingoProvider.d.cts","names":[],"sources":["../../../src/react/server/ServerLingoProvider.tsx"],"sourcesContent":[],"mappings":";;;;iBAOsB,aAAA;;;;GAInB,qBAAkB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,12 @@
1
+ import { LingoProviderProps } from "../shared/LingoProvider.mjs";
2
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
3
+
4
+ //#region src/react/server/ServerLingoProvider.d.ts
5
+ declare function LingoProvider({
6
+ initialLocale,
7
+ initialTranslations,
8
+ ...rest
9
+ }: LingoProviderProps): Promise<react_jsx_runtime3.JSX.Element>;
10
+ //#endregion
11
+ export { LingoProvider };
12
+ //# sourceMappingURL=ServerLingoProvider.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerLingoProvider.d.mts","names":[],"sources":["../../../src/react/server/ServerLingoProvider.tsx"],"sourcesContent":[],"mappings":";;;;iBAOsB,aAAA;;;;GAInB,qBAAkB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,19 @@
1
+ import { logger } from "../../utils/logger.mjs";
2
+ import { LingoProvider as LingoProvider$1 } from "../shared/LingoProvider.mjs";
3
+ import { getServerTranslations } from "../server-only/index.mjs";
4
+ import { jsx } from "react/jsx-runtime";
5
+
6
+ //#region src/react/server/ServerLingoProvider.tsx
7
+ async function LingoProvider({ initialLocale, initialTranslations = {}, ...rest }) {
8
+ const { locale, translations } = await getServerTranslations({ locale: initialLocale });
9
+ logger.debug(`Server. LingoProvider. Resolved locale: ${locale}`);
10
+ return /* @__PURE__ */ jsx(LingoProvider$1, {
11
+ initialLocale: locale,
12
+ initialTranslations: translations,
13
+ ...rest
14
+ });
15
+ }
16
+
17
+ //#endregion
18
+ export { LingoProvider };
19
+ //# sourceMappingURL=ServerLingoProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerLingoProvider.mjs","names":["BaseLingoProvider"],"sources":["../../../src/react/server/ServerLingoProvider.tsx"],"sourcesContent":["import {\n LingoProvider as BaseLingoProvider,\n type LingoProviderProps,\n} from \"../shared/LingoProvider\";\nimport { getServerTranslations } from \"../server-only\";\nimport { logger } from \"../../utils/logger\";\n\nexport async function LingoProvider({\n initialLocale,\n initialTranslations = {},\n ...rest\n}: LingoProviderProps) {\n const { locale, translations } = await getServerTranslations({\n locale: initialLocale,\n });\n\n logger.debug(`Server. LingoProvider. Resolved locale: ${locale}`);\n\n return (\n <BaseLingoProvider\n initialLocale={locale}\n initialTranslations={translations}\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;AAOA,eAAsB,cAAc,EAClC,eACA,sBAAsB,EAAE,EACxB,GAAG,QACkB;CACrB,MAAM,EAAE,QAAQ,iBAAiB,MAAM,sBAAsB,EAC3D,QAAQ,eACT,CAAC;AAEF,QAAO,MAAM,2CAA2C,SAAS;AAEjE,QACE,oBAACA;EACC,eAAe;EACf,qBAAqB;EACrB,GAAI;GACJ"}
@@ -0,0 +1,7 @@
1
+ const require_ServerLingoProvider = require('./ServerLingoProvider.cjs');
2
+ const require_LocaleSwitcher = require('../shared/LocaleSwitcher.cjs');
3
+ const require_useTranslation = require('./useTranslation.cjs');
4
+
5
+ exports.LingoProvider = require_ServerLingoProvider.LingoProvider;
6
+ exports.LocaleSwitcher = require_LocaleSwitcher.LocaleSwitcher;
7
+ exports.useTranslation = require_useTranslation.useTranslation;
@@ -0,0 +1,4 @@
1
+ import { LocaleSwitcher } from "../shared/LocaleSwitcher.cjs";
2
+ import { LingoProvider } from "./ServerLingoProvider.cjs";
3
+ import { useTranslation } from "./useTranslation.cjs";
4
+ export { LingoProvider, LocaleSwitcher, useTranslation };
@@ -0,0 +1,4 @@
1
+ import { LocaleSwitcher } from "../shared/LocaleSwitcher.mjs";
2
+ import { LingoProvider } from "./ServerLingoProvider.mjs";
3
+ import { useTranslation } from "./useTranslation.mjs";
4
+ export { LingoProvider, LocaleSwitcher, useTranslation };
@@ -0,0 +1,5 @@
1
+ import { LingoProvider } from "./ServerLingoProvider.mjs";
2
+ import { LocaleSwitcher } from "../shared/LocaleSwitcher.mjs";
3
+ import { useTranslation } from "./useTranslation.mjs";
4
+
5
+ export { LingoProvider, LocaleSwitcher, useTranslation };
@@ -0,0 +1,60 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../../utils/logger.cjs');
3
+ const require_translations = require('../server-only/translations.cjs');
4
+ const require_render_rich_text = require('../shared/render-rich-text.cjs');
5
+ let react = require("react");
6
+ let _lingo_dev_compiler_virtual_locale_server = require("@lingo.dev/compiler/virtual/locale/server");
7
+
8
+ //#region src/react/server/useTranslation.ts
9
+ const getTranslations = async (hashes) => {
10
+ const locale = await (0, _lingo_dev_compiler_virtual_locale_server.getServerLocale)();
11
+ const translations = await require_translations.fetchTranslationsOnServer(locale, hashes);
12
+ require_logger.logger.debug(`Server. The translations for locale ${locale} are: ${JSON.stringify(translations)}`);
13
+ return {
14
+ locale,
15
+ translations
16
+ };
17
+ };
18
+ /**
19
+ * Server-side translation hook
20
+ *
21
+ * Works in Server Components WITHOUT async/await!
22
+ * Uses React's use() hook to unwrap the cached promise.
23
+ *
24
+ * This hook has the SAME signature as the client-side version,
25
+ * making components truly isomorphic.
26
+ *
27
+ * @param hashes - List of translation hashes used in component (injected by compiler)
28
+ * @returns Translation function
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * // Works in Server Components (no async needed!)
33
+ * export default function ServerPage() {
34
+ * const t = useTranslation(['hash_abc', 'hash_def']);
35
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
36
+ * }
37
+ *
38
+ * // Also works in Client Components (via conditional exports)
39
+ * 'use client';
40
+ * export default function ClientPage() {
41
+ * const t = useTranslation(['hash_abc', 'hash_def']);
42
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
43
+ * }
44
+ * ```
45
+ */
46
+ const useTranslation = (hashes) => {
47
+ const { locale, translations } = (0, react.use)(getTranslations(hashes));
48
+ require_logger.logger.debug(`Server. The translations for locale ${locale} are: ${JSON.stringify(translations)}`);
49
+ return {
50
+ t: (hash, source, params) => {
51
+ const text = translations[hash] || source;
52
+ if (!params) return text;
53
+ return require_render_rich_text.renderRichText(text, params, locale);
54
+ },
55
+ locale
56
+ };
57
+ };
58
+
59
+ //#endregion
60
+ exports.useTranslation = useTranslation;
@@ -0,0 +1,36 @@
1
+ import { TranslationHook } from "../types.cjs";
2
+
3
+ //#region src/react/server/useTranslation.d.ts
4
+
5
+ /**
6
+ * Server-side translation hook
7
+ *
8
+ * Works in Server Components WITHOUT async/await!
9
+ * Uses React's use() hook to unwrap the cached promise.
10
+ *
11
+ * This hook has the SAME signature as the client-side version,
12
+ * making components truly isomorphic.
13
+ *
14
+ * @param hashes - List of translation hashes used in component (injected by compiler)
15
+ * @returns Translation function
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * // Works in Server Components (no async needed!)
20
+ * export default function ServerPage() {
21
+ * const t = useTranslation(['hash_abc', 'hash_def']);
22
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
23
+ * }
24
+ *
25
+ * // Also works in Client Components (via conditional exports)
26
+ * 'use client';
27
+ * export default function ClientPage() {
28
+ * const t = useTranslation(['hash_abc', 'hash_def']);
29
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
30
+ * }
31
+ * ```
32
+ */
33
+ declare const useTranslation: TranslationHook;
34
+ //#endregion
35
+ export { useTranslation };
36
+ //# sourceMappingURL=useTranslation.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslation.d.cts","names":[],"sources":["../../../src/react/server/useTranslation.ts"],"sourcesContent":[],"mappings":";;;;;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,gBAAgB"}
@@ -0,0 +1,36 @@
1
+ import { TranslationHook } from "../types.mjs";
2
+
3
+ //#region src/react/server/useTranslation.d.ts
4
+
5
+ /**
6
+ * Server-side translation hook
7
+ *
8
+ * Works in Server Components WITHOUT async/await!
9
+ * Uses React's use() hook to unwrap the cached promise.
10
+ *
11
+ * This hook has the SAME signature as the client-side version,
12
+ * making components truly isomorphic.
13
+ *
14
+ * @param hashes - List of translation hashes used in component (injected by compiler)
15
+ * @returns Translation function
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * // Works in Server Components (no async needed!)
20
+ * export default function ServerPage() {
21
+ * const t = useTranslation(['hash_abc', 'hash_def']);
22
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
23
+ * }
24
+ *
25
+ * // Also works in Client Components (via conditional exports)
26
+ * 'use client';
27
+ * export default function ClientPage() {
28
+ * const t = useTranslation(['hash_abc', 'hash_def']);
29
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
30
+ * }
31
+ * ```
32
+ */
33
+ declare const useTranslation: TranslationHook;
34
+ //#endregion
35
+ export { useTranslation };
36
+ //# sourceMappingURL=useTranslation.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslation.d.mts","names":[],"sources":["../../../src/react/server/useTranslation.ts"],"sourcesContent":[],"mappings":";;;;;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,gBAAgB"}
@@ -0,0 +1,60 @@
1
+ import { logger } from "../../utils/logger.mjs";
2
+ import { fetchTranslationsOnServer } from "../server-only/translations.mjs";
3
+ import { renderRichText } from "../shared/render-rich-text.mjs";
4
+ import { use } from "react";
5
+ import { getServerLocale } from "@lingo.dev/compiler/virtual/locale/server";
6
+
7
+ //#region src/react/server/useTranslation.ts
8
+ const getTranslations = async (hashes) => {
9
+ const locale = await getServerLocale();
10
+ const translations = await fetchTranslationsOnServer(locale, hashes);
11
+ logger.debug(`Server. The translations for locale ${locale} are: ${JSON.stringify(translations)}`);
12
+ return {
13
+ locale,
14
+ translations
15
+ };
16
+ };
17
+ /**
18
+ * Server-side translation hook
19
+ *
20
+ * Works in Server Components WITHOUT async/await!
21
+ * Uses React's use() hook to unwrap the cached promise.
22
+ *
23
+ * This hook has the SAME signature as the client-side version,
24
+ * making components truly isomorphic.
25
+ *
26
+ * @param hashes - List of translation hashes used in component (injected by compiler)
27
+ * @returns Translation function
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * // Works in Server Components (no async needed!)
32
+ * export default function ServerPage() {
33
+ * const t = useTranslation(['hash_abc', 'hash_def']);
34
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
35
+ * }
36
+ *
37
+ * // Also works in Client Components (via conditional exports)
38
+ * 'use client';
39
+ * export default function ClientPage() {
40
+ * const t = useTranslation(['hash_abc', 'hash_def']);
41
+ * return <h1>{t('hash_abc', 'Welcome')}</h1>;
42
+ * }
43
+ * ```
44
+ */
45
+ const useTranslation = (hashes) => {
46
+ const { locale, translations } = use(getTranslations(hashes));
47
+ logger.debug(`Server. The translations for locale ${locale} are: ${JSON.stringify(translations)}`);
48
+ return {
49
+ t: (hash, source, params) => {
50
+ const text = translations[hash] || source;
51
+ if (!params) return text;
52
+ return renderRichText(text, params, locale);
53
+ },
54
+ locale
55
+ };
56
+ };
57
+
58
+ //#endregion
59
+ export { useTranslation };
60
+ //# sourceMappingURL=useTranslation.mjs.map