@weglot/translate-react 0.0.0-stage → 0.2.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 (292) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +6 -0
  3. package/README.md +199 -2
  4. package/build/_virtual/rolldown_runtime.cjs +29 -0
  5. package/build/_virtual/rolldown_runtime.mjs +7 -0
  6. package/build/index.cjs +0 -0
  7. package/build/index.d.cts +2 -0
  8. package/build/index.d.mts +2 -0
  9. package/build/index.mjs +1 -0
  10. package/build/locale.d.cts +6 -0
  11. package/build/locale.d.cts.map +1 -0
  12. package/build/locale.d.mts +6 -0
  13. package/build/locale.d.mts.map +1 -0
  14. package/build/metadata/manager.cjs +119 -0
  15. package/build/metadata/manager.mjs +114 -0
  16. package/build/metadata/manager.mjs.map +1 -0
  17. package/build/plugin/build-translator.cjs +210 -0
  18. package/build/plugin/build-translator.mjs +208 -0
  19. package/build/plugin/build-translator.mjs.map +1 -0
  20. package/build/plugin/cleanup.cjs +20 -0
  21. package/build/plugin/cleanup.mjs +20 -0
  22. package/build/plugin/cleanup.mjs.map +1 -0
  23. package/build/plugin/index.cjs +0 -0
  24. package/build/plugin/index.d.cts +2 -0
  25. package/build/plugin/index.d.mts +2 -0
  26. package/build/plugin/index.mjs +1 -0
  27. package/build/plugin/next-compiler-loader.cjs +40 -0
  28. package/build/plugin/next-compiler-loader.d.cts +12 -0
  29. package/build/plugin/next-compiler-loader.d.cts.map +1 -0
  30. package/build/plugin/next-compiler-loader.d.mts +13 -0
  31. package/build/plugin/next-compiler-loader.d.mts.map +1 -0
  32. package/build/plugin/next-compiler-loader.mjs +41 -0
  33. package/build/plugin/next-compiler-loader.mjs.map +1 -0
  34. package/build/plugin/next-config-loader.cjs +13 -0
  35. package/build/plugin/next-config-loader.d.cts +8 -0
  36. package/build/plugin/next-config-loader.d.cts.map +1 -0
  37. package/build/plugin/next-config-loader.d.mts +9 -0
  38. package/build/plugin/next-config-loader.d.mts.map +1 -0
  39. package/build/plugin/next-config-loader.mjs +14 -0
  40. package/build/plugin/next-config-loader.mjs.map +1 -0
  41. package/build/plugin/next-locale-client-loader.cjs +9 -0
  42. package/build/plugin/next-locale-client-loader.d.cts +8 -0
  43. package/build/plugin/next-locale-client-loader.d.cts.map +1 -0
  44. package/build/plugin/next-locale-client-loader.d.mts +9 -0
  45. package/build/plugin/next-locale-client-loader.d.mts.map +1 -0
  46. package/build/plugin/next-locale-client-loader.mjs +10 -0
  47. package/build/plugin/next-locale-client-loader.mjs.map +1 -0
  48. package/build/plugin/next-locale-server-loader.cjs +9 -0
  49. package/build/plugin/next-locale-server-loader.d.cts +8 -0
  50. package/build/plugin/next-locale-server-loader.d.cts.map +1 -0
  51. package/build/plugin/next-locale-server-loader.d.mts +9 -0
  52. package/build/plugin/next-locale-server-loader.d.mts.map +1 -0
  53. package/build/plugin/next-locale-server-loader.mjs +10 -0
  54. package/build/plugin/next-locale-server-loader.mjs.map +1 -0
  55. package/build/plugin/next.cjs +227 -0
  56. package/build/plugin/next.d.cts +9 -0
  57. package/build/plugin/next.d.cts.map +1 -0
  58. package/build/plugin/next.d.mts +9 -0
  59. package/build/plugin/next.d.mts.map +1 -0
  60. package/build/plugin/next.mjs +229 -0
  61. package/build/plugin/next.mjs.map +1 -0
  62. package/build/plugin/transform/babel-compat.cjs +13 -0
  63. package/build/plugin/transform/babel-compat.mjs +10 -0
  64. package/build/plugin/transform/babel-compat.mjs.map +1 -0
  65. package/build/plugin/transform/expression-strings.cjs +145 -0
  66. package/build/plugin/transform/expression-strings.mjs +140 -0
  67. package/build/plugin/transform/expression-strings.mjs.map +1 -0
  68. package/build/plugin/transform/index.cjs +45 -0
  69. package/build/plugin/transform/index.mjs +43 -0
  70. package/build/plugin/transform/index.mjs.map +1 -0
  71. package/build/plugin/transform/metadata.cjs +142 -0
  72. package/build/plugin/transform/metadata.mjs +141 -0
  73. package/build/plugin/transform/metadata.mjs.map +1 -0
  74. package/build/plugin/transform/process-file.cjs +525 -0
  75. package/build/plugin/transform/process-file.mjs +524 -0
  76. package/build/plugin/transform/process-file.mjs.map +1 -0
  77. package/build/plugin/transform/use-i18n.cjs +8 -0
  78. package/build/plugin/transform/use-i18n.mjs +7 -0
  79. package/build/plugin/transform/use-i18n.mjs.map +1 -0
  80. package/build/plugin/transform/utils.cjs +237 -0
  81. package/build/plugin/transform/utils.mjs +219 -0
  82. package/build/plugin/transform/utils.mjs.map +1 -0
  83. package/build/plugin/unplugin.cjs +188 -0
  84. package/build/plugin/unplugin.d.cts +8 -0
  85. package/build/plugin/unplugin.d.cts.map +1 -0
  86. package/build/plugin/unplugin.d.mts +8 -0
  87. package/build/plugin/unplugin.d.mts.map +1 -0
  88. package/build/plugin/unplugin.mjs +188 -0
  89. package/build/plugin/unplugin.mjs.map +1 -0
  90. package/build/plugin/vite.cjs +27 -0
  91. package/build/plugin/vite.d.cts +9 -0
  92. package/build/plugin/vite.d.cts.map +1 -0
  93. package/build/plugin/vite.d.mts +9 -0
  94. package/build/plugin/vite.d.mts.map +1 -0
  95. package/build/plugin/vite.mjs +28 -0
  96. package/build/plugin/vite.mjs.map +1 -0
  97. package/build/plugin/webpack.cjs +26 -0
  98. package/build/plugin/webpack.d.cts +8 -0
  99. package/build/plugin/webpack.d.cts.map +1 -0
  100. package/build/plugin/webpack.d.mts +8 -0
  101. package/build/plugin/webpack.d.mts.map +1 -0
  102. package/build/plugin/webpack.mjs +27 -0
  103. package/build/plugin/webpack.mjs.map +1 -0
  104. package/build/react/client/index.cjs +9 -0
  105. package/build/react/client/index.d.cts +5 -0
  106. package/build/react/client/index.d.mts +5 -0
  107. package/build/react/client/index.mjs +6 -0
  108. package/build/react/client/useTranslation.cjs +71 -0
  109. package/build/react/client/useTranslation.d.cts +42 -0
  110. package/build/react/client/useTranslation.d.cts.map +1 -0
  111. package/build/react/client/useTranslation.d.mts +42 -0
  112. package/build/react/client/useTranslation.d.mts.map +1 -0
  113. package/build/react/client/useTranslation.mjs +71 -0
  114. package/build/react/client/useTranslation.mjs.map +1 -0
  115. package/build/react/next/client.cjs +25 -0
  116. package/build/react/next/client.d.cts +9 -0
  117. package/build/react/next/client.d.cts.map +1 -0
  118. package/build/react/next/client.d.mts +9 -0
  119. package/build/react/next/client.d.mts.map +1 -0
  120. package/build/react/next/client.mjs +24 -0
  121. package/build/react/next/client.mjs.map +1 -0
  122. package/build/react/next/cookie-locale-resolver.cjs +29 -0
  123. package/build/react/next/cookie-locale-resolver.d.cts +33 -0
  124. package/build/react/next/cookie-locale-resolver.d.cts.map +1 -0
  125. package/build/react/next/cookie-locale-resolver.d.mts +33 -0
  126. package/build/react/next/cookie-locale-resolver.d.mts.map +1 -0
  127. package/build/react/next/cookie-locale-resolver.mjs +29 -0
  128. package/build/react/next/cookie-locale-resolver.mjs.map +1 -0
  129. package/build/react/next/server.cjs +21 -0
  130. package/build/react/next/server.d.cts +13 -0
  131. package/build/react/next/server.d.cts.map +1 -0
  132. package/build/react/next/server.d.mts +14 -0
  133. package/build/react/next/server.d.mts.map +1 -0
  134. package/build/react/next/server.mjs +20 -0
  135. package/build/react/next/server.mjs.map +1 -0
  136. package/build/react/server/ServerWeglotProvider.cjs +19 -0
  137. package/build/react/server/ServerWeglotProvider.d.cts +12 -0
  138. package/build/react/server/ServerWeglotProvider.d.cts.map +1 -0
  139. package/build/react/server/ServerWeglotProvider.d.mts +12 -0
  140. package/build/react/server/ServerWeglotProvider.d.mts.map +1 -0
  141. package/build/react/server/ServerWeglotProvider.mjs +19 -0
  142. package/build/react/server/ServerWeglotProvider.mjs.map +1 -0
  143. package/build/react/server/index.cjs +7 -0
  144. package/build/react/server/index.d.cts +4 -0
  145. package/build/react/server/index.d.mts +4 -0
  146. package/build/react/server/index.mjs +5 -0
  147. package/build/react/server/useTranslation.cjs +60 -0
  148. package/build/react/server/useTranslation.d.cts +36 -0
  149. package/build/react/server/useTranslation.d.cts.map +1 -0
  150. package/build/react/server/useTranslation.d.mts +36 -0
  151. package/build/react/server/useTranslation.d.mts.map +1 -0
  152. package/build/react/server/useTranslation.mjs +60 -0
  153. package/build/react/server/useTranslation.mjs.map +1 -0
  154. package/build/react/server-only/index.cjs +42 -0
  155. package/build/react/server-only/index.d.cts +38 -0
  156. package/build/react/server-only/index.d.cts.map +1 -0
  157. package/build/react/server-only/index.d.mts +38 -0
  158. package/build/react/server-only/index.d.mts.map +1 -0
  159. package/build/react/server-only/index.mjs +42 -0
  160. package/build/react/server-only/index.mjs.map +1 -0
  161. package/build/react/server-only/translations.cjs +86 -0
  162. package/build/react/server-only/translations.mjs +86 -0
  163. package/build/react/server-only/translations.mjs.map +1 -0
  164. package/build/react/shared/LocaleSwitcher.cjs +61 -0
  165. package/build/react/shared/LocaleSwitcher.d.cts +71 -0
  166. package/build/react/shared/LocaleSwitcher.d.cts.map +1 -0
  167. package/build/react/shared/LocaleSwitcher.d.mts +71 -0
  168. package/build/react/shared/LocaleSwitcher.d.mts.map +1 -0
  169. package/build/react/shared/LocaleSwitcher.mjs +61 -0
  170. package/build/react/shared/LocaleSwitcher.mjs.map +1 -0
  171. package/build/react/shared/WeglotContext.cjs +14 -0
  172. package/build/react/shared/WeglotContext.d.cts +34 -0
  173. package/build/react/shared/WeglotContext.d.cts.map +1 -0
  174. package/build/react/shared/WeglotContext.d.mts +34 -0
  175. package/build/react/shared/WeglotContext.d.mts.map +1 -0
  176. package/build/react/shared/WeglotContext.mjs +13 -0
  177. package/build/react/shared/WeglotContext.mjs.map +1 -0
  178. package/build/react/shared/WeglotProvider.cjs +250 -0
  179. package/build/react/shared/WeglotProvider.d.cts +60 -0
  180. package/build/react/shared/WeglotProvider.d.cts.map +1 -0
  181. package/build/react/shared/WeglotProvider.d.mts +60 -0
  182. package/build/react/shared/WeglotProvider.d.mts.map +1 -0
  183. package/build/react/shared/WeglotProvider.mjs +250 -0
  184. package/build/react/shared/WeglotProvider.mjs.map +1 -0
  185. package/build/react/shared/render-rich-text.cjs +56 -0
  186. package/build/react/shared/render-rich-text.d.cts +16 -0
  187. package/build/react/shared/render-rich-text.d.cts.map +1 -0
  188. package/build/react/shared/render-rich-text.d.mts +16 -0
  189. package/build/react/shared/render-rich-text.d.mts.map +1 -0
  190. package/build/react/shared/render-rich-text.mjs +55 -0
  191. package/build/react/shared/render-rich-text.mjs.map +1 -0
  192. package/build/react/shared/utils.cjs +34 -0
  193. package/build/react/shared/utils.mjs +35 -0
  194. package/build/react/shared/utils.mjs.map +1 -0
  195. package/build/react/types.d.cts +16 -0
  196. package/build/react/types.d.cts.map +1 -0
  197. package/build/react/types.d.mts +16 -0
  198. package/build/react/types.d.mts.map +1 -0
  199. package/build/runtime/html/segmenter.cjs +226 -0
  200. package/build/runtime/html/segmenter.mjs +225 -0
  201. package/build/runtime/html/segmenter.mjs.map +1 -0
  202. package/build/runtime/index.cjs +6 -0
  203. package/build/runtime/index.d.cts +2 -0
  204. package/build/runtime/index.d.mts +2 -0
  205. package/build/runtime/index.mjs +3 -0
  206. package/build/runtime/translate-dynamic.cjs +144 -0
  207. package/build/runtime/translate-dynamic.d.cts +29 -0
  208. package/build/runtime/translate-dynamic.d.cts.map +1 -0
  209. package/build/runtime/translate-dynamic.d.mts +29 -0
  210. package/build/runtime/translate-dynamic.d.mts.map +1 -0
  211. package/build/runtime/translate-dynamic.mjs +141 -0
  212. package/build/runtime/translate-dynamic.mjs.map +1 -0
  213. package/build/translation-server/logger.cjs +37 -0
  214. package/build/translation-server/logger.mjs +37 -0
  215. package/build/translation-server/logger.mjs.map +1 -0
  216. package/build/translation-server/translation-server.cjs +451 -0
  217. package/build/translation-server/translation-server.mjs +448 -0
  218. package/build/translation-server/translation-server.mjs.map +1 -0
  219. package/build/translators/api.cjs +12 -0
  220. package/build/translators/api.mjs +12 -0
  221. package/build/translators/api.mjs.map +1 -0
  222. package/build/translators/cache-factory.cjs +26 -0
  223. package/build/translators/cache-factory.mjs +27 -0
  224. package/build/translators/cache-factory.mjs.map +1 -0
  225. package/build/translators/local-cache.cjs +132 -0
  226. package/build/translators/local-cache.mjs +130 -0
  227. package/build/translators/local-cache.mjs.map +1 -0
  228. package/build/translators/translation-service.cjs +139 -0
  229. package/build/translators/translation-service.mjs +140 -0
  230. package/build/translators/translation-service.mjs.map +1 -0
  231. package/build/translators/weglot/api-client.cjs +131 -0
  232. package/build/translators/weglot/api-client.mjs +130 -0
  233. package/build/translators/weglot/api-client.mjs.map +1 -0
  234. package/build/translators/weglot/definitions/definitions.generated.cjs +53 -0
  235. package/build/translators/weglot/definitions/definitions.generated.mjs +52 -0
  236. package/build/translators/weglot/definitions/definitions.generated.mjs.map +1 -0
  237. package/build/translators/weglot/engine.cjs +43 -0
  238. package/build/translators/weglot/engine.mjs +40 -0
  239. package/build/translators/weglot/engine.mjs.map +1 -0
  240. package/build/translators/weglot/translator.cjs +67 -0
  241. package/build/translators/weglot/translator.mjs +68 -0
  242. package/build/translators/weglot/translator.mjs.map +1 -0
  243. package/build/translators/weglot/wire-format.cjs +128 -0
  244. package/build/translators/weglot/wire-format.mjs +129 -0
  245. package/build/translators/weglot/wire-format.mjs.map +1 -0
  246. package/build/types.d.cts +153 -0
  247. package/build/types.d.cts.map +1 -0
  248. package/build/types.d.mts +153 -0
  249. package/build/types.d.mts.map +1 -0
  250. package/build/utils/config-factory.cjs +100 -0
  251. package/build/utils/config-factory.mjs +97 -0
  252. package/build/utils/config-factory.mjs.map +1 -0
  253. package/build/utils/hash.cjs +17 -0
  254. package/build/utils/hash.mjs +16 -0
  255. package/build/utils/hash.mjs.map +1 -0
  256. package/build/utils/is-valid-locale.cjs +13 -0
  257. package/build/utils/is-valid-locale.mjs +13 -0
  258. package/build/utils/is-valid-locale.mjs.map +1 -0
  259. package/build/utils/logger.cjs +51 -0
  260. package/build/utils/logger.mjs +50 -0
  261. package/build/utils/logger.mjs.map +1 -0
  262. package/build/utils/path-helpers.cjs +49 -0
  263. package/build/utils/path-helpers.mjs +47 -0
  264. package/build/utils/path-helpers.mjs.map +1 -0
  265. package/build/utils/timeout.cjs +42 -0
  266. package/build/utils/timeout.mjs +41 -0
  267. package/build/utils/timeout.mjs.map +1 -0
  268. package/build/virtual/code-generator.cjs +58 -0
  269. package/build/virtual/code-generator.mjs +57 -0
  270. package/build/virtual/code-generator.mjs.map +1 -0
  271. package/build/virtual/config.cjs +19 -0
  272. package/build/virtual/config.d.cts +15 -0
  273. package/build/virtual/config.d.cts.map +1 -0
  274. package/build/virtual/config.d.mts +15 -0
  275. package/build/virtual/config.d.mts.map +1 -0
  276. package/build/virtual/config.mjs +14 -0
  277. package/build/virtual/config.mjs.map +1 -0
  278. package/build/virtual/locale/client.cjs +23 -0
  279. package/build/virtual/locale/client.d.cts +19 -0
  280. package/build/virtual/locale/client.d.cts.map +1 -0
  281. package/build/virtual/locale/client.d.mts +19 -0
  282. package/build/virtual/locale/client.d.mts.map +1 -0
  283. package/build/virtual/locale/client.mjs +22 -0
  284. package/build/virtual/locale/client.mjs.map +1 -0
  285. package/build/virtual/locale/server.cjs +13 -0
  286. package/build/virtual/locale/server.d.cts +13 -0
  287. package/build/virtual/locale/server.d.cts.map +1 -0
  288. package/build/virtual/locale/server.d.mts +13 -0
  289. package/build/virtual/locale/server.d.mts.map +1 -0
  290. package/build/virtual/locale/server.mjs +13 -0
  291. package/build/virtual/locale/server.mjs.map +1 -0
  292. package/package.json +260 -4
