@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
package/LICENSE.md ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024 Lingo.dev
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # @lingo.dev/compiler
2
+
3
+ See the main [README](../../README.md) for general information.
4
+
5
+ Lingo.dev compiler with automatic translation support for React applications.
6
+
7
+ This package provides plugins for multiple bundlers (Vite, Webpack) and Next.js that
8
+ automatically transforms React components to inject translation calls.
9
+
10
+ ## Features
11
+
12
+ - **Automatic JSX text transformation** - Automatically detects and transforms translatable text in JSX
13
+ - **Opt-in or automatic** - Configure whether to require `'use i18n'` directive or transform all files
14
+ - **Multi-bundler support** - Works with Vite, Webpack and Next.js (both Webpack and Turbopack builds)
15
+ - **Translation server** - On-demand translation generation during development
16
+ - **AI-powered translations** - Support for multiple LLM providers and Lingo.dev Engine
17
+
18
+ ## Getting started
19
+
20
+ Install the package - `pnpm install @lingo.dev/compiler`
21
+
22
+ ### Vite
23
+
24
+ - Configure the plugin in your vite config.
25
+
26
+ ```ts
27
+ import { defineConfig } from "vite";
28
+ import { lingoCompilerPlugin } from "@lingo.dev/compiler/vite";
29
+
30
+ export default defineConfig({
31
+ plugins: [
32
+ lingoCompilerPlugin({
33
+ sourceRoot: "src",
34
+ sourceLocale: "en",
35
+ targetLocales: ["es", "de", "fr"],
36
+ models: "lingo.dev",
37
+ dev: {
38
+ usePseudotranslator: true,
39
+ },
40
+ }), // ...other plugins
41
+ ],
42
+ });
43
+ ```
44
+
45
+ - Wrap your app with `LingoProvider`. It should be used as early as possible in your app.
46
+ e.g. in vite example with tanstack-router `LingoProvider` should be above `RouterProvider`, otherwise code-splitting breaks contexts.
47
+ ```tsx
48
+ // Imports and other tanstack router setup
49
+ if (rootElement && !rootElement.innerHTML) {
50
+ const root = ReactDOM.createRoot(rootElement);
51
+ root.render(
52
+ <StrictMode>
53
+ <LingoProvider>
54
+ <RouterProvider router={router} />
55
+ </LingoProvider>
56
+ </StrictMode>,
57
+ );
58
+ }
59
+ ```
60
+
61
+ See `demo/vite-react-spa` for the working example
62
+
63
+ ### Next.js
64
+
65
+ - Use `withLingo` function to wrap your existing next config. You will have to make your config async.
66
+
67
+ ```ts
68
+ import type { NextConfig } from "next";
69
+ import { withLingo } from "@lingo.dev/compiler/next";
70
+
71
+ const nextConfig: NextConfig = {};
72
+
73
+ export default async function (): Promise<NextConfig> {
74
+ return await withLingo(nextConfig, {
75
+ sourceRoot: "./app",
76
+ sourceLocale: "en",
77
+ targetLocales: ["es", "de", "ru"],
78
+ models: "lingo.dev",
79
+ dev: {
80
+ usePseudotranslator: true,
81
+ },
82
+ buildMode: "cache-only",
83
+ });
84
+ }
85
+ ```
86
+
87
+ - Wrap your app with `LingoProvider`. It should be used as early as possible in your app, root `Layout` is a good place.
88
+ ```tsx
89
+ export default function RootLayout({
90
+ children,
91
+ }: Readonly<{ children: React.ReactNode }>) {
92
+ return (
93
+ <LingoProvider>
94
+ <html>
95
+ <body className="antialiased">{children}</body>
96
+ </html>
97
+ </LingoProvider>
98
+ );
99
+ }
100
+ ```
101
+
102
+ ## Development
103
+
104
+ `pnpm install` from project root
105
+ `pnpm turbo dev --filter=@lingo.dev/compile` to compile and watch for compiler changes
106
+
107
+ Choose the demo you want to work with and run it from the corresponding folder.
108
+ `tsdown` in compiler is configured to cleanup the output folder before compilation, which works fine with next, but vite
109
+ seems to be dead every time and has to be restarted.
110
+
111
+ ## Structure
112
+
113
+ The compiler is organized into several key modules:
114
+
115
+ ### Core Directories
116
+
117
+ #### `src/plugin/` - Build-time transformation
118
+
119
+ - **`transform/`** - Babel AST transformation logic for JSX text extraction
120
+ - **`unplugin.ts`** - Universal plugin implementation (Vite, Webpack)
121
+ - **`next.ts`** - Next.js-specific plugin with Turbopack and Webpack support
122
+ - **`build-translator.ts`** - Batch translation generation at build time
123
+ - **`virtual-modules-code-generator.ts`** - Generates code for virtual modules, dev config and locale resolvers for client and server
124
+
125
+ #### `src/metadata/` - Translation metadata management
126
+
127
+ - **`manager.ts`** - CRUD operations for `.lingo/metadata.json`
128
+ - Thread-safe metadata file operations with file locking
129
+ - Manages translation entries with hash-based identifiers
130
+
131
+ #### `src/translators/` - Translation provider abstraction
132
+
133
+ - **`lcp/`** - Lingo.dev Engine integration
134
+ - **`pseudotranslator/`** - Development-mode fake translator
135
+ - **`pluralization/`** - Automatic ICU MessageFormat detection
136
+ - **`translator-factory.ts`** - Provider selection and initialization
137
+
138
+ #### `src/translation-server/` - Development server
139
+
140
+ - **`translation-server.ts`** - HTTP server for on-demand translations
141
+ - **`cli.ts`** - Standalone CLI for translation generation
142
+ - WebSocket support for real-time dev widget updates
143
+ - Port management (60000-60099 range)
144
+
145
+ #### `src/react/` - Runtime translation hooks
146
+
147
+ - **`client/`** - Client-side Context-based hooks
148
+ - **`server/`** - Server component cache-based hooks (isomorphic)
149
+ - **`server-only/`** - Async server-only API (`getServerTranslations`)
150
+ - **`shared/`** - Shared utilities (RichText rendering, Context)
151
+ - **`next/`** - Next.js-specific middleware and locale switcher
152
+
153
+ #### `src/utils/` - Shared utilities
154
+
155
+ - **`hash.ts`** - Stable hash generation for translation keys
156
+ - **`config-factory.ts`** - Configuration defaults and merging
157
+ - **`logger.ts`** - Structured logging utilities
158
+ - **`path-helpers.ts`** - File path resolution
159
+
160
+ #### `src/widget/` - Development widget
161
+
162
+ - In-browser translation editor overlay for development mode
163
+
164
+ ### Support Directories
165
+
166
+ #### `tests/` - End-to-end testing
167
+
168
+ - **`e2e/`** - Playwright tests for full build workflows
169
+ - **`fixtures/`** - Test applications (Vite, Next.js)
170
+ - **`helpers/`** - Test utilities and assertions
171
+
172
+ #### `benchmarks/` - Performance benchmarks
173
+
174
+ - Translation speed benchmarks
175
+ - Metadata I/O performance tests
176
+
177
+ #### `old-docs/` - Legacy documentation
178
+
179
+ - Historical design documents and notes
180
+
181
+ ### Entry Points
182
+
183
+ - **`src/index.ts`** - Main package exports (plugins, types)
184
+ - **`src/types.ts`** - Core TypeScript types
185
+
186
+ ## Contributing
187
+
188
+ This is a beta package under active development. Feedback and contributions are welcome!
189
+
190
+ ## License
191
+
192
+ ISC
@@ -0,0 +1,29 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -0,0 +1,7 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region rolldown:runtime
4
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
+
6
+ //#endregion
7
+ export { __require };
File without changes
@@ -0,0 +1,2 @@
1
+ import { PartialLingoConfig } from "./types.cjs";
2
+ export { type PartialLingoConfig };
@@ -0,0 +1,2 @@
1
+ import { PartialLingoConfig } from "./types.mjs";
2
+ export { type PartialLingoConfig };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,131 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../utils/logger.cjs');
3
+ const require_timeout = require('../utils/timeout.cjs');
4
+ const require_path_helpers = require('../utils/path-helpers.cjs');
5
+ let fs_promises = require("fs/promises");
6
+ fs_promises = require_rolldown_runtime.__toESM(fs_promises);
7
+ let path = require("path");
8
+ path = require_rolldown_runtime.__toESM(path);
9
+ let fs = require("fs");
10
+ fs = require_rolldown_runtime.__toESM(fs);
11
+ let proper_lockfile = require("proper-lockfile");
12
+ proper_lockfile = require_rolldown_runtime.__toESM(proper_lockfile);
13
+
14
+ //#region src/metadata/manager.ts
15
+ function createEmptyMetadata() {
16
+ return {
17
+ entries: {},
18
+ stats: {
19
+ totalEntries: 0,
20
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
21
+ }
22
+ };
23
+ }
24
+ function loadMetadata(path$2) {
25
+ return new MetadataManager(path$2).loadMetadata();
26
+ }
27
+ function cleanupExistingMetadata(metadataFilePath) {
28
+ require_logger.logger.debug(`Attempting to cleanup metadata file: ${metadataFilePath}`);
29
+ try {
30
+ fs.default.unlinkSync(metadataFilePath);
31
+ require_logger.logger.info(`🧹 Cleaned up build metadata file: ${metadataFilePath}`);
32
+ } catch (error) {
33
+ if (error.code === "ENOENT") require_logger.logger.debug(`Metadata file already deleted or doesn't exist: ${metadataFilePath}`);
34
+ else require_logger.logger.warn(`Failed to cleanup metadata file: ${error.message}`);
35
+ }
36
+ }
37
+ /**
38
+ * Get the absolute path to the metadata file
39
+ *
40
+ * @param config - Config with sourceRoot, lingoDir, and environment
41
+ * @returns Absolute path to metadata file
42
+ */
43
+ function getMetadataPath(config) {
44
+ const filename = config.environment === "development" ? "metadata-dev.json" : "metadata-build.json";
45
+ return path.default.join(require_path_helpers.getLingoDir(config), filename);
46
+ }
47
+ var MetadataManager = class {
48
+ constructor(filePath) {
49
+ this.filePath = filePath;
50
+ }
51
+ /**
52
+ * Load metadata from disk
53
+ * Creates empty metadata if file doesn't exist
54
+ * Times out after 15 seconds to prevent indefinite hangs
55
+ */
56
+ async loadMetadata() {
57
+ try {
58
+ const content = await require_timeout.withTimeout(fs_promises.default.readFile(this.filePath, "utf-8"), require_timeout.DEFAULT_TIMEOUTS.METADATA, "Load metadata");
59
+ return JSON.parse(content);
60
+ } catch (error) {
61
+ if (error.code === "ENOENT") return createEmptyMetadata();
62
+ throw error;
63
+ }
64
+ }
65
+ /**
66
+ * Save metadata to disk
67
+ * Times out after 15 seconds to prevent indefinite hangs
68
+ */
69
+ async saveMetadata(metadata) {
70
+ await require_timeout.withTimeout(fs_promises.default.mkdir(path.default.dirname(this.filePath), { recursive: true }), require_timeout.DEFAULT_TIMEOUTS.FILE_IO, "Create metadata directory");
71
+ metadata.stats = {
72
+ totalEntries: Object.keys(metadata.entries).length,
73
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
74
+ };
75
+ const dir = path.default.dirname(this.filePath);
76
+ const base = path.default.basename(this.filePath);
77
+ const tmpPath = path.default.join(dir, `.${base}.tmp-${process.pid}-${Date.now()}`);
78
+ const json = JSON.stringify(metadata, null, 2);
79
+ await require_timeout.withTimeout(fs_promises.default.writeFile(tmpPath, json, "utf-8"), require_timeout.DEFAULT_TIMEOUTS.METADATA, "Save metadata (tmp write)");
80
+ try {
81
+ await require_timeout.withTimeout(fs_promises.default.rename(tmpPath, this.filePath), require_timeout.DEFAULT_TIMEOUTS.METADATA, "Save metadata (atomic rename)");
82
+ } catch (error) {
83
+ if (error && typeof error === "object" && "code" in error && error.code === "EPERM") {
84
+ await require_timeout.withTimeout(fs_promises.default.writeFile(this.filePath, json, "utf-8"), require_timeout.DEFAULT_TIMEOUTS.METADATA, "Save metadata (EPERM fallback direct write)");
85
+ return;
86
+ }
87
+ throw error;
88
+ } finally {
89
+ await fs_promises.default.unlink(tmpPath).catch(() => {});
90
+ }
91
+ }
92
+ /**
93
+ * Thread-safe save operation that atomically updates metadata with new entries
94
+ * Uses file locking to prevent concurrent write corruption
95
+ *
96
+ * @param entries - Translation entries to add/update
97
+ * @returns The updated metadata schema
98
+ */
99
+ async saveMetadataWithEntries(entries) {
100
+ const lockDir = path.default.dirname(this.filePath);
101
+ await fs_promises.default.mkdir(lockDir, { recursive: true });
102
+ try {
103
+ await fs_promises.default.access(this.filePath);
104
+ } catch {
105
+ await fs_promises.default.writeFile(this.filePath, JSON.stringify(createEmptyMetadata(), null, 2), "utf-8");
106
+ }
107
+ const release = await proper_lockfile.default.lock(this.filePath, {
108
+ retries: {
109
+ retries: 10,
110
+ minTimeout: 50,
111
+ maxTimeout: 1e3
112
+ },
113
+ stale: 2e3
114
+ });
115
+ try {
116
+ const currentMetadata = await this.loadMetadata();
117
+ for (const entry of entries) currentMetadata.entries[entry.hash] = entry;
118
+ await this.saveMetadata(currentMetadata);
119
+ return currentMetadata;
120
+ } finally {
121
+ await release();
122
+ }
123
+ }
124
+ };
125
+
126
+ //#endregion
127
+ exports.MetadataManager = MetadataManager;
128
+ exports.cleanupExistingMetadata = cleanupExistingMetadata;
129
+ exports.createEmptyMetadata = createEmptyMetadata;
130
+ exports.getMetadataPath = getMetadataPath;
131
+ exports.loadMetadata = loadMetadata;