@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,12 @@
1
+ //#region src/plugin/next-compiler-loader.d.ts
2
+ /**
3
+ * Turbopack/Webpack loader for automatic translation
4
+ *
5
+ * This loader transforms React components to inject translation calls automatically.
6
+ *
7
+ * For production builds, translations are generated after compilation completes
8
+ * via Next.js's runAfterProductionCompile hook (see next.ts plugin).
9
+ */
10
+ declare function nextCompilerLoader(this: any, source: string): Promise<void>;
11
+ export = nextCompilerLoader;
12
+ //# sourceMappingURL=next-compiler-loader.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-compiler-loader.d.cts","names":[],"sources":["../../src/plugin/next-compiler-loader.ts"],"sourcesContent":[],"mappings":";;;;;;;;;iBAa8B,kBAAA,6BAG3B"}
@@ -0,0 +1,13 @@
1
+ //#region src/plugin/next-compiler-loader.d.ts
2
+ /**
3
+ * Turbopack/Webpack loader for automatic translation
4
+ *
5
+ * This loader transforms React components to inject translation calls automatically.
6
+ *
7
+ * For production builds, translations are generated after compilation completes
8
+ * via Next.js's runAfterProductionCompile hook (see next.ts plugin).
9
+ */
10
+ declare function nextCompilerLoader(this: any, source: string): Promise<void>;
11
+ //#endregion
12
+ export { nextCompilerLoader as default };
13
+ //# sourceMappingURL=next-compiler-loader.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-compiler-loader.d.mts","names":[],"sources":["../../src/plugin/next-compiler-loader.ts"],"sourcesContent":[],"mappings":";;;;;;;;;iBAa8B,kBAAA,6BAG3B"}
@@ -0,0 +1,42 @@
1
+ import { logger } from "../utils/logger.mjs";
2
+ import { MetadataManager } from "../metadata/manager.mjs";
3
+ import { transformComponent } from "./transform/index.mjs";
4
+
5
+ //#region src/plugin/next-compiler-loader.ts
6
+ /**
7
+ * Turbopack/Webpack loader for automatic translation
8
+ *
9
+ * This loader transforms React components to inject translation calls automatically.
10
+ *
11
+ * For production builds, translations are generated after compilation completes
12
+ * via Next.js's runAfterProductionCompile hook (see next.ts plugin).
13
+ */
14
+ async function nextCompilerLoader(source) {
15
+ if (typeof this.async !== "function") throw new Error("This module must be run as a loader");
16
+ const callback = this.async();
17
+ try {
18
+ const config = this.getOptions();
19
+ const metadataManager = new MetadataManager(config.metadataFilePath);
20
+ logger.debug(`[Turbopack Loader] Processing: ${this.resourcePath}`);
21
+ const result = transformComponent({
22
+ code: source,
23
+ filePath: this.resourcePath,
24
+ config
25
+ });
26
+ if (!result.transformed) return callback(null, source);
27
+ if (result.newEntries && result.newEntries.length > 0) {
28
+ await metadataManager.saveMetadataWithEntries(result.newEntries);
29
+ logger.debug(`[Turbopack Loader] Found ${result.newEntries.length} translatable text(s) in ${this.resourcePath}`);
30
+ }
31
+ const validMap = result.map && result.map.sources && Array.isArray(result.map.sources) && result.map.sources.every((s) => typeof s === "string") ? result.map : void 0;
32
+ callback(null, result.code, validMap);
33
+ } catch (error) {
34
+ logger.error(`Compiler failed for ${this.resourcePath}:`);
35
+ logger.error("Details:", error, typeof error === "object" && error && "message" in error ? error.message : error, error instanceof Error ? error.stack : void 0);
36
+ callback(error);
37
+ }
38
+ }
39
+
40
+ //#endregion
41
+ export { nextCompilerLoader as default };
42
+ //# sourceMappingURL=next-compiler-loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-compiler-loader.mjs","names":["config: LingoConfig & { metadataFilePath: string }"],"sources":["../../src/plugin/next-compiler-loader.ts"],"sourcesContent":["import type { LingoConfig } from \"../types\";\nimport { transformComponent } from \"./transform\";\nimport { logger } from \"../utils/logger\";\nimport { MetadataManager } from \"../metadata/manager\";\n\n/**\n * Turbopack/Webpack loader for automatic translation\n *\n * This loader transforms React components to inject translation calls automatically.\n *\n * For production builds, translations are generated after compilation completes\n * via Next.js's runAfterProductionCompile hook (see next.ts plugin).\n */\nexport default async function nextCompilerLoader(\n this: any,\n source: string,\n): Promise<void> {\n // TODO (AleksandrSl 14/12/2025): Webpack doesn't like callback usage in async function.\n // But async function can return only code, so we have to use promises which is sad. It actually errors only when we catch an error, so it's not an urgent problem\n\n // Ensure we're running in loader context\n if (typeof this.async !== \"function\") {\n throw new Error(\"This module must be run as a loader\");\n }\n const callback = this.async();\n\n try {\n const config: LingoConfig & { metadataFilePath: string } =\n this.getOptions();\n\n const metadataManager = new MetadataManager(config.metadataFilePath);\n\n logger.debug(`[Turbopack Loader] Processing: ${this.resourcePath}`);\n\n // Transform the component\n const result = transformComponent({\n code: source,\n filePath: this.resourcePath,\n config,\n });\n\n // If no transformation occurred, return original source\n if (!result.transformed) {\n return callback(null, source);\n }\n\n // Update metadata with new entries\n if (result.newEntries && result.newEntries.length > 0) {\n await metadataManager.saveMetadataWithEntries(result.newEntries);\n\n logger.debug(\n `[Turbopack Loader] Found ${result.newEntries.length} translatable text(s) in ${this.resourcePath}`,\n );\n }\n\n // Validate source map before passing to webpack\n // Webpack crashes if sources array contains undefined values\n const validMap =\n result.map &&\n result.map.sources &&\n Array.isArray(result.map.sources) &&\n result.map.sources.every((s: any) => typeof s === \"string\")\n ? result.map\n : undefined;\n\n callback(null, result.code, validMap);\n } catch (error) {\n logger.error(`Compiler failed for ${this.resourcePath}:`);\n logger.error(\n \"Details:\",\n error,\n typeof error === \"object\" && error && \"message\" in error\n ? error.message\n : error,\n error instanceof Error ? error.stack : undefined,\n );\n callback(error as Error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,eAA8B,mBAE5B,QACe;AAKf,KAAI,OAAO,KAAK,UAAU,WACxB,OAAM,IAAI,MAAM,sCAAsC;CAExD,MAAM,WAAW,KAAK,OAAO;AAE7B,KAAI;EACF,MAAMA,SACJ,KAAK,YAAY;EAEnB,MAAM,kBAAkB,IAAI,gBAAgB,OAAO,iBAAiB;AAEpE,SAAO,MAAM,kCAAkC,KAAK,eAAe;EAGnE,MAAM,SAAS,mBAAmB;GAChC,MAAM;GACN,UAAU,KAAK;GACf;GACD,CAAC;AAGF,MAAI,CAAC,OAAO,YACV,QAAO,SAAS,MAAM,OAAO;AAI/B,MAAI,OAAO,cAAc,OAAO,WAAW,SAAS,GAAG;AACrD,SAAM,gBAAgB,wBAAwB,OAAO,WAAW;AAEhE,UAAO,MACL,4BAA4B,OAAO,WAAW,OAAO,2BAA2B,KAAK,eACtF;;EAKH,MAAM,WACJ,OAAO,OACP,OAAO,IAAI,WACX,MAAM,QAAQ,OAAO,IAAI,QAAQ,IACjC,OAAO,IAAI,QAAQ,OAAO,MAAW,OAAO,MAAM,SAAS,GACvD,OAAO,MACP;AAEN,WAAS,MAAM,OAAO,MAAM,SAAS;UAC9B,OAAO;AACd,SAAO,MAAM,uBAAuB,KAAK,aAAa,GAAG;AACzD,SAAO,MACL,YACA,OACA,OAAO,UAAU,YAAY,SAAS,aAAa,QAC/C,MAAM,UACN,OACJ,iBAAiB,QAAQ,MAAM,QAAQ,OACxC;AACD,WAAS,MAAe"}
@@ -0,0 +1,13 @@
1
+ const require_code_generator = require('../virtual/code-generator.cjs');
2
+
3
+ //#region src/plugin/next-config-loader.ts
4
+ /**
5
+ * Loader for config module
6
+ * Generates full module code - ignores source file (template is only for types)
7
+ */
8
+ function nextConfigLoader(_source) {
9
+ return require_code_generator.generateConfigModule(this.getOptions());
10
+ }
11
+
12
+ //#endregion
13
+ module.exports = nextConfigLoader;
@@ -0,0 +1,8 @@
1
+ //#region src/plugin/next-config-loader.d.ts
2
+ /**
3
+ * Loader for config module
4
+ * Generates full module code - ignores source file (template is only for types)
5
+ */
6
+ declare function nextConfigLoader(this: any, _source: string): string;
7
+ export = nextConfigLoader;
8
+ //# sourceMappingURL=next-config-loader.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-config-loader.d.cts","names":[],"sources":["../../src/plugin/next-config-loader.ts"],"sourcesContent":[],"mappings":";;;;;iBAOwB,gBAAA"}
@@ -0,0 +1,9 @@
1
+ //#region src/plugin/next-config-loader.d.ts
2
+ /**
3
+ * Loader for config module
4
+ * Generates full module code - ignores source file (template is only for types)
5
+ */
6
+ declare function nextConfigLoader(this: any, _source: string): string;
7
+ //#endregion
8
+ export { nextConfigLoader as default };
9
+ //# sourceMappingURL=next-config-loader.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-config-loader.d.mts","names":[],"sources":["../../src/plugin/next-config-loader.ts"],"sourcesContent":[],"mappings":";;;;;iBAOwB,gBAAA"}
@@ -0,0 +1,14 @@
1
+ import { generateConfigModule } from "../virtual/code-generator.mjs";
2
+
3
+ //#region src/plugin/next-config-loader.ts
4
+ /**
5
+ * Loader for config module
6
+ * Generates full module code - ignores source file (template is only for types)
7
+ */
8
+ function nextConfigLoader(_source) {
9
+ return generateConfigModule(this.getOptions());
10
+ }
11
+
12
+ //#endregion
13
+ export { nextConfigLoader as default };
14
+ //# sourceMappingURL=next-config-loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-config-loader.mjs","names":[],"sources":["../../src/plugin/next-config-loader.ts"],"sourcesContent":["import type { LingoConfig } from \"../types\";\nimport { generateConfigModule } from \"../virtual/code-generator\";\n\n/**\n * Loader for config module\n * Generates full module code - ignores source file (template is only for types)\n */\nexport default function nextConfigLoader(this: any, _source: string): string {\n const config: LingoConfig = this.getOptions();\n return generateConfigModule(config);\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,iBAA4B,SAAyB;AAE3E,QAAO,qBADqB,KAAK,YAAY,CACV"}
@@ -0,0 +1,9 @@
1
+ const require_code_generator = require('../virtual/code-generator.cjs');
2
+
3
+ //#region src/plugin/next-locale-client-loader.ts
4
+ function nextLocaleClientLoader(_source) {
5
+ return require_code_generator.generateClientLocaleModule(this.getOptions());
6
+ }
7
+
8
+ //#endregion
9
+ module.exports = nextLocaleClientLoader;
@@ -0,0 +1,8 @@
1
+ //#region src/plugin/next-locale-client-loader.d.ts
2
+ /**
3
+ * Loader for locale/client module
4
+ * Generates full module code - ignores source file (template is only for types)
5
+ */
6
+ declare function nextLocaleClientLoader(this: any, _source: string): string;
7
+ export = nextLocaleClientLoader;
8
+ //# sourceMappingURL=next-locale-client-loader.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-locale-client-loader.d.cts","names":[],"sources":["../../src/plugin/next-locale-client-loader.ts"],"sourcesContent":[],"mappings":";;;;;iBAQwB,sBAAA"}
@@ -0,0 +1,9 @@
1
+ //#region src/plugin/next-locale-client-loader.d.ts
2
+ /**
3
+ * Loader for locale/client module
4
+ * Generates full module code - ignores source file (template is only for types)
5
+ */
6
+ declare function nextLocaleClientLoader(this: any, _source: string): string;
7
+ //#endregion
8
+ export { nextLocaleClientLoader as default };
9
+ //# sourceMappingURL=next-locale-client-loader.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-locale-client-loader.d.mts","names":[],"sources":["../../src/plugin/next-locale-client-loader.ts"],"sourcesContent":[],"mappings":";;;;;iBAQwB,sBAAA"}
@@ -0,0 +1,10 @@
1
+ import { generateClientLocaleModule } from "../virtual/code-generator.mjs";
2
+
3
+ //#region src/plugin/next-locale-client-loader.ts
4
+ function nextLocaleClientLoader(_source) {
5
+ return generateClientLocaleModule(this.getOptions());
6
+ }
7
+
8
+ //#endregion
9
+ export { nextLocaleClientLoader as default };
10
+ //# sourceMappingURL=next-locale-client-loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-locale-client-loader.mjs","names":[],"sources":["../../src/plugin/next-locale-client-loader.ts"],"sourcesContent":["/**\n * Loader for locale/client module\n * Generates full module code - ignores source file (template is only for types)\n */\n\nimport type { LingoConfig } from \"../types\";\nimport { generateClientLocaleModule } from \"../virtual/code-generator\";\n\nexport default function nextLocaleClientLoader(\n this: any,\n _source: string,\n): string {\n const config: LingoConfig = this.getOptions();\n return generateClientLocaleModule(config);\n}\n"],"mappings":";;;AAQA,SAAwB,uBAEtB,SACQ;AAER,QAAO,2BADqB,KAAK,YAAY,CACJ"}
@@ -0,0 +1,9 @@
1
+ const require_code_generator = require('../virtual/code-generator.cjs');
2
+
3
+ //#region src/plugin/next-locale-server-loader.ts
4
+ function nextLocaleServerLoader(_source) {
5
+ return require_code_generator.generateServerLocaleModule(this.getOptions());
6
+ }
7
+
8
+ //#endregion
9
+ module.exports = nextLocaleServerLoader;
@@ -0,0 +1,8 @@
1
+ //#region src/plugin/next-locale-server-loader.d.ts
2
+ /**
3
+ * Loader for locale/server module
4
+ * Generates full module code - ignores source file (template is only for types)
5
+ */
6
+ declare function nextLocaleServerLoader(this: any, _source: string): string;
7
+ export = nextLocaleServerLoader;
8
+ //# sourceMappingURL=next-locale-server-loader.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-locale-server-loader.d.cts","names":[],"sources":["../../src/plugin/next-locale-server-loader.ts"],"sourcesContent":[],"mappings":";;;;;iBAQwB,sBAAA"}
@@ -0,0 +1,9 @@
1
+ //#region src/plugin/next-locale-server-loader.d.ts
2
+ /**
3
+ * Loader for locale/server module
4
+ * Generates full module code - ignores source file (template is only for types)
5
+ */
6
+ declare function nextLocaleServerLoader(this: any, _source: string): string;
7
+ //#endregion
8
+ export { nextLocaleServerLoader as default };
9
+ //# sourceMappingURL=next-locale-server-loader.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-locale-server-loader.d.mts","names":[],"sources":["../../src/plugin/next-locale-server-loader.ts"],"sourcesContent":[],"mappings":";;;;;iBAQwB,sBAAA"}
@@ -0,0 +1,10 @@
1
+ import { generateServerLocaleModule } from "../virtual/code-generator.mjs";
2
+
3
+ //#region src/plugin/next-locale-server-loader.ts
4
+ function nextLocaleServerLoader(_source) {
5
+ return generateServerLocaleModule(this.getOptions());
6
+ }
7
+
8
+ //#endregion
9
+ export { nextLocaleServerLoader as default };
10
+ //# sourceMappingURL=next-locale-server-loader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-locale-server-loader.mjs","names":[],"sources":["../../src/plugin/next-locale-server-loader.ts"],"sourcesContent":["/**\n * Loader for locale/server module\n * Generates full module code - ignores source file (template is only for types)\n */\n\nimport type { LingoConfig } from \"../types\";\nimport { generateServerLocaleModule } from \"../virtual/code-generator\";\n\nexport default function nextLocaleServerLoader(\n this: any,\n _source: string,\n): string {\n const config: LingoConfig = this.getOptions();\n return generateServerLocaleModule(config);\n}\n"],"mappings":";;;AAQA,SAAwB,uBAEtB,SACQ;AAER,QAAO,2BADqB,KAAK,YAAY,CACJ"}
@@ -0,0 +1,220 @@
1
+ const require_logger = require('../utils/logger.cjs');
2
+ const require_config_factory = require('../utils/config-factory.cjs');
3
+ const require_manager = require('../metadata/manager.cjs');
4
+ const require_translation_server = require('../translation-server/translation-server.cjs');
5
+ const require_build_translator = require('./build-translator.cjs');
6
+ const require_cleanup = require('./cleanup.cjs');
7
+ const require_use_i18n = require('./transform/use-i18n.cjs');
8
+
9
+ //#region src/plugin/next.ts
10
+ function loaders({ lingoConfig, metadataFilePath, translationServerUrl }) {
11
+ const common = {
12
+ sourceRoot: lingoConfig.sourceRoot,
13
+ lingoDir: lingoConfig.lingoDir,
14
+ sourceLocale: lingoConfig.sourceLocale
15
+ };
16
+ const compilerLoader = {
17
+ loader: "@lingo.dev/compiler/next-compiler-loader",
18
+ options: {
19
+ ...common,
20
+ useDirective: lingoConfig.useDirective,
21
+ metadataFilePath
22
+ }
23
+ };
24
+ const configLoader = {
25
+ loader: "@lingo.dev/compiler/next-config-loader",
26
+ options: {
27
+ ...common,
28
+ dev: {
29
+ translationServerUrl,
30
+ ...lingoConfig.dev
31
+ }
32
+ }
33
+ };
34
+ const localeServerLoader = {
35
+ loader: "@lingo.dev/compiler/next-locale-server-loader",
36
+ options: {
37
+ ...common,
38
+ localePersistence: lingoConfig.localePersistence
39
+ }
40
+ };
41
+ const localeClientLoader = {
42
+ loader: "@lingo.dev/compiler/next-locale-client-loader",
43
+ options: {
44
+ ...common,
45
+ localePersistence: lingoConfig.localePersistence
46
+ }
47
+ };
48
+ return {
49
+ compiler: {
50
+ turbopack: {
51
+ pattern: "*.{tsx,jsx}",
52
+ config: {
53
+ condition: { content: lingoConfig.useDirective ? require_use_i18n.useI18nRegex : void 0 },
54
+ loaders: [compilerLoader]
55
+ }
56
+ },
57
+ webpack: {
58
+ enforce: "pre",
59
+ test: /\.(tsx|jsx)$/i,
60
+ exclude: /node_modules/,
61
+ use: [compilerLoader]
62
+ }
63
+ },
64
+ devConfig: translationServerUrl ? {
65
+ turbopack: {
66
+ pattern: "**/virtual/config.mjs",
67
+ config: { loaders: [configLoader] }
68
+ },
69
+ webpack: {
70
+ enforce: "pre",
71
+ test: /virtual\/config\.mjs$/i,
72
+ use: [configLoader]
73
+ }
74
+ } : {},
75
+ localeServer: {
76
+ turbopack: {
77
+ pattern: "**/virtual/locale/server.mjs",
78
+ config: { loaders: [localeServerLoader] }
79
+ },
80
+ webpack: {
81
+ enforce: "pre",
82
+ test: /virtual\/locale[\\/]server\.mjs$/i,
83
+ use: [localeServerLoader]
84
+ }
85
+ },
86
+ localeClient: {
87
+ turbopack: {
88
+ pattern: "**/virtual/locale/client.mjs",
89
+ config: { loaders: [localeClientLoader] }
90
+ },
91
+ webpack: {
92
+ enforce: "pre",
93
+ test: /virtual\/locale[\\/]client\.mjs$/i,
94
+ use: [localeClientLoader]
95
+ }
96
+ }
97
+ };
98
+ }
99
+ /**
100
+ * Check if Next.js supports stable turbopack config (Next.js 16+)
101
+ */
102
+ function hasStableTurboConfig() {
103
+ try {
104
+ const nextPackage = require("next/package.json");
105
+ return parseInt(nextPackage.version.split(".")[0], 10) >= 16;
106
+ } catch {
107
+ return false;
108
+ }
109
+ }
110
+ function getTurbopackConfig(userConfig) {
111
+ return (hasStableTurboConfig() ? userConfig?.turbopack?.rules : userConfig?.experimental?.turbo) || {};
112
+ }
113
+ /**
114
+ * Merge Turbopack rules without mutating original
115
+ */
116
+ function mergeTurbopackRules(existingRules, newRules) {
117
+ const mergedRules = { ...existingRules };
118
+ for (const newRule of newRules) {
119
+ if (!newRule) continue;
120
+ const { pattern, config } = newRule;
121
+ if (mergedRules[pattern]) if (Array.isArray(mergedRules[pattern])) mergedRules[pattern] = [...mergedRules[pattern], config];
122
+ else mergedRules[pattern] = [mergedRules[pattern], config];
123
+ else mergedRules[pattern] = config;
124
+ }
125
+ return mergedRules;
126
+ }
127
+ function isMainRunner() {
128
+ return !process.env.NEXT_PRIVATE_BUILD_WORKER && !process.env.IS_NEXT_WORKER && !process.env.NEXT_PRIVATE_WORKER;
129
+ }
130
+ async function withLingo(nextConfig = {}, lingoOptions) {
131
+ const lingoConfig = require_config_factory.createLingoConfig(lingoOptions);
132
+ let metadataFilePath = require_manager.getMetadataPath(lingoConfig);
133
+ const isDev = lingoConfig.environment === "development";
134
+ require_logger.logger.debug(`Initializing Lingo.dev compiler. Is dev mode: ${isDev}. Is main runner: ${isMainRunner()}`);
135
+ if (isDev && !process.env.LINGO_TRANSLATION_SERVER_URL) {
136
+ const translationServer = await require_translation_server.startOrGetTranslationServer({
137
+ startPort: lingoConfig.dev.translationServerStartPort,
138
+ onError: (err) => {
139
+ require_logger.logger.error("Translation server error:", err);
140
+ },
141
+ onReady: (port) => {
142
+ require_logger.logger.info(`Translation server started successfully on port: ${port}`);
143
+ },
144
+ config: lingoConfig
145
+ });
146
+ process.env.LINGO_TRANSLATION_SERVER_URL = translationServer.url;
147
+ if (translationServer.server) require_cleanup.registerCleanupOnCurrentProcess({ asyncCleanup: async () => {
148
+ await translationServer.server.stop();
149
+ } });
150
+ }
151
+ const translationServerUrl = process.env.LINGO_TRANSLATION_SERVER_URL;
152
+ if (isMainRunner()) {
153
+ require_manager.cleanupExistingMetadata(metadataFilePath);
154
+ require_cleanup.registerCleanupOnCurrentProcess({ cleanup: () => {
155
+ require_manager.cleanupExistingMetadata(metadataFilePath);
156
+ } });
157
+ }
158
+ const existingTurbopackConfig = getTurbopackConfig(nextConfig);
159
+ let mergedRules = mergeTurbopackRules(existingTurbopackConfig.rules ?? {}, Object.values(loaders({
160
+ lingoConfig,
161
+ metadataFilePath,
162
+ translationServerUrl
163
+ })).map((rules) => rules.turbopack));
164
+ const mergedResolveAlias = { ...existingTurbopackConfig.resolveAlias };
165
+ let turbopackConfig;
166
+ if (hasStableTurboConfig()) turbopackConfig = { turbopack: {
167
+ ...nextConfig.turbopack,
168
+ rules: mergedRules,
169
+ resolveAlias: mergedResolveAlias
170
+ } };
171
+ else turbopackConfig = { experimental: {
172
+ ...nextConfig.experimental,
173
+ turbo: {
174
+ ...nextConfig.experimental?.turbo,
175
+ rules: mergedRules,
176
+ resolveAlias: mergedResolveAlias
177
+ }
178
+ } };
179
+ const runAfterProductionCompile = async ({ distDir, projectDir }) => {
180
+ if (typeof nextConfig.compiler?.runAfterProductionCompile === "function") await nextConfig.compiler.runAfterProductionCompile({
181
+ distDir,
182
+ projectDir
183
+ });
184
+ require_logger.logger.info("Running post-build translation generation...");
185
+ require_logger.logger.info(`Build mode: Using metadata file: ${metadataFilePath}`);
186
+ try {
187
+ await require_build_translator.processBuildTranslations({
188
+ config: lingoConfig,
189
+ publicOutputPath: distDir,
190
+ metadataFilePath
191
+ });
192
+ } catch (error) {
193
+ require_logger.logger.error("Translation generation failed:", error);
194
+ throw error;
195
+ }
196
+ };
197
+ const webpack = (config, options) => {
198
+ let modifiedConfig = config;
199
+ if (typeof nextConfig.webpack === "function") modifiedConfig = nextConfig.webpack(config, options);
200
+ const lingoRules = Object.values(loaders({
201
+ lingoConfig,
202
+ metadataFilePath,
203
+ translationServerUrl
204
+ })).map((rules) => rules.webpack).filter(Boolean);
205
+ modifiedConfig.module.rules.unshift(...lingoRules);
206
+ return modifiedConfig;
207
+ };
208
+ return {
209
+ ...nextConfig,
210
+ ...turbopackConfig,
211
+ compiler: {
212
+ ...nextConfig.compiler,
213
+ runAfterProductionCompile
214
+ },
215
+ webpack
216
+ };
217
+ }
218
+
219
+ //#endregion
220
+ exports.withLingo = withLingo;
@@ -0,0 +1,9 @@
1
+ import { PartialLingoConfig } from "../types.cjs";
2
+ import { NextConfig } from "next";
3
+
4
+ //#region src/plugin/next.d.ts
5
+ type LingoNextPluginOptions = PartialLingoConfig;
6
+ declare function withLingo(nextConfig: NextConfig | undefined, lingoOptions: LingoNextPluginOptions): Promise<NextConfig>;
7
+ //#endregion
8
+ export { LingoNextPluginOptions, withLingo };
9
+ //# sourceMappingURL=next.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.d.cts","names":[],"sources":["../../src/plugin/next.ts"],"sourcesContent":[],"mappings":";;;;KAeY,sBAAA,GAAyB;iBAoLf,SAAA,aACR,sCACE,yBACb,QAAQ"}
@@ -0,0 +1,9 @@
1
+ import { PartialLingoConfig } from "../types.mjs";
2
+ import { NextConfig } from "next";
3
+
4
+ //#region src/plugin/next.d.ts
5
+ type LingoNextPluginOptions = PartialLingoConfig;
6
+ declare function withLingo(nextConfig: NextConfig | undefined, lingoOptions: LingoNextPluginOptions): Promise<NextConfig>;
7
+ //#endregion
8
+ export { LingoNextPluginOptions, withLingo };
9
+ //# sourceMappingURL=next.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.d.mts","names":[],"sources":["../../src/plugin/next.ts"],"sourcesContent":[],"mappings":";;;;KAeY,sBAAA,GAAyB;iBAoLf,SAAA,aACR,sCACE,yBACb,QAAQ"}