@@ -0,0 +1,188 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../utils/logger.cjs');
3
+ const require_config_factory = require('../utils/config-factory.cjs');
4
+ const require_translation_service = require('../translators/translation-service.cjs');
5
+ const require_manager = require('../metadata/manager.cjs');
6
+ const require_translation_server = require('../translation-server/translation-server.cjs');
7
+ const require_build_translator = require('./build-translator.cjs');
8
+ const require_cleanup = require('./cleanup.cjs');
9
+ const require_use_i18n = require('./transform/use-i18n.cjs');
10
+ const require_index = require('./transform/index.cjs');
11
+ const require_code_generator = require('../virtual/code-generator.cjs');
12
+ let unplugin = require("unplugin");
13
+
14
+ //#region src/plugin/unplugin.ts
15
+ let translationServer;
16
+ const PLUGIN_NAME = "weglot-translate-react";
17
+ /**
18
+ * Single source of truth for virtual modules
19
+ * Each entry defines both resolver (import path → virtual ID) and loader (virtual ID → code)
20
+ */
21
+ const virtualModules = {
22
+ "@weglot/translate-react/virtual/config": {
23
+ virtualId: "\0virtual:weglot-config",
24
+ loader: (config) => require_code_generator.generateConfigModule(config)
25
+ },
26
+ "@weglot/translate-react/virtual/locale/server": {
27
+ virtualId: "\0virtual:locale-resolver.server",
28
+ loader: (config) => require_code_generator.generateServerLocaleModule(config)
29
+ },
30
+ "@weglot/translate-react/virtual/locale/client": {
31
+ virtualId: "\0virtual:locale-resolver.client",
32
+ loader: (config) => require_code_generator.generateClientLocaleModule(config)
33
+ }
34
+ };
35
+ const virtualModulesResolvers = Object.fromEntries(Object.entries(virtualModules).map(([importPath, module$1]) => [importPath, () => module$1.virtualId]));
36
+ const virtualModulesLoaders = Object.fromEntries(Object.values(virtualModules).map((value) => [value.virtualId, value.loader]));
37
+ /**
38
+ * Universal plugin for @weglot/translate-react
39
+ * Supports Vite, Webpack
40
+ */
41
+ const weglotUnplugin = (0, unplugin.createUnplugin)((options) => {
42
+ const config = require_config_factory.createWeglotConfig(options);
43
+ let languagesResolved;
44
+ const ensureLanguages = () => {
45
+ languagesResolved ??= require_config_factory.resolveProjectLanguages(config).catch((error) => {
46
+ languagesResolved = void 0;
47
+ throw error;
48
+ });
49
+ return languagesResolved;
50
+ };
51
+ const isDev = config.environment === "development";
52
+ config.dev.translationServerStartPort;
53
+ let webpackMode;
54
+ const getMetadataPath$1 = () => {
55
+ return require_manager.getMetadataPath(webpackMode ? {
56
+ ...config,
57
+ environment: webpackMode
58
+ } : config);
59
+ };
60
+ async function startServer() {
61
+ const server = await require_translation_server.startTranslationServer({
62
+ translationService: new require_translation_service.TranslationService(config, require_logger.logger),
63
+ onError: (err) => {
64
+ require_logger.logger.error("Translation server error:", err);
65
+ },
66
+ onReady: (port) => {
67
+ require_logger.logger.info(`Translation server started successfully on port: ${port}`);
68
+ },
69
+ config
70
+ });
71
+ config.dev.translationServerUrl = server.getUrl();
72
+ require_cleanup.registerCleanupOnCurrentProcess({ asyncCleanup: async () => {
73
+ await translationServer.stop();
74
+ } });
75
+ return server;
76
+ }
77
+ return {
78
+ name: PLUGIN_NAME,
79
+ enforce: "pre",
80
+ vite: {
81
+ config() {
82
+ return { optimizeDeps: { exclude: ["@weglot/translate-react"] } };
83
+ },
84
+ async buildStart() {
85
+ await ensureLanguages();
86
+ const metadataFilePath = getMetadataPath$1();
87
+ const environment = isDev ? "development" : "production";
88
+ require_manager.cleanupMetadataForEnvironment(metadataFilePath, environment);
89
+ require_cleanup.registerCleanupOnCurrentProcess({ cleanup: () => require_manager.cleanupMetadataForEnvironment(metadataFilePath, environment) });
90
+ if (isDev && !translationServer) translationServer = await startServer();
91
+ },
92
+ async buildEnd() {
93
+ const metadataFilePath = getMetadataPath$1();
94
+ if (!isDev) try {
95
+ await require_build_translator.processBuildTranslations({
96
+ config,
97
+ publicOutputPath: "public/translations",
98
+ metadataFilePath
99
+ });
100
+ } catch (error) {
101
+ require_logger.logger.error("Build-time translation processing failed:", error);
102
+ }
103
+ }
104
+ },
105
+ webpack(compiler) {
106
+ const environment = compiler.options.mode === "development" ? "development" : "production";
107
+ webpackMode = environment;
108
+ const metadataFilePath = getMetadataPath$1();
109
+ config.environment = webpackMode;
110
+ compiler.hooks.initialize.tap(PLUGIN_NAME, () => {
111
+ require_manager.cleanupMetadataForEnvironment(metadataFilePath, environment);
112
+ require_cleanup.registerCleanupOnCurrentProcess({ cleanup: () => require_manager.cleanupMetadataForEnvironment(metadataFilePath, environment) });
113
+ });
114
+ compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, ensureLanguages);
115
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
116
+ await ensureLanguages();
117
+ if (webpackMode === "development" && !translationServer) translationServer = await startServer();
118
+ });
119
+ compiler.hooks.additionalPass.tapPromise(PLUGIN_NAME, async () => {
120
+ if (webpackMode === "production") try {
121
+ await require_build_translator.processBuildTranslations({
122
+ config,
123
+ publicOutputPath: "public/translations",
124
+ metadataFilePath
125
+ });
126
+ } catch (error) {
127
+ require_logger.logger.error("Build-time translation processing failed:", error);
128
+ throw error;
129
+ }
130
+ });
131
+ compiler.hooks.shutdown.tapPromise(PLUGIN_NAME, async () => {
132
+ require_manager.cleanupMetadataForEnvironment(metadataFilePath, environment);
133
+ await translationServer?.stop();
134
+ });
135
+ },
136
+ resolveId(id) {
137
+ const handler = virtualModulesResolvers[id];
138
+ if (handler) return handler();
139
+ return null;
140
+ },
141
+ load: {
142
+ filter: { id: /virtual:/ },
143
+ handler(id) {
144
+ const handler = virtualModulesLoaders[id];
145
+ if (handler) return handler(config);
146
+ return null;
147
+ }
148
+ },
149
+ transform: {
150
+ filter: {
151
+ id: {
152
+ include: [/\.[tj]sx$/],
153
+ exclude: /node_modules/
154
+ },
155
+ code: config.useDirective ? require_use_i18n.useI18nRegex : void 0
156
+ },
157
+ async handler(code, id) {
158
+ try {
159
+ await ensureLanguages();
160
+ const result = require_index.transformComponent({
161
+ code,
162
+ filePath: id,
163
+ config
164
+ });
165
+ if (!result.transformed) {
166
+ require_logger.logger.debug(`No transformation needed for ${id}`);
167
+ return null;
168
+ }
169
+ if (result.newEntries && result.newEntries.length > 0) {
170
+ await require_manager.saveMetadata(getMetadataPath$1(), result.newEntries, !isDev);
171
+ require_logger.logger.debug(`Found ${result.newEntries.length} translatable text(s) in ${id}`);
172
+ }
173
+ require_logger.logger.debug(`Returning transformed code for ${id}`);
174
+ return {
175
+ code: result.code,
176
+ map: result.map
177
+ };
178
+ } catch (error) {
179
+ require_logger.logger.error(`Transform error in ${id}:`, error);
180
+ return null;
181
+ }
182
+ }
183
+ }
184
+ };
185
+ });
186
+
187
+ //#endregion
188
+ exports.weglotUnplugin = weglotUnplugin;
@@ -0,0 +1,8 @@
1
+ import { PartialWeglotConfig } from "../types.cjs";
2
+ import "unplugin";
3
+
4
+ //#region src/plugin/unplugin.d.ts
5
+ type WeglotPluginOptions = PartialWeglotConfig;
6
+ //#endregion
7
+ export { WeglotPluginOptions };
8
+ //# sourceMappingURL=unplugin.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unplugin.d.cts","names":[],"sources":["../../src/plugin/unplugin.ts"],"sourcesContent":[],"mappings":";;;;KA+BY,mBAAA,GAAsB"}
@@ -0,0 +1,8 @@
1
+ import { PartialWeglotConfig } from "../types.mjs";
2
+ import "unplugin";
3
+
4
+ //#region src/plugin/unplugin.d.ts
5
+ type WeglotPluginOptions = PartialWeglotConfig;
6
+ //#endregion
7
+ export { WeglotPluginOptions };
8
+ //# sourceMappingURL=unplugin.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unplugin.d.mts","names":[],"sources":["../../src/plugin/unplugin.ts"],"sourcesContent":[],"mappings":";;;;KA+BY,mBAAA,GAAsB"}
@@ -0,0 +1,188 @@
1
+ import { logger } from "../utils/logger.mjs";
2
+ import { createWeglotConfig, resolveProjectLanguages } from "../utils/config-factory.mjs";
3
+ import { TranslationService } from "../translators/translation-service.mjs";
4
+ import { cleanupMetadataForEnvironment, getMetadataPath, saveMetadata } from "../metadata/manager.mjs";
5
+ import { startTranslationServer } from "../translation-server/translation-server.mjs";
6
+ import { processBuildTranslations } from "./build-translator.mjs";
7
+ import { registerCleanupOnCurrentProcess } from "./cleanup.mjs";
8
+ import { useI18nRegex } from "./transform/use-i18n.mjs";
9
+ import { transformComponent } from "./transform/index.mjs";
10
+ import { generateClientLocaleModule, generateConfigModule, generateServerLocaleModule } from "../virtual/code-generator.mjs";
11
+ import { createUnplugin } from "unplugin";
12
+
13
+ //#region src/plugin/unplugin.ts
14
+ let translationServer;
15
+ const PLUGIN_NAME = "weglot-translate-react";
16
+ /**
17
+ * Single source of truth for virtual modules
18
+ * Each entry defines both resolver (import path → virtual ID) and loader (virtual ID → code)
19
+ */
20
+ const virtualModules = {
21
+ "@weglot/translate-react/virtual/config": {
22
+ virtualId: "\0virtual:weglot-config",
23
+ loader: (config) => generateConfigModule(config)
24
+ },
25
+ "@weglot/translate-react/virtual/locale/server": {
26
+ virtualId: "\0virtual:locale-resolver.server",
27
+ loader: (config) => generateServerLocaleModule(config)
28
+ },
29
+ "@weglot/translate-react/virtual/locale/client": {
30
+ virtualId: "\0virtual:locale-resolver.client",
31
+ loader: (config) => generateClientLocaleModule(config)
32
+ }
33
+ };
34
+ const virtualModulesResolvers = Object.fromEntries(Object.entries(virtualModules).map(([importPath, module]) => [importPath, () => module.virtualId]));
35
+ const virtualModulesLoaders = Object.fromEntries(Object.values(virtualModules).map((value) => [value.virtualId, value.loader]));
36
+ /**
37
+ * Universal plugin for @weglot/translate-react
38
+ * Supports Vite, Webpack
39
+ */
40
+ const weglotUnplugin = createUnplugin((options) => {
41
+ const config = createWeglotConfig(options);
42
+ let languagesResolved;
43
+ const ensureLanguages = () => {
44
+ languagesResolved ??= resolveProjectLanguages(config).catch((error) => {
45
+ languagesResolved = void 0;
46
+ throw error;
47
+ });
48
+ return languagesResolved;
49
+ };
50
+ const isDev = config.environment === "development";
51
+ config.dev.translationServerStartPort;
52
+ let webpackMode;
53
+ const getMetadataPath$1 = () => {
54
+ return getMetadataPath(webpackMode ? {
55
+ ...config,
56
+ environment: webpackMode
57
+ } : config);
58
+ };
59
+ async function startServer() {
60
+ const server = await startTranslationServer({
61
+ translationService: new TranslationService(config, logger),
62
+ onError: (err) => {
63
+ logger.error("Translation server error:", err);
64
+ },
65
+ onReady: (port) => {
66
+ logger.info(`Translation server started successfully on port: ${port}`);
67
+ },
68
+ config
69
+ });
70
+ config.dev.translationServerUrl = server.getUrl();
71
+ registerCleanupOnCurrentProcess({ asyncCleanup: async () => {
72
+ await translationServer.stop();
73
+ } });
74
+ return server;
75
+ }
76
+ return {
77
+ name: PLUGIN_NAME,
78
+ enforce: "pre",
79
+ vite: {
80
+ config() {
81
+ return { optimizeDeps: { exclude: ["@weglot/translate-react"] } };
82
+ },
83
+ async buildStart() {
84
+ await ensureLanguages();
85
+ const metadataFilePath = getMetadataPath$1();
86
+ const environment = isDev ? "development" : "production";
87
+ cleanupMetadataForEnvironment(metadataFilePath, environment);
88
+ registerCleanupOnCurrentProcess({ cleanup: () => cleanupMetadataForEnvironment(metadataFilePath, environment) });
89
+ if (isDev && !translationServer) translationServer = await startServer();
90
+ },
91
+ async buildEnd() {
92
+ const metadataFilePath = getMetadataPath$1();
93
+ if (!isDev) try {
94
+ await processBuildTranslations({
95
+ config,
96
+ publicOutputPath: "public/translations",
97
+ metadataFilePath
98
+ });
99
+ } catch (error) {
100
+ logger.error("Build-time translation processing failed:", error);
101
+ }
102
+ }
103
+ },
104
+ webpack(compiler) {
105
+ const environment = compiler.options.mode === "development" ? "development" : "production";
106
+ webpackMode = environment;
107
+ const metadataFilePath = getMetadataPath$1();
108
+ config.environment = webpackMode;
109
+ compiler.hooks.initialize.tap(PLUGIN_NAME, () => {
110
+ cleanupMetadataForEnvironment(metadataFilePath, environment);
111
+ registerCleanupOnCurrentProcess({ cleanup: () => cleanupMetadataForEnvironment(metadataFilePath, environment) });
112
+ });
113
+ compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, ensureLanguages);
114
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
115
+ await ensureLanguages();
116
+ if (webpackMode === "development" && !translationServer) translationServer = await startServer();
117
+ });
118
+ compiler.hooks.additionalPass.tapPromise(PLUGIN_NAME, async () => {
119
+ if (webpackMode === "production") try {
120
+ await processBuildTranslations({
121
+ config,
122
+ publicOutputPath: "public/translations",
123
+ metadataFilePath
124
+ });
125
+ } catch (error) {
126
+ logger.error("Build-time translation processing failed:", error);
127
+ throw error;
128
+ }
129
+ });
130
+ compiler.hooks.shutdown.tapPromise(PLUGIN_NAME, async () => {
131
+ cleanupMetadataForEnvironment(metadataFilePath, environment);
132
+ await translationServer?.stop();
133
+ });
134
+ },
135
+ resolveId(id) {
136
+ const handler = virtualModulesResolvers[id];
137
+ if (handler) return handler();
138
+ return null;
139
+ },
140
+ load: {
141
+ filter: { id: /virtual:/ },
142
+ handler(id) {
143
+ const handler = virtualModulesLoaders[id];
144
+ if (handler) return handler(config);
145
+ return null;
146
+ }
147
+ },
148
+ transform: {
149
+ filter: {
150
+ id: {
151
+ include: [/\.[tj]sx$/],
152
+ exclude: /node_modules/
153
+ },
154
+ code: config.useDirective ? useI18nRegex : void 0
155
+ },
156
+ async handler(code, id) {
157
+ try {
158
+ await ensureLanguages();
159
+ const result = transformComponent({
160
+ code,
161
+ filePath: id,
162
+ config
163
+ });
164
+ if (!result.transformed) {
165
+ logger.debug(`No transformation needed for ${id}`);
166
+ return null;
167
+ }
168
+ if (result.newEntries && result.newEntries.length > 0) {
169
+ await saveMetadata(getMetadataPath$1(), result.newEntries, !isDev);
170
+ logger.debug(`Found ${result.newEntries.length} translatable text(s) in ${id}`);
171
+ }
172
+ logger.debug(`Returning transformed code for ${id}`);
173
+ return {
174
+ code: result.code,
175
+ map: result.map
176
+ };
177
+ } catch (error) {
178
+ logger.error(`Transform error in ${id}:`, error);
179
+ return null;
180
+ }
181
+ }
182
+ }
183
+ };
184
+ });
185
+
186
+ //#endregion
187
+ export { weglotUnplugin };
188
+ //# sourceMappingURL=unplugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unplugin.mjs","names":["translationServer: TranslationServer","languagesResolved: Promise<void> | undefined","webpackMode: \"development\" | \"production\" | undefined","getMetadataPath","rawGetMetadataPath"],"sources":["../../src/plugin/unplugin.ts"],"sourcesContent":["import { createUnplugin } from \"unplugin\";\nimport { transformComponent } from \"./transform\";\nimport type {\n WeglotConfig,\n WeglotInternalFields,\n PartialWeglotConfig,\n} from \"../types\";\nimport {\n startTranslationServer,\n type TranslationServer,\n} from \"../translation-server\";\nimport {\n cleanupMetadataForEnvironment,\n getMetadataPath as rawGetMetadataPath,\n saveMetadata,\n} from \"../metadata/manager\";\nimport {\n createWeglotConfig,\n resolveProjectLanguages,\n} from \"../utils/config-factory\";\nimport { logger } from \"../utils/logger\";\nimport { useI18nRegex } from \"./transform/use-i18n\";\nimport {\n generateClientLocaleModule,\n generateConfigModule,\n generateServerLocaleModule,\n} from \"../virtual/code-generator\";\nimport { processBuildTranslations } from \"./build-translator\";\nimport { registerCleanupOnCurrentProcess } from \"./cleanup\";\nimport { TranslationService } from \"../translators\";\n\nexport type WeglotPluginOptions = PartialWeglotConfig;\n\nlet translationServer: TranslationServer;\n\nconst PLUGIN_NAME = \"weglot-translate-react\";\n\n/**\n * Single source of truth for virtual modules\n * Each entry defines both resolver (import path → virtual ID) and loader (virtual ID → code)\n */\nconst virtualModules = {\n \"@weglot/translate-react/virtual/config\": {\n virtualId: \"\\0virtual:weglot-config\",\n loader: (config: WeglotConfig) => generateConfigModule(config),\n },\n \"@weglot/translate-react/virtual/locale/server\": {\n virtualId: \"\\0virtual:locale-resolver.server\" as const,\n loader: (config: WeglotConfig) => generateServerLocaleModule(config),\n },\n \"@weglot/translate-react/virtual/locale/client\": {\n virtualId: \"\\0virtual:locale-resolver.client\" as const,\n loader: (config: WeglotConfig) => generateClientLocaleModule(config),\n },\n} as const;\n\n// Derive resolver and loader maps from the single source\nconst virtualModulesResolvers = Object.fromEntries(\n Object.entries(virtualModules).map(([importPath, module]) => [\n importPath,\n () => module.virtualId,\n ]),\n);\n\nconst virtualModulesLoaders = Object.fromEntries(\n Object.values(virtualModules).map((value) => [value.virtualId, value.loader]),\n);\n\n/**\n * Universal plugin for @weglot/translate-react\n * Supports Vite, Webpack\n */\nexport const weglotUnplugin = createUnplugin<\n WeglotPluginOptions & Partial<Pick<WeglotConfig, WeglotInternalFields>>\n>((options) => {\n const config = createWeglotConfig(options);\n\n let languagesResolved: Promise<void> | undefined;\n const ensureLanguages = () => {\n languagesResolved ??= resolveProjectLanguages(config).catch((error) => {\n languagesResolved = undefined;\n throw error;\n });\n return languagesResolved;\n };\n\n // Won't work for webpack most likely. Use mode there to set correct environment in configs.\n const isDev = config.environment === \"development\";\n const startPort = config.dev.translationServerStartPort;\n\n // For webpack: store the actual mode and use it to compute the correct metadata path\n let webpackMode: \"development\" | \"production\" | undefined;\n // Should be dynamic, because webpack only tells us the mode inside the plugin, not inside the config.\n const getMetadataPath = () => {\n return rawGetMetadataPath(\n webpackMode ? { ...config, environment: webpackMode } : config,\n );\n };\n\n async function startServer() {\n const server = await startTranslationServer({\n translationService: new TranslationService(config, logger),\n onError: (err) => {\n logger.error(\"Translation server error:\", err);\n },\n onReady: (port) => {\n logger.info(`Translation server started successfully on port: ${port}`);\n },\n config,\n });\n // I don't like this quite a lot. But starting server inside the loader seems lame.\n config.dev.translationServerUrl = server.getUrl();\n registerCleanupOnCurrentProcess({\n asyncCleanup: async () => {\n await translationServer.stop();\n },\n });\n return server;\n }\n\n return {\n name: PLUGIN_NAME,\n enforce: \"pre\", // Run before other plugins (especially before React plugin)\n\n vite: {\n // Vite handles deep merge\n config() {\n // Required for custom virtual like modules to be resolved; otherwise they are bundled with raw source code.\n return {\n optimizeDeps: {\n exclude: [\"@weglot/translate-react\"],\n },\n };\n },\n async buildStart() {\n await ensureLanguages();\n\n const metadataFilePath = getMetadataPath();\n\n const environment = isDev ? \"development\" : \"production\";\n cleanupMetadataForEnvironment(metadataFilePath, environment);\n registerCleanupOnCurrentProcess({\n cleanup: () => cleanupMetadataForEnvironment(metadataFilePath, environment),\n });\n\n if (isDev && !translationServer) {\n translationServer = await startServer();\n }\n },\n\n async buildEnd() {\n const metadataFilePath = getMetadataPath();\n if (!isDev) {\n try {\n await processBuildTranslations({\n config,\n publicOutputPath: \"public/translations\",\n metadataFilePath,\n });\n } catch (error) {\n logger.error(\"Build-time translation processing failed:\", error);\n }\n }\n },\n },\n\n webpack(compiler) {\n const environment =\n compiler.options.mode === \"development\" ? \"development\" : \"production\";\n webpackMode = environment;\n const metadataFilePath = getMetadataPath();\n // Yes, this is dirty play, but webpack runs only for this plugin, and this way we save people from using wrong config\n config.environment = webpackMode;\n\n compiler.hooks.initialize.tap(PLUGIN_NAME, () => {\n cleanupMetadataForEnvironment(metadataFilePath, environment);\n registerCleanupOnCurrentProcess({\n cleanup: () => cleanupMetadataForEnvironment(metadataFilePath, environment),\n });\n });\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, ensureLanguages);\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n await ensureLanguages();\n if (webpackMode === \"development\" && !translationServer) {\n translationServer = await startServer();\n }\n });\n\n compiler.hooks.additionalPass.tapPromise(PLUGIN_NAME, async () => {\n if (webpackMode === \"production\") {\n try {\n await processBuildTranslations({\n config,\n publicOutputPath: \"public/translations\",\n metadataFilePath,\n });\n } catch (error) {\n logger.error(\"Build-time translation processing failed:\", error);\n throw error;\n }\n }\n });\n\n // Duplicates the cleanup process handlers does, but won't hurt since cleanup is idempotent.\n compiler.hooks.shutdown.tapPromise(PLUGIN_NAME, async () => {\n cleanupMetadataForEnvironment(metadataFilePath, environment);\n await translationServer?.stop();\n });\n },\n\n resolveId(id) {\n const handler = virtualModulesResolvers[id];\n if (handler) {\n return handler();\n }\n return null;\n },\n\n load: {\n filter: {\n // Without the filter webpack goes mad\n id: /virtual:/,\n },\n handler(id: string) {\n const handler = virtualModulesLoaders[id];\n if (handler) {\n return handler(config);\n }\n return null;\n },\n },\n\n transform: {\n filter: {\n id: {\n include: [/\\.[tj]sx$/],\n exclude: /node_modules/,\n },\n // If useDirective is enabled, only process files with \"use i18n\"\n // This is more efficient than checking in the handler\n code: config.useDirective ? useI18nRegex : undefined,\n },\n async handler(code, id) {\n try {\n // Cheap after the first call; guards loaders that run before\n // buildStart in odd setups.\n await ensureLanguages();\n\n // Transform the component\n const result = transformComponent({\n code,\n filePath: id,\n config,\n });\n\n // If no transformation occurred, return original code\n if (!result.transformed) {\n logger.debug(`No transformation needed for ${id}`);\n return null;\n }\n // Update metadata with new entries (thread-safe)\n if (result.newEntries && result.newEntries.length > 0) {\n await saveMetadata(getMetadataPath(), result.newEntries, !isDev);\n\n logger.debug(\n `Found ${result.newEntries.length} translatable text(s) in ${id}`,\n );\n }\n\n logger.debug(`Returning transformed code for ${id}`);\n return {\n code: result.code,\n map: result.map,\n };\n } catch (error) {\n logger.error(`Transform error in ${id}:`, error);\n return null;\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;;;;;;;;AAiCA,IAAIA;AAEJ,MAAM,cAAc;;;;;AAMpB,MAAM,iBAAiB;CACrB,0CAA0C;EACxC,WAAW;EACX,SAAS,WAAyB,qBAAqB,OAAO;EAC/D;CACD,iDAAiD;EAC/C,WAAW;EACX,SAAS,WAAyB,2BAA2B,OAAO;EACrE;CACD,iDAAiD;EAC/C,WAAW;EACX,SAAS,WAAyB,2BAA2B,OAAO;EACrE;CACF;AAGD,MAAM,0BAA0B,OAAO,YACrC,OAAO,QAAQ,eAAe,CAAC,KAAK,CAAC,YAAY,YAAY,CAC3D,kBACM,OAAO,UACd,CAAC,CACH;AAED,MAAM,wBAAwB,OAAO,YACnC,OAAO,OAAO,eAAe,CAAC,KAAK,UAAU,CAAC,MAAM,WAAW,MAAM,OAAO,CAAC,CAC9E;;;;;AAMD,MAAa,iBAAiB,gBAE3B,YAAY;CACb,MAAM,SAAS,mBAAmB,QAAQ;CAE1C,IAAIC;CACJ,MAAM,wBAAwB;AAC5B,wBAAsB,wBAAwB,OAAO,CAAC,OAAO,UAAU;AACrE,uBAAoB;AACpB,SAAM;IACN;AACF,SAAO;;CAIT,MAAM,QAAQ,OAAO,gBAAgB;AACnB,QAAO,IAAI;CAG7B,IAAIC;CAEJ,MAAMC,0BAAwB;AAC5B,SAAOC,gBACL,cAAc;GAAE,GAAG;GAAQ,aAAa;GAAa,GAAG,OACzD;;CAGH,eAAe,cAAc;EAC3B,MAAM,SAAS,MAAM,uBAAuB;GAC1C,oBAAoB,IAAI,mBAAmB,QAAQ,OAAO;GAC1D,UAAU,QAAQ;AAChB,WAAO,MAAM,6BAA6B,IAAI;;GAEhD,UAAU,SAAS;AACjB,WAAO,KAAK,oDAAoD,OAAO;;GAEzE;GACD,CAAC;AAEF,SAAO,IAAI,uBAAuB,OAAO,QAAQ;AACjD,kCAAgC,EAC9B,cAAc,YAAY;AACxB,SAAM,kBAAkB,MAAM;KAEjC,CAAC;AACF,SAAO;;AAGT,QAAO;EACL,MAAM;EACN,SAAS;EAET,MAAM;GAEJ,SAAS;AAEP,WAAO,EACL,cAAc,EACZ,SAAS,CAAC,0BAA0B,EACrC,EACF;;GAEH,MAAM,aAAa;AACjB,UAAM,iBAAiB;IAEvB,MAAM,mBAAmBD,mBAAiB;IAE1C,MAAM,cAAc,QAAQ,gBAAgB;AAC5C,kCAA8B,kBAAkB,YAAY;AAC5D,oCAAgC,EAC9B,eAAe,8BAA8B,kBAAkB,YAAY,EAC5E,CAAC;AAEF,QAAI,SAAS,CAAC,kBACZ,qBAAoB,MAAM,aAAa;;GAI3C,MAAM,WAAW;IACf,MAAM,mBAAmBA,mBAAiB;AAC1C,QAAI,CAAC,MACH,KAAI;AACF,WAAM,yBAAyB;MAC7B;MACA,kBAAkB;MAClB;MACD,CAAC;aACK,OAAO;AACd,YAAO,MAAM,6CAA6C,MAAM;;;GAIvE;EAED,QAAQ,UAAU;GAChB,MAAM,cACJ,SAAS,QAAQ,SAAS,gBAAgB,gBAAgB;AAC5D,iBAAc;GACd,MAAM,mBAAmBA,mBAAiB;AAE1C,UAAO,cAAc;AAErB,YAAS,MAAM,WAAW,IAAI,mBAAmB;AAC/C,kCAA8B,kBAAkB,YAAY;AAC5D,oCAAgC,EAC9B,eAAe,8BAA8B,kBAAkB,YAAY,EAC5E,CAAC;KACF;AAEF,YAAS,MAAM,UAAU,WAAW,aAAa,gBAAgB;AAEjE,YAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,UAAM,iBAAiB;AACvB,QAAI,gBAAgB,iBAAiB,CAAC,kBACpC,qBAAoB,MAAM,aAAa;KAEzC;AAEF,YAAS,MAAM,eAAe,WAAW,aAAa,YAAY;AAChE,QAAI,gBAAgB,aAClB,KAAI;AACF,WAAM,yBAAyB;MAC7B;MACA,kBAAkB;MAClB;MACD,CAAC;aACK,OAAO;AACd,YAAO,MAAM,6CAA6C,MAAM;AAChE,WAAM;;KAGV;AAGF,YAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,kCAA8B,kBAAkB,YAAY;AAC5D,UAAM,mBAAmB,MAAM;KAC/B;;EAGJ,UAAU,IAAI;GACZ,MAAM,UAAU,wBAAwB;AACxC,OAAI,QACF,QAAO,SAAS;AAElB,UAAO;;EAGT,MAAM;GACJ,QAAQ,EAEN,IAAI,YACL;GACD,QAAQ,IAAY;IAClB,MAAM,UAAU,sBAAsB;AACtC,QAAI,QACF,QAAO,QAAQ,OAAO;AAExB,WAAO;;GAEV;EAED,WAAW;GACT,QAAQ;IACN,IAAI;KACF,SAAS,CAAC,YAAY;KACtB,SAAS;KACV;IAGD,MAAM,OAAO,eAAe,eAAe;IAC5C;GACD,MAAM,QAAQ,MAAM,IAAI;AACtB,QAAI;AAGF,WAAM,iBAAiB;KAGvB,MAAM,SAAS,mBAAmB;MAChC;MACA,UAAU;MACV;MACD,CAAC;AAGF,SAAI,CAAC,OAAO,aAAa;AACvB,aAAO,MAAM,gCAAgC,KAAK;AAClD,aAAO;;AAGT,SAAI,OAAO,cAAc,OAAO,WAAW,SAAS,GAAG;AACrD,YAAM,aAAaA,mBAAiB,EAAE,OAAO,YAAY,CAAC,MAAM;AAEhE,aAAO,MACL,SAAS,OAAO,WAAW,OAAO,2BAA2B,KAC9D;;AAGH,YAAO,MAAM,kCAAkC,KAAK;AACpD,YAAO;MACL,MAAM,OAAO;MACb,KAAK,OAAO;MACb;aACM,OAAO;AACd,YAAO,MAAM,sBAAsB,GAAG,IAAI,MAAM;AAChD,YAAO;;;GAGZ;EACF;EACD"}
@@ -0,0 +1,27 @@
1
+ const require_unplugin = require('./unplugin.cjs');
2
+
3
+ //#region src/plugin/vite.ts
4
+ /**
5
+ * Vite plugin for @weglot/translate-react
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * // vite.config.ts
10
+ * import { defineConfig } from 'vite';
11
+ * import { weglotPlugin } from '@weglot/translate-react/vite';
12
+ *
13
+ * export default defineConfig({
14
+ * plugins: [
15
+ * weglotPlugin({
16
+ * apiKey: 'your_weglot_project_key',
17
+ * }),
18
+ * ],
19
+ * });
20
+ * ```
21
+ */
22
+ function weglotPlugin(options) {
23
+ return require_unplugin.weglotUnplugin.vite(options);
24
+ }
25
+
26
+ //#endregion
27
+ exports.weglotPlugin = weglotPlugin;
@@ -0,0 +1,9 @@
1
+ import { WeglotPluginOptions } from "./unplugin.cjs";
2
+ import * as unplugin0 from "unplugin";
3
+
4
+ //#region src/plugin/vite.d.ts
5
+
6
+ declare function weglotPlugin(options: WeglotPluginOptions): unplugin0.VitePlugin<any> | unplugin0.VitePlugin<any>[];
7
+ //#endregion
8
+ export { type WeglotPluginOptions, weglotPlugin };
9
+ //# sourceMappingURL=vite.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.cts","names":[],"sources":["../../src/plugin/vite.ts"],"sourcesContent":[],"mappings":";;;;;iBAqBgB,YAAA,UAAsB,sBAAmB,SAAA,CAAA,kBAAA,SAAA,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { WeglotPluginOptions } from "./unplugin.mjs";
2
+ import * as unplugin0 from "unplugin";
3
+
4
+ //#region src/plugin/vite.d.ts
5
+
6
+ declare function weglotPlugin(options: WeglotPluginOptions): unplugin0.VitePlugin<any> | unplugin0.VitePlugin<any>[];
7
+ //#endregion
8
+ export { type WeglotPluginOptions, weglotPlugin };
9
+ //# sourceMappingURL=vite.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.mts","names":[],"sources":["../../src/plugin/vite.ts"],"sourcesContent":[],"mappings":";;;;;iBAqBgB,YAAA,UAAsB,sBAAmB,SAAA,CAAA,kBAAA,SAAA,CAAA"}
@@ -0,0 +1,28 @@
1
+ import { weglotUnplugin } from "./unplugin.mjs";
2
+
3
+ //#region src/plugin/vite.ts
4
+ /**
5
+ * Vite plugin for @weglot/translate-react
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * // vite.config.ts
10
+ * import { defineConfig } from 'vite';
11
+ * import { weglotPlugin } from '@weglot/translate-react/vite';
12
+ *
13
+ * export default defineConfig({
14
+ * plugins: [
15
+ * weglotPlugin({
16
+ * apiKey: 'your_weglot_project_key',
17
+ * }),
18
+ * ],
19
+ * });
20
+ * ```
21
+ */
22
+ function weglotPlugin(options) {
23
+ return weglotUnplugin.vite(options);
24
+ }
25
+
26
+ //#endregion
27
+ export { weglotPlugin };
28
+ //# sourceMappingURL=vite.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.mjs","names":[],"sources":["../../src/plugin/vite.ts"],"sourcesContent":["/**\n * Vite plugin for @weglot/translate-react\n *\n * Usage:\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { weglotPlugin } from '@weglot/translate-react/vite';\n *\n * export default defineConfig({\n * plugins: [\n * weglotPlugin({\n * apiKey: 'your_weglot_project_key',\n * }),\n * ],\n * });\n * ```\n */\n\nimport { type WeglotPluginOptions, weglotUnplugin } from \"./unplugin\";\n\nexport function weglotPlugin(options: WeglotPluginOptions) {\n return weglotUnplugin.vite(options);\n}\n\nexport type { WeglotPluginOptions };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,aAAa,SAA8B;AACzD,QAAO,eAAe,KAAK,QAAQ"}
@@ -0,0 +1,26 @@
1
+ const require_unplugin = require('./unplugin.cjs');
2
+
3
+ //#region src/plugin/webpack.ts
4
+ /**
5
+ * Webpack plugin for @weglot/translate-react
6
+ *
7
+ * Usage:
8
+ * ```js
9
+ * // webpack.config.js
10
+ * import { weglotPlugin } from '@weglot/translate-react/webpack';
11
+ *
12
+ * export default {
13
+ * plugins: [
14
+ * weglotPlugin({
15
+ * apiKey: 'your_weglot_project_key',
16
+ * }),
17
+ * ],
18
+ * };
19
+ * ```
20
+ */
21
+ function weglotPlugin(options) {
22
+ return require_unplugin.weglotUnplugin.webpack(options);
23
+ }
24
+
25
+ //#endregion
26
+ exports.weglotPlugin = weglotPlugin;
@@ -0,0 +1,8 @@
1
+ import { WeglotPluginOptions } from "./unplugin.cjs";
2
+
3
+ //#region src/plugin/webpack.d.ts
4
+
5
+ declare function weglotPlugin(options: WeglotPluginOptions): WebpackPluginInstance;
6
+ //#endregion
7
+ export { type WeglotPluginOptions, weglotPlugin };
8
+ //# sourceMappingURL=webpack.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.d.cts","names":[],"sources":["../../src/plugin/webpack.ts"],"sourcesContent":[],"mappings":";;;;iBAoBgB,YAAA,UAAsB,sBAAmB"}
@@ -0,0 +1,8 @@
1
+ import { WeglotPluginOptions } from "./unplugin.mjs";
2
+
3
+ //#region src/plugin/webpack.d.ts
4
+
5
+ declare function weglotPlugin(options: WeglotPluginOptions): WebpackPluginInstance;
6
+ //#endregion
7
+ export { type WeglotPluginOptions, weglotPlugin };
8
+ //# sourceMappingURL=webpack.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.d.mts","names":[],"sources":["../../src/plugin/webpack.ts"],"sourcesContent":[],"mappings":";;;;iBAoBgB,YAAA,UAAsB,sBAAmB"}
@@ -0,0 +1,27 @@
1
+ import { weglotUnplugin } from "./unplugin.mjs";
2
+
3
+ //#region src/plugin/webpack.ts
4
+ /**
5
+ * Webpack plugin for @weglot/translate-react
6
+ *
7
+ * Usage:
8
+ * ```js
9
+ * // webpack.config.js
10
+ * import { weglotPlugin } from '@weglot/translate-react/webpack';
11
+ *
12
+ * export default {
13
+ * plugins: [
14
+ * weglotPlugin({
15
+ * apiKey: 'your_weglot_project_key',
16
+ * }),
17
+ * ],
18
+ * };
19
+ * ```
20
+ */
21
+ function weglotPlugin(options) {
22
+ return weglotUnplugin.webpack(options);
23
+ }
24
+
25
+ //#endregion
26
+ export { weglotPlugin };
27
+ //# sourceMappingURL=webpack.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.mjs","names":[],"sources":["../../src/plugin/webpack.ts"],"sourcesContent":["/**\n * Webpack plugin for @weglot/translate-react\n *\n * Usage:\n * ```js\n * // webpack.config.js\n * import { weglotPlugin } from '@weglot/translate-react/webpack';\n *\n * export default {\n * plugins: [\n * weglotPlugin({\n * apiKey: 'your_weglot_project_key',\n * }),\n * ],\n * };\n * ```\n */\n\nimport { weglotUnplugin, type WeglotPluginOptions } from \"./unplugin\";\n\nexport function weglotPlugin(options: WeglotPluginOptions) {\n return weglotUnplugin.webpack(options);\n}\n\nexport type { WeglotPluginOptions };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,aAAa,SAA8B;AACzD,QAAO,eAAe,QAAQ,QAAQ"}
@@ -0,0 +1,9 @@
1
+ const require_WeglotContext = require('../shared/WeglotContext.cjs');
2
+ const require_WeglotProvider = require('../shared/WeglotProvider.cjs');
3
+ const require_LocaleSwitcher = require('../shared/LocaleSwitcher.cjs');
4
+ const require_useTranslation = require('./useTranslation.cjs');
5
+
6
+ exports.LocaleSwitcher = require_LocaleSwitcher.LocaleSwitcher;
7
+ exports.WeglotProvider = require_WeglotProvider.WeglotProvider;
8
+ exports.useTranslation = require_useTranslation.useTranslation;
9
+ exports.useWeglotContext = require_WeglotContext.useWeglotContext;
@@ -0,0 +1,5 @@
1
+ import { WeglotProvider, WeglotProviderProps } from "../shared/WeglotProvider.cjs";
2
+ import { useWeglotContext } from "../shared/WeglotContext.cjs";
3
+ import { useTranslation } from "./useTranslation.cjs";
4
+ import { LocaleSwitcher } from "../shared/LocaleSwitcher.cjs";
5
+ export { LocaleSwitcher, WeglotProvider, type WeglotProviderProps, useTranslation, useWeglotContext };
@@ -0,0 +1,5 @@
1
+ import { WeglotProvider, WeglotProviderProps } from "../shared/WeglotProvider.mjs";
2
+ import { useWeglotContext } from "../shared/WeglotContext.mjs";
3
+ import { useTranslation } from "./useTranslation.mjs";
4
+ import { LocaleSwitcher } from "../shared/LocaleSwitcher.mjs";
5
+ export { LocaleSwitcher, WeglotProvider, type WeglotProviderProps, useTranslation, useWeglotContext };
@@ -0,0 +1,6 @@
1
+ import { useWeglotContext } from "../shared/WeglotContext.mjs";
2
+ import { WeglotProvider } from "../shared/WeglotProvider.mjs";
3
+ import { LocaleSwitcher } from "../shared/LocaleSwitcher.mjs";
4
+ import { useTranslation } from "./useTranslation.mjs";
5
+
6
+ export { LocaleSwitcher, WeglotProvider, useTranslation, useWeglotContext };