@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/server/useTranslation.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { use } from \"react\";\nimport { getServerLocale } from \"@lingo.dev/compiler/virtual/locale/server\";\nimport { fetchTranslationsOnServer } from \"../server-only/translations\";\nimport {\n renderRichText,\n type RichTextParams,\n} from \"../shared/render-rich-text\";\nimport { logger } from \"../../utils/logger\";\nimport type { TranslationHook } from \"../types\";\n\n// TODO (AleksandrSl 01/12/2025): Should we add back the cache?\nconst getTranslations = async (hashes: string[]) => {\n // 1. Resolve locale (framework-specific)\n const locale = await getServerLocale();\n\n // 2. Fetch translations (universal)\n const translations = await fetchTranslationsOnServer(locale, hashes);\n\n logger.debug(\n `Server. The translations for locale ${locale} are: ${JSON.stringify(translations)}`,\n );\n\n return {\n locale,\n translations,\n };\n};\n\n/**\n * Server-side translation hook\n *\n * Works in Server Components WITHOUT async/await!\n * Uses React's use() hook to unwrap the cached promise.\n *\n * This hook has the SAME signature as the client-side version,\n * making components truly isomorphic.\n *\n * @param hashes - List of translation hashes used in component (injected by compiler)\n * @returns Translation function\n *\n * @example\n * ```tsx\n * // Works in Server Components (no async needed!)\n * export default function ServerPage() {\n * const t = useTranslation(['hash_abc', 'hash_def']);\n * return <h1>{t('hash_abc', 'Welcome')}</h1>;\n * }\n *\n * // Also works in Client Components (via conditional exports)\n * 'use client';\n * export default function ClientPage() {\n * const t = useTranslation(['hash_abc', 'hash_def']);\n * return <h1>{t('hash_abc', 'Welcome')}</h1>;\n * }\n * ```\n */\nexport const useTranslation: TranslationHook = (hashes: string[]) => {\n const { locale, translations } = use(getTranslations(hashes));\n logger.debug(\n `Server. The translations for locale ${locale} are: ${JSON.stringify(translations)}`,\n );\n\n return {\n t: (\n hash: string,\n source: string,\n params?: RichTextParams,\n ): string | ReactNode => {\n const text = translations[hash] || source;\n\n if (!params) {\n return text;\n }\n\n return renderRichText(text, params, locale);\n },\n locale,\n };\n};\n"],"mappings":";;;;;;;AAYA,MAAM,kBAAkB,OAAO,WAAqB;CAElD,MAAM,SAAS,MAAM,iBAAiB;CAGtC,MAAM,eAAe,MAAM,0BAA0B,QAAQ,OAAO;AAEpE,QAAO,MACL,uCAAuC,OAAO,QAAQ,KAAK,UAAU,aAAa,GACnF;AAED,QAAO;EACL;EACA;EACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BH,MAAaA,kBAAmC,WAAqB;CACnE,MAAM,EAAE,QAAQ,iBAAiB,IAAI,gBAAgB,OAAO,CAAC;AAC7D,QAAO,MACL,uCAAuC,OAAO,QAAQ,KAAK,UAAU,aAAa,GACnF;AAED,QAAO;EACL,IACE,MACA,QACA,WACuB;GACvB,MAAM,OAAO,aAAa,SAAS;AAEnC,OAAI,CAAC,OACH,QAAO;AAGT,UAAO,eAAe,MAAM,QAAQ,OAAO;;EAE7C;EACD"}
@@ -0,0 +1,42 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../../utils/logger.cjs');
3
+ const require_translations = require('./translations.cjs');
4
+ const require_render_rich_text = require('../shared/render-rich-text.cjs');
5
+ let _lingo_dev_compiler_virtual_locale_server = require("@lingo.dev/compiler/virtual/locale/server");
6
+
7
+ //#region src/react/server-only/index.ts
8
+ /**
9
+ * Server-side translation utilities for React Server Components
10
+ * Provides async API for explicit locale passing
11
+ *
12
+ * NOTE: For most cases, use the unified `useTranslation()` hook instead.
13
+ * This module is for advanced use cases where you need explicit control.
14
+ *
15
+ * @module @lingo.dev/compiler-beta/react/server
16
+ */
17
+ /**
18
+ * Get server-side translations function
19
+ * This is the async alternative to useTranslation() for Server Components
20
+ *
21
+ * For the most common use case, use the unified `useTranslation()` hook instead.
22
+ *
23
+ * The function automatically fetches translations from static files in production
24
+ * and falls back to the development server in development mode.
25
+ */
26
+ async function getServerTranslations(options) {
27
+ const locale = options.locale || await (0, _lingo_dev_compiler_virtual_locale_server.getServerLocale)();
28
+ require_logger.logger.debug(`Async Server. Fetching translations for ${locale}`);
29
+ const translations = await require_translations.fetchTranslationsOnServer(locale, options.hashes ?? [], { basePath: options.basePath });
30
+ return {
31
+ t: (hash, sourceText, params) => {
32
+ const text = translations[hash] || sourceText;
33
+ if (!params) return text;
34
+ return require_render_rich_text.renderRichText(text, params, locale);
35
+ },
36
+ locale,
37
+ translations
38
+ };
39
+ }
40
+
41
+ //#endregion
42
+ exports.getServerTranslations = getServerTranslations;
@@ -0,0 +1,38 @@
1
+ import { RichTextParams } from "../shared/render-rich-text.cjs";
2
+ import { LocaleCode } from "lingo.dev/spec";
3
+ import { ReactNode } from "react";
4
+
5
+ //#region src/react/server-only/index.d.ts
6
+
7
+ /**
8
+ * Get server-side translations function
9
+ * This is the async alternative to useTranslation() for Server Components
10
+ *
11
+ * For the most common use case, use the unified `useTranslation()` hook instead.
12
+ *
13
+ * The function automatically fetches translations from static files in production
14
+ * and falls back to the development server in development mode.
15
+ */
16
+ declare function getServerTranslations(options: {
17
+ /**
18
+ * Target locale for translations (required)
19
+ */
20
+ locale?: LocaleCode;
21
+ /**
22
+ * List of translation hashes needed for this component
23
+ * Typically injected at build time by the Babel plugin
24
+ */
25
+ hashes?: string[];
26
+ /**
27
+ * Base path for translation files
28
+ * @default process.cwd()
29
+ */
30
+ basePath?: string;
31
+ }): Promise<{
32
+ t: (hash: string, sourceText: string, params?: RichTextParams) => string | ReactNode;
33
+ locale: LocaleCode;
34
+ translations: Record<string, string>;
35
+ }>;
36
+ //#endregion
37
+ export { getServerTranslations };
38
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/react/server-only/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;iBA8BsB,qBAAA;;;;WAIX;;;;;;;;;;;IAaP;iDAIS,4BACG;UACN;gBACM"}
@@ -0,0 +1,38 @@
1
+ import { RichTextParams } from "../shared/render-rich-text.mjs";
2
+ import { ReactNode } from "react";
3
+ import { LocaleCode } from "lingo.dev/spec";
4
+
5
+ //#region src/react/server-only/index.d.ts
6
+
7
+ /**
8
+ * Get server-side translations function
9
+ * This is the async alternative to useTranslation() for Server Components
10
+ *
11
+ * For the most common use case, use the unified `useTranslation()` hook instead.
12
+ *
13
+ * The function automatically fetches translations from static files in production
14
+ * and falls back to the development server in development mode.
15
+ */
16
+ declare function getServerTranslations(options: {
17
+ /**
18
+ * Target locale for translations (required)
19
+ */
20
+ locale?: LocaleCode;
21
+ /**
22
+ * List of translation hashes needed for this component
23
+ * Typically injected at build time by the Babel plugin
24
+ */
25
+ hashes?: string[];
26
+ /**
27
+ * Base path for translation files
28
+ * @default process.cwd()
29
+ */
30
+ basePath?: string;
31
+ }): Promise<{
32
+ t: (hash: string, sourceText: string, params?: RichTextParams) => string | ReactNode;
33
+ locale: LocaleCode;
34
+ translations: Record<string, string>;
35
+ }>;
36
+ //#endregion
37
+ export { getServerTranslations };
38
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/react/server-only/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;iBA8BsB,qBAAA;;;;WAIX;;;;;;;;;;;IAaP;iDAIS,4BACG;UACN;gBACM"}
@@ -0,0 +1,42 @@
1
+ import { logger } from "../../utils/logger.mjs";
2
+ import { fetchTranslationsOnServer } from "./translations.mjs";
3
+ import { renderRichText } from "../shared/render-rich-text.mjs";
4
+ import { getServerLocale } from "@lingo.dev/compiler/virtual/locale/server";
5
+
6
+ //#region src/react/server-only/index.ts
7
+ /**
8
+ * Server-side translation utilities for React Server Components
9
+ * Provides async API for explicit locale passing
10
+ *
11
+ * NOTE: For most cases, use the unified `useTranslation()` hook instead.
12
+ * This module is for advanced use cases where you need explicit control.
13
+ *
14
+ * @module @lingo.dev/compiler-beta/react/server
15
+ */
16
+ /**
17
+ * Get server-side translations function
18
+ * This is the async alternative to useTranslation() for Server Components
19
+ *
20
+ * For the most common use case, use the unified `useTranslation()` hook instead.
21
+ *
22
+ * The function automatically fetches translations from static files in production
23
+ * and falls back to the development server in development mode.
24
+ */
25
+ async function getServerTranslations(options) {
26
+ const locale = options.locale || await getServerLocale();
27
+ logger.debug(`Async Server. Fetching translations for ${locale}`);
28
+ const translations = await fetchTranslationsOnServer(locale, options.hashes ?? [], { basePath: options.basePath });
29
+ return {
30
+ t: (hash, sourceText, params) => {
31
+ const text = translations[hash] || sourceText;
32
+ if (!params) return text;
33
+ return renderRichText(text, params, locale);
34
+ },
35
+ locale,
36
+ translations
37
+ };
38
+ }
39
+
40
+ //#endregion
41
+ export { getServerTranslations };
42
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/react/server-only/index.ts"],"sourcesContent":["/**\n * Server-side translation utilities for React Server Components\n * Provides async API for explicit locale passing\n *\n * NOTE: For most cases, use the unified `useTranslation()` hook instead.\n * This module is for advanced use cases where you need explicit control.\n *\n * @module @lingo.dev/compiler-beta/react/server\n */\n\nimport { fetchTranslationsOnServer } from \"./translations\";\nimport {\n renderRichText,\n type RichTextParams,\n} from \"../shared/render-rich-text\";\nimport type { ReactNode } from \"react\";\nimport { logger } from \"../../utils/logger\";\n// Keep this import full for replacement during build.\nimport { getServerLocale } from \"@lingo.dev/compiler/virtual/locale/server\";\nimport type { LocaleCode } from \"lingo.dev/spec\";\n\n/**\n * Get server-side translations function\n * This is the async alternative to useTranslation() for Server Components\n *\n * For the most common use case, use the unified `useTranslation()` hook instead.\n *\n * The function automatically fetches translations from static files in production\n * and falls back to the development server in development mode.\n */\nexport async function getServerTranslations(options: {\n /**\n * Target locale for translations (required)\n */\n locale?: LocaleCode;\n\n /**\n * List of translation hashes needed for this component\n * Typically injected at build time by the Babel plugin\n */\n hashes?: string[];\n\n /**\n * Base path for translation files\n * @default process.cwd()\n */\n basePath?: string;\n}): Promise<{\n t: (\n hash: string,\n sourceText: string,\n params?: RichTextParams,\n ) => string | ReactNode;\n locale: LocaleCode;\n translations: Record<string, string>;\n}> {\n const locale = options.locale || (await getServerLocale());\n\n logger.debug(`Async Server. Fetching translations for ${locale}`);\n\n const translations = await fetchTranslationsOnServer(\n locale,\n options.hashes ?? [],\n {\n basePath: options.basePath,\n },\n );\n\n return {\n t: (hash: string, sourceText: string, params?: RichTextParams) => {\n const text = translations[hash] || sourceText;\n\n if (!params) {\n return text;\n }\n\n return renderRichText(text, params, locale);\n },\n locale,\n translations,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,sBAAsB,SAyBzC;CACD,MAAM,SAAS,QAAQ,UAAW,MAAM,iBAAiB;AAEzD,QAAO,MAAM,2CAA2C,SAAS;CAEjE,MAAM,eAAe,MAAM,0BACzB,QACA,QAAQ,UAAU,EAAE,EACpB,EACE,UAAU,QAAQ,UACnB,CACF;AAED,QAAO;EACL,IAAI,MAAc,YAAoB,WAA4B;GAChE,MAAM,OAAO,aAAa,SAAS;AAEnC,OAAI,CAAC,OACH,QAAO;AAGT,UAAO,eAAe,MAAM,QAAQ,OAAO;;EAE7C;EACA;EACD"}
@@ -0,0 +1,85 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../../utils/logger.cjs');
3
+ const require_utils = require('../shared/utils.cjs');
4
+ let _lingo_dev_compiler_virtual_config = require("@lingo.dev/compiler/virtual/config");
5
+ let fs_promises = require("fs/promises");
6
+ let path = require("path");
7
+
8
+ //#region src/react/server-only/translations.ts
9
+ /**
10
+ * Core translation service - framework-agnostic
11
+ * Handles fetching translations from dev server or filesystem
12
+ *
13
+ * This is the UNIVERSAL pattern that works across all frameworks:
14
+ * Given a locale, fetch the translation dictionary for that locale.
15
+ *
16
+ * @module @lingo.dev/compiler/react/server/translations
17
+ */
18
+ /**
19
+ * Read translations from filesystem
20
+ * Used in production builds or as fallback in development
21
+ *
22
+ * Tries multiple common locations for translation files:
23
+ * - .lingo/cache/{locale}.json (dev cache)
24
+ * - .next/{locale}.json (Next.js)
25
+ *
26
+ * @param locale - Target locale
27
+ * @param basePath - Base directory to search from (default: cwd)
28
+ * @returns Translation dictionary (hash -> translated text)
29
+ */
30
+ async function readFromFilesystem(locale, basePath = process.cwd()) {
31
+ const possiblePaths = [(0, path.join)(basePath, _lingo_dev_compiler_virtual_config.cacheDir, `${locale}.json`), (0, path.join)(basePath, ".next", `${locale}.json`)];
32
+ for (const filePath of possiblePaths) try {
33
+ const fileContent = await (0, fs_promises.readFile)(filePath, "utf-8");
34
+ const translations = JSON.parse(fileContent).entries || {};
35
+ require_logger.logger.debug(`Loaded ${Object.keys(translations).length} translations from ${filePath}`);
36
+ return translations;
37
+ } catch {
38
+ continue;
39
+ }
40
+ if (process.env.NODE_ENV === "development") require_logger.logger.warn(`Translation file not found for locale: ${locale}. Tried: ${possiblePaths.join(", ")}`);
41
+ return {};
42
+ }
43
+ /**
44
+ * Fetch translations for a given locale
45
+ *
46
+ * This is the CORE UNIVERSAL function that works across all frameworks.
47
+ * It handles the logic of fetching translations from either:
48
+ * - Development server (if running)
49
+ * - Filesystem (production or fallback)
50
+ *
51
+ * Framework-specific code should NOT duplicate this logic.
52
+ * Instead, they should:
53
+ * 1. Resolve the locale (framework-specific: cookies, URL, headers, etc.)
54
+ * 2. Call this function to get translations
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * // In Next.js locale resolver
59
+ * const locale = await getLocaleFromCookies();
60
+ * const translations = await fetchTranslations(locale);
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // In React Router loader
66
+ * const locale = getLocaleFromUrl(request.url);
67
+ * const translations = await fetchTranslations(locale);
68
+ * ```
69
+ */
70
+ async function fetchTranslationsOnServer(locale, hashes, config = {}) {
71
+ if (process.env.NODE_ENV === "development" && _lingo_dev_compiler_virtual_config.serverUrl) {
72
+ require_logger.logger.debug(`Server. Fetching translations for ${locale} and ${hashes.join(", ")} from dev server (${_lingo_dev_compiler_virtual_config.serverUrl})`);
73
+ try {
74
+ return await require_utils.fetchTranslations(locale, hashes, _lingo_dev_compiler_virtual_config.serverUrl);
75
+ } catch (error) {
76
+ require_logger.logger.warn(`Failed to fetch translations from translation server: ${error}.`);
77
+ return {};
78
+ }
79
+ }
80
+ require_logger.logger.debug(`Reading translations for ${locale} from filesystem`);
81
+ return await readFromFilesystem(locale, config.basePath);
82
+ }
83
+
84
+ //#endregion
85
+ exports.fetchTranslationsOnServer = fetchTranslationsOnServer;
@@ -0,0 +1,85 @@
1
+ import { logger } from "../../utils/logger.mjs";
2
+ import { fetchTranslations } from "../shared/utils.mjs";
3
+ import { cacheDir, serverUrl } from "@lingo.dev/compiler/virtual/config";
4
+ import { readFile } from "fs/promises";
5
+ import { join } from "path";
6
+
7
+ //#region src/react/server-only/translations.ts
8
+ /**
9
+ * Core translation service - framework-agnostic
10
+ * Handles fetching translations from dev server or filesystem
11
+ *
12
+ * This is the UNIVERSAL pattern that works across all frameworks:
13
+ * Given a locale, fetch the translation dictionary for that locale.
14
+ *
15
+ * @module @lingo.dev/compiler/react/server/translations
16
+ */
17
+ /**
18
+ * Read translations from filesystem
19
+ * Used in production builds or as fallback in development
20
+ *
21
+ * Tries multiple common locations for translation files:
22
+ * - .lingo/cache/{locale}.json (dev cache)
23
+ * - .next/{locale}.json (Next.js)
24
+ *
25
+ * @param locale - Target locale
26
+ * @param basePath - Base directory to search from (default: cwd)
27
+ * @returns Translation dictionary (hash -> translated text)
28
+ */
29
+ async function readFromFilesystem(locale, basePath = process.cwd()) {
30
+ const possiblePaths = [join(basePath, cacheDir, `${locale}.json`), join(basePath, ".next", `${locale}.json`)];
31
+ for (const filePath of possiblePaths) try {
32
+ const fileContent = await readFile(filePath, "utf-8");
33
+ const translations = JSON.parse(fileContent).entries || {};
34
+ logger.debug(`Loaded ${Object.keys(translations).length} translations from ${filePath}`);
35
+ return translations;
36
+ } catch {
37
+ continue;
38
+ }
39
+ if (process.env.NODE_ENV === "development") logger.warn(`Translation file not found for locale: ${locale}. Tried: ${possiblePaths.join(", ")}`);
40
+ return {};
41
+ }
42
+ /**
43
+ * Fetch translations for a given locale
44
+ *
45
+ * This is the CORE UNIVERSAL function that works across all frameworks.
46
+ * It handles the logic of fetching translations from either:
47
+ * - Development server (if running)
48
+ * - Filesystem (production or fallback)
49
+ *
50
+ * Framework-specific code should NOT duplicate this logic.
51
+ * Instead, they should:
52
+ * 1. Resolve the locale (framework-specific: cookies, URL, headers, etc.)
53
+ * 2. Call this function to get translations
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // In Next.js locale resolver
58
+ * const locale = await getLocaleFromCookies();
59
+ * const translations = await fetchTranslations(locale);
60
+ * ```
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * // In React Router loader
65
+ * const locale = getLocaleFromUrl(request.url);
66
+ * const translations = await fetchTranslations(locale);
67
+ * ```
68
+ */
69
+ async function fetchTranslationsOnServer(locale, hashes, config = {}) {
70
+ if (process.env.NODE_ENV === "development" && serverUrl) {
71
+ logger.debug(`Server. Fetching translations for ${locale} and ${hashes.join(", ")} from dev server (${serverUrl})`);
72
+ try {
73
+ return await fetchTranslations(locale, hashes, serverUrl);
74
+ } catch (error) {
75
+ logger.warn(`Failed to fetch translations from translation server: ${error}.`);
76
+ return {};
77
+ }
78
+ }
79
+ logger.debug(`Reading translations for ${locale} from filesystem`);
80
+ return await readFromFilesystem(locale, config.basePath);
81
+ }
82
+
83
+ //#endregion
84
+ export { fetchTranslationsOnServer };
85
+ //# sourceMappingURL=translations.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translations.mjs","names":["fetchFromDevServer"],"sources":["../../../src/react/server-only/translations.ts"],"sourcesContent":["/**\n * Core translation service - framework-agnostic\n * Handles fetching translations from dev server or filesystem\n *\n * This is the UNIVERSAL pattern that works across all frameworks:\n * Given a locale, fetch the translation dictionary for that locale.\n *\n * @module @lingo.dev/compiler/react/server/translations\n */\n\nimport { readFile } from \"fs/promises\";\nimport { join } from \"path\";\nimport { logger } from \"../../utils/logger\";\nimport { fetchTranslations as fetchFromDevServer } from \"../shared/utils\";\nimport { cacheDir, serverUrl } from \"@lingo.dev/compiler/virtual/config\";\nimport type { LocaleCode } from \"lingo.dev/spec\";\n\n/**\n * Configuration for translation fetching\n */\nexport interface TranslationFetchConfig {\n /**\n * Base path for translation files (default: process.cwd())\n */\n basePath?: string;\n}\n\n/**\n * Read translations from filesystem\n * Used in production builds or as fallback in development\n *\n * Tries multiple common locations for translation files:\n * - .lingo/cache/{locale}.json (dev cache)\n * - .next/{locale}.json (Next.js)\n *\n * @param locale - Target locale\n * @param basePath - Base directory to search from (default: cwd)\n * @returns Translation dictionary (hash -> translated text)\n */\nasync function readFromFilesystem(\n locale: LocaleCode,\n basePath: string = process.cwd(),\n): Promise<Record<string, string>> {\n // TODO (AleksandrSl 15/12/2025): What should be the correct way here to load translations on server for other frameworks?\n const possiblePaths = [\n join(basePath, cacheDir, `${locale}.json`),\n join(basePath, \".next\", `${locale}.json`),\n ];\n\n // Try each path until we find the file\n for (const filePath of possiblePaths) {\n try {\n const fileContent = await readFile(filePath, \"utf-8\");\n const data = JSON.parse(fileContent);\n const translations = data.entries || {};\n\n logger.debug(\n `Loaded ${Object.keys(translations).length} translations from ${filePath}`,\n );\n return translations;\n } catch {\n // File doesn't exist at this path, try next one\n continue;\n }\n }\n\n // No translations found\n if (process.env.NODE_ENV === \"development\") {\n logger.warn(\n `Translation file not found for locale: ${locale}. Tried: ${possiblePaths.join(\", \")}`,\n );\n }\n\n return {};\n}\n\n/**\n * Fetch translations for a given locale\n *\n * This is the CORE UNIVERSAL function that works across all frameworks.\n * It handles the logic of fetching translations from either:\n * - Development server (if running)\n * - Filesystem (production or fallback)\n *\n * Framework-specific code should NOT duplicate this logic.\n * Instead, they should:\n * 1. Resolve the locale (framework-specific: cookies, URL, headers, etc.)\n * 2. Call this function to get translations\n *\n * @example\n * ```typescript\n * // In Next.js locale resolver\n * const locale = await getLocaleFromCookies();\n * const translations = await fetchTranslations(locale);\n * ```\n *\n * @example\n * ```typescript\n * // In React Router loader\n * const locale = getLocaleFromUrl(request.url);\n * const translations = await fetchTranslations(locale);\n * ```\n */\nexport async function fetchTranslationsOnServer(\n locale: LocaleCode,\n hashes: string[],\n config: TranslationFetchConfig = {},\n): Promise<Record<string, string>> {\n const isDev = process.env.NODE_ENV === \"development\";\n\n // Development mode: Try dev server first, then filesystem\n if (isDev && serverUrl) {\n logger.debug(\n `Server. Fetching translations for ${locale} and ${hashes.join(\", \")} from dev server (${serverUrl})`,\n );\n try {\n return await fetchFromDevServer(locale, hashes, serverUrl);\n } catch (error) {\n logger.warn(\n `Failed to fetch translations from translation server: ${error}.`,\n );\n return {};\n }\n }\n\n logger.debug(`Reading translations for ${locale} from filesystem`);\n return await readFromFilesystem(locale, config.basePath);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,eAAe,mBACb,QACA,WAAmB,QAAQ,KAAK,EACC;CAEjC,MAAM,gBAAgB,CACpB,KAAK,UAAU,UAAU,GAAG,OAAO,OAAO,EAC1C,KAAK,UAAU,SAAS,GAAG,OAAO,OAAO,CAC1C;AAGD,MAAK,MAAM,YAAY,cACrB,KAAI;EACF,MAAM,cAAc,MAAM,SAAS,UAAU,QAAQ;EAErD,MAAM,eADO,KAAK,MAAM,YAAY,CACV,WAAW,EAAE;AAEvC,SAAO,MACL,UAAU,OAAO,KAAK,aAAa,CAAC,OAAO,qBAAqB,WACjE;AACD,SAAO;SACD;AAEN;;AAKJ,KAAI,QAAQ,IAAI,aAAa,cAC3B,QAAO,KACL,0CAA0C,OAAO,WAAW,cAAc,KAAK,KAAK,GACrF;AAGH,QAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BX,eAAsB,0BACpB,QACA,QACA,SAAiC,EAAE,EACF;AAIjC,KAHc,QAAQ,IAAI,aAAa,iBAG1B,WAAW;AACtB,SAAO,MACL,qCAAqC,OAAO,OAAO,OAAO,KAAK,KAAK,CAAC,oBAAoB,UAAU,GACpG;AACD,MAAI;AACF,UAAO,MAAMA,kBAAmB,QAAQ,QAAQ,UAAU;WACnD,OAAO;AACd,UAAO,KACL,yDAAyD,MAAM,GAChE;AACD,UAAO,EAAE;;;AAIb,QAAO,MAAM,4BAA4B,OAAO,kBAAkB;AAClE,QAAO,MAAM,mBAAmB,QAAQ,OAAO,SAAS"}
@@ -0,0 +1,14 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ let react = require("react");
3
+
4
+ //#region src/react/shared/LingoContext.ts
5
+ const LingoContext = (0, react.createContext)(null);
6
+ function useLingoContext() {
7
+ const context = (0, react.useContext)(LingoContext);
8
+ if (!context) throw new Error("useLingoContext must be used within LingoProvider");
9
+ return context;
10
+ }
11
+
12
+ //#endregion
13
+ exports.LingoContext = LingoContext;
14
+ exports.useLingoContext = useLingoContext;
@@ -0,0 +1,41 @@
1
+ import { LocaleCode } from "lingo.dev/spec";
2
+
3
+ //#region src/react/shared/LingoContext.d.ts
4
+ interface LingoContextType {
5
+ /**
6
+ * Source locale (default language)
7
+ */
8
+ sourceLocale: LocaleCode;
9
+ /**
10
+ * Current locale (e.g., 'en', 'de', 'fr')
11
+ */
12
+ locale: LocaleCode;
13
+ /**
14
+ * Change the current locale and dynamically load translations
15
+ */
16
+ setLocale: (locale: LocaleCode) => Promise<void>;
17
+ /**
18
+ * Translation dictionary: hash -> translated text
19
+ */
20
+ translations: Record<string, string>;
21
+ /**
22
+ * Register a hash as being used in a component
23
+ * The provider will automatically request missing translations
24
+ */
25
+ registerHashes: (hashes: string[]) => void;
26
+ /**
27
+ * Whether translations are currently being loaded
28
+ */
29
+ isLoading: boolean;
30
+ /**
31
+ * Development statistics (only in dev mode)
32
+ */
33
+ _devStats?: {
34
+ pendingCount: number;
35
+ totalRegisteredCount: number;
36
+ };
37
+ }
38
+ declare function useLingoContext(): LingoContextType;
39
+ //#endregion
40
+ export { useLingoContext };
41
+ //# sourceMappingURL=LingoContext.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LingoContext.d.cts","names":[],"sources":["../../../src/react/shared/LingoContext.ts"],"sourcesContent":[],"mappings":";;;UAGU,gBAAA;;AAFuC;;EAWvC,YAAA,EALM,UAKN;EAKY;;;EAKA,MAAA,EAVZ,UAUY;EAwBN;;;sBA7BM,eAAe;;;;gBAKrB;;;;;;;;;;;;;;;;;;iBAwBA,eAAA,CAAA,GAAmB"}
@@ -0,0 +1,41 @@
1
+ import { LocaleCode } from "lingo.dev/spec";
2
+
3
+ //#region src/react/shared/LingoContext.d.ts
4
+ interface LingoContextType {
5
+ /**
6
+ * Source locale (default language)
7
+ */
8
+ sourceLocale: LocaleCode;
9
+ /**
10
+ * Current locale (e.g., 'en', 'de', 'fr')
11
+ */
12
+ locale: LocaleCode;
13
+ /**
14
+ * Change the current locale and dynamically load translations
15
+ */
16
+ setLocale: (locale: LocaleCode) => Promise<void>;
17
+ /**
18
+ * Translation dictionary: hash -> translated text
19
+ */
20
+ translations: Record<string, string>;
21
+ /**
22
+ * Register a hash as being used in a component
23
+ * The provider will automatically request missing translations
24
+ */
25
+ registerHashes: (hashes: string[]) => void;
26
+ /**
27
+ * Whether translations are currently being loaded
28
+ */
29
+ isLoading: boolean;
30
+ /**
31
+ * Development statistics (only in dev mode)
32
+ */
33
+ _devStats?: {
34
+ pendingCount: number;
35
+ totalRegisteredCount: number;
36
+ };
37
+ }
38
+ declare function useLingoContext(): LingoContextType;
39
+ //#endregion
40
+ export { useLingoContext };
41
+ //# sourceMappingURL=LingoContext.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LingoContext.d.mts","names":[],"sources":["../../../src/react/shared/LingoContext.ts"],"sourcesContent":[],"mappings":";;;UAGU,gBAAA;;AAFuC;;EAWvC,YAAA,EALM,UAKN;EAKY;;;EAKA,MAAA,EAVZ,UAUY;EAwBN;;;sBA7BM,eAAe;;;;gBAKrB;;;;;;;;;;;;;;;;;;iBAwBA,eAAA,CAAA,GAAmB"}
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from "react";
2
+
3
+ //#region src/react/shared/LingoContext.ts
4
+ const LingoContext = createContext(null);
5
+ function useLingoContext() {
6
+ const context = useContext(LingoContext);
7
+ if (!context) throw new Error("useLingoContext must be used within LingoProvider");
8
+ return context;
9
+ }
10
+
11
+ //#endregion
12
+ export { LingoContext, useLingoContext };
13
+ //# sourceMappingURL=LingoContext.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LingoContext.mjs","names":[],"sources":["../../../src/react/shared/LingoContext.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { LocaleCode } from \"lingo.dev/spec\";\n\ninterface LingoContextType {\n /**\n * Source locale (default language)\n */\n sourceLocale: LocaleCode;\n\n /**\n * Current locale (e.g., 'en', 'de', 'fr')\n */\n locale: LocaleCode;\n\n /**\n * Change the current locale and dynamically load translations\n */\n setLocale: (locale: LocaleCode) => Promise<void>;\n\n /**\n * Translation dictionary: hash -> translated text\n */\n translations: Record<string, string>;\n\n /**\n * Register a hash as being used in a component\n * The provider will automatically request missing translations\n */\n registerHashes: (hashes: string[]) => void;\n\n /**\n * Whether translations are currently being loaded\n */\n isLoading: boolean;\n\n /**\n * Development statistics (only in dev mode)\n */\n _devStats?: {\n pendingCount: number;\n totalRegisteredCount: number;\n };\n}\n\nexport const LingoContext = createContext<LingoContextType | null>(null);\n\nexport function useLingoContext(): LingoContextType {\n const context = useContext(LingoContext);\n\n if (!context) {\n // TODO (AleksandrSl 14/12/2025): Shouldn't throw in production\n throw new Error(\"useLingoContext must be used within LingoProvider\");\n }\n\n return context;\n}\n"],"mappings":";;;AA4CA,MAAa,eAAe,cAAuC,KAAK;AAExE,SAAgB,kBAAoC;CAClD,MAAM,UAAU,WAAW,aAAa;AAExC,KAAI,CAAC,QAEH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,QAAO"}