@weglot/translate-react 0.0.0-stage → 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 (292) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +6 -0
  3. package/README.md +190 -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 +207 -0
  18. package/build/plugin/build-translator.mjs +205 -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 +226 -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 +228 -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 +142 -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 +139 -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 +137 -0
  229. package/build/translators/translation-service.mjs +138 -0
  230. package/build/translators/translation-service.mjs.map +1 -0
  231. package/build/translators/weglot/api-client.cjs +79 -0
  232. package/build/translators/weglot/api-client.mjs +79 -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 +46 -0
  238. package/build/translators/weglot/engine.mjs +43 -0
  239. package/build/translators/weglot/engine.mjs.map +1 -0
  240. package/build/translators/weglot/translator.cjs +61 -0
  241. package/build/translators/weglot/translator.mjs +62 -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 +143 -0
  247. package/build/types.d.cts.map +1 -0
  248. package/build/types.d.mts +143 -0
  249. package/build/types.d.mts.map +1 -0
  250. package/build/utils/config-factory.cjs +86 -0
  251. package/build/utils/config-factory.mjs +83 -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 +56 -0
  269. package/build/virtual/code-generator.mjs +55 -0
  270. package/build/virtual/code-generator.mjs.map +1 -0
  271. package/build/virtual/config.cjs +16 -0
  272. package/build/virtual/config.d.cts +13 -0
  273. package/build/virtual/config.d.cts.map +1 -0
  274. package/build/virtual/config.d.mts +13 -0
  275. package/build/virtual/config.d.mts.map +1 -0
  276. package/build/virtual/config.mjs +12 -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,13 @@
1
+
2
+ //#region src/utils/is-valid-locale.ts
3
+ const LOCALE_REGEX = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/i;
4
+ function isValidLocale(locale) {
5
+ return LOCALE_REGEX.test(locale);
6
+ }
7
+ function parseLocaleOrThrow(locale) {
8
+ if (locale && isValidLocale(locale)) return locale;
9
+ else throw new Error(`Invalid locale: ${locale}`);
10
+ }
11
+
12
+ //#endregion
13
+ exports.parseLocaleOrThrow = parseLocaleOrThrow;
@@ -0,0 +1,13 @@
1
+ //#region src/utils/is-valid-locale.ts
2
+ const LOCALE_REGEX = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/i;
3
+ function isValidLocale(locale) {
4
+ return LOCALE_REGEX.test(locale);
5
+ }
6
+ function parseLocaleOrThrow(locale) {
7
+ if (locale && isValidLocale(locale)) return locale;
8
+ else throw new Error(`Invalid locale: ${locale}`);
9
+ }
10
+
11
+ //#endregion
12
+ export { parseLocaleOrThrow };
13
+ //# sourceMappingURL=is-valid-locale.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-valid-locale.mjs","names":[],"sources":["../../src/utils/is-valid-locale.ts"],"sourcesContent":["import type { LocaleCode } from \"../locale\";\n\nconst LOCALE_REGEX = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/i;\n\nexport function isValidLocale(locale: string): locale is LocaleCode {\n return LOCALE_REGEX.test(locale);\n}\n\nexport function parseLocale(\n locale: string | undefined,\n): LocaleCode | undefined {\n return locale && isValidLocale(locale) ? locale : undefined;\n}\n\nexport function parseLocaleOrThrow(locale: string | undefined): LocaleCode {\n if (locale && isValidLocale(locale)) {\n return locale;\n } else {\n throw new Error(`Invalid locale: ${locale}`);\n }\n}\n"],"mappings":";AAEA,MAAM,eAAe;AAErB,SAAgB,cAAc,QAAsC;AAClE,QAAO,aAAa,KAAK,OAAO;;AASlC,SAAgB,mBAAmB,QAAwC;AACzE,KAAI,UAAU,cAAc,OAAO,CACjC,QAAO;KAEP,OAAM,IAAI,MAAM,mBAAmB,SAAS"}
@@ -0,0 +1,51 @@
1
+
2
+ //#region src/utils/logger.ts
3
+ var Logger = class {
4
+ config;
5
+ prefix = "\x1B[42m\x1B[30m[Weglot]\x1B[0m";
6
+ constructor(config = {}) {
7
+ this.config = {
8
+ enableDebug: config.enableDebug ?? (typeof process !== "undefined" && process.env?.WEGLOT_DEBUG === "true"),
9
+ enableConsole: config.enableConsole ?? true,
10
+ writeToFile: config.writeToFile
11
+ };
12
+ }
13
+ setDebug(enabled) {
14
+ this.config.enableDebug = enabled;
15
+ }
16
+ setConsoleEnabled(enabled) {
17
+ this.config.enableConsole = enabled;
18
+ }
19
+ /**
20
+ * Set a custom file writer function
21
+ * This allows server-side code to inject file writing without importing fs
22
+ */
23
+ setFileWriter(writer) {
24
+ this.config.writeToFile = writer;
25
+ }
26
+ formatMessage(...args) {
27
+ return args.map((arg) => typeof arg === "object" ? JSON.stringify(arg, null, 2) : String(arg)).join(" ");
28
+ }
29
+ log(level, ...args) {
30
+ const message = this.formatMessage(...args);
31
+ if (this.config.enableConsole) (level === "debug" || level === "info" ? console.log : console[level])(this.prefix, message);
32
+ if (this.config.writeToFile) this.config.writeToFile(level, message);
33
+ }
34
+ debug(...args) {
35
+ if (this.config.enableDebug) this.log("debug", ...args);
36
+ }
37
+ info(...args) {
38
+ this.log("info", ...args);
39
+ }
40
+ warn(...args) {
41
+ this.log("warn", ...args);
42
+ }
43
+ error(...args) {
44
+ this.log("error", ...args);
45
+ }
46
+ };
47
+ const logger = new Logger({ enableConsole: true });
48
+
49
+ //#endregion
50
+ exports.Logger = Logger;
51
+ exports.logger = logger;
@@ -0,0 +1,50 @@
1
+ //#region src/utils/logger.ts
2
+ var Logger = class {
3
+ config;
4
+ prefix = "\x1B[42m\x1B[30m[Weglot]\x1B[0m";
5
+ constructor(config = {}) {
6
+ this.config = {
7
+ enableDebug: config.enableDebug ?? (typeof process !== "undefined" && process.env?.WEGLOT_DEBUG === "true"),
8
+ enableConsole: config.enableConsole ?? true,
9
+ writeToFile: config.writeToFile
10
+ };
11
+ }
12
+ setDebug(enabled) {
13
+ this.config.enableDebug = enabled;
14
+ }
15
+ setConsoleEnabled(enabled) {
16
+ this.config.enableConsole = enabled;
17
+ }
18
+ /**
19
+ * Set a custom file writer function
20
+ * This allows server-side code to inject file writing without importing fs
21
+ */
22
+ setFileWriter(writer) {
23
+ this.config.writeToFile = writer;
24
+ }
25
+ formatMessage(...args) {
26
+ return args.map((arg) => typeof arg === "object" ? JSON.stringify(arg, null, 2) : String(arg)).join(" ");
27
+ }
28
+ log(level, ...args) {
29
+ const message = this.formatMessage(...args);
30
+ if (this.config.enableConsole) (level === "debug" || level === "info" ? console.log : console[level])(this.prefix, message);
31
+ if (this.config.writeToFile) this.config.writeToFile(level, message);
32
+ }
33
+ debug(...args) {
34
+ if (this.config.enableDebug) this.log("debug", ...args);
35
+ }
36
+ info(...args) {
37
+ this.log("info", ...args);
38
+ }
39
+ warn(...args) {
40
+ this.log("warn", ...args);
41
+ }
42
+ error(...args) {
43
+ this.log("error", ...args);
44
+ }
45
+ };
46
+ const logger = new Logger({ enableConsole: true });
47
+
48
+ //#endregion
49
+ export { Logger, logger };
50
+ //# sourceMappingURL=logger.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.mjs","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":["export type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\ninterface LoggerConfig {\n enableDebug: boolean;\n enableConsole?: boolean;\n writeToFile?: (level: LogLevel, message: string) => void;\n}\n\nexport class Logger {\n private config: LoggerConfig;\n private readonly prefix = \"\\x1b[42m\\x1b[30m[Weglot]\\x1b[0m\";\n\n constructor(config: Partial<LoggerConfig> = {}) {\n this.config = {\n enableDebug:\n config.enableDebug ??\n (typeof process !== \"undefined\" &&\n process.env?.WEGLOT_DEBUG === \"true\"),\n enableConsole: config.enableConsole ?? true,\n writeToFile: config.writeToFile,\n };\n }\n\n setDebug(enabled: boolean) {\n this.config.enableDebug = enabled;\n }\n\n setConsoleEnabled(enabled: boolean) {\n this.config.enableConsole = enabled;\n }\n\n /**\n * Set a custom file writer function\n * This allows server-side code to inject file writing without importing fs\n */\n setFileWriter(writer: (level: LogLevel, message: string) => void) {\n this.config.writeToFile = writer;\n }\n\n private formatMessage(...args: any[]): string {\n return args\n .map((arg) =>\n typeof arg === \"object\" ? JSON.stringify(arg, null, 2) : String(arg),\n )\n .join(\" \");\n }\n\n private log(level: LogLevel, ...args: any[]) {\n const message = this.formatMessage(...args);\n\n // Console output\n if (this.config.enableConsole) {\n const consoleMethod =\n level === \"debug\" || level === \"info\" ? console.log : console[level];\n consoleMethod(this.prefix, message);\n }\n\n // File output (if configured)\n if (this.config.writeToFile) {\n this.config.writeToFile(level, message);\n }\n }\n\n debug(...args: any[]) {\n if (this.config.enableDebug) {\n this.log(\"debug\", ...args);\n }\n }\n\n info(...args: any[]) {\n this.log(\"info\", ...args);\n }\n\n warn(...args: any[]) {\n this.log(\"warn\", ...args);\n }\n\n error(...args: any[]) {\n this.log(\"error\", ...args);\n }\n}\n\nexport const logger = new Logger({\n enableConsole: true,\n});\n"],"mappings":";AAQA,IAAa,SAAb,MAAoB;CAClB,AAAQ;CACR,AAAiB,SAAS;CAE1B,YAAY,SAAgC,EAAE,EAAE;AAC9C,OAAK,SAAS;GACZ,aACE,OAAO,gBACN,OAAO,YAAY,eAClB,QAAQ,KAAK,iBAAiB;GAClC,eAAe,OAAO,iBAAiB;GACvC,aAAa,OAAO;GACrB;;CAGH,SAAS,SAAkB;AACzB,OAAK,OAAO,cAAc;;CAG5B,kBAAkB,SAAkB;AAClC,OAAK,OAAO,gBAAgB;;;;;;CAO9B,cAAc,QAAoD;AAChE,OAAK,OAAO,cAAc;;CAG5B,AAAQ,cAAc,GAAG,MAAqB;AAC5C,SAAO,KACJ,KAAK,QACJ,OAAO,QAAQ,WAAW,KAAK,UAAU,KAAK,MAAM,EAAE,GAAG,OAAO,IAAI,CACrE,CACA,KAAK,IAAI;;CAGd,AAAQ,IAAI,OAAiB,GAAG,MAAa;EAC3C,MAAM,UAAU,KAAK,cAAc,GAAG,KAAK;AAG3C,MAAI,KAAK,OAAO,cAGd,EADE,UAAU,WAAW,UAAU,SAAS,QAAQ,MAAM,QAAQ,QAClD,KAAK,QAAQ,QAAQ;AAIrC,MAAI,KAAK,OAAO,YACd,MAAK,OAAO,YAAY,OAAO,QAAQ;;CAI3C,MAAM,GAAG,MAAa;AACpB,MAAI,KAAK,OAAO,YACd,MAAK,IAAI,SAAS,GAAG,KAAK;;CAI9B,KAAK,GAAG,MAAa;AACnB,OAAK,IAAI,QAAQ,GAAG,KAAK;;CAG3B,KAAK,GAAG,MAAa;AACnB,OAAK,IAAI,QAAQ,GAAG,KAAK;;CAG3B,MAAM,GAAG,MAAa;AACpB,OAAK,IAAI,SAAS,GAAG,KAAK;;;AAI9B,MAAa,SAAS,IAAI,OAAO,EAC/B,eAAe,MAChB,CAAC"}
@@ -0,0 +1,49 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let path = require("path");
3
+ path = require_rolldown_runtime.__toESM(path);
4
+
5
+ //#region src/utils/path-helpers.ts
6
+ /**
7
+ * Path resolution utilities
8
+ * Centralize path construction logic to eliminate duplication
9
+ */
10
+ /**
11
+ * Resolve a path to absolute, using cwd as base if relative
12
+ *
13
+ * @param configPath - Path from config (may be relative or absolute)
14
+ * @param basePath - Base path to resolve against (defaults to cwd)
15
+ * @returns Absolute path
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * resolveAbsolutePath("src") // -> "/full/path/to/cwd/src"
20
+ * resolveAbsolutePath("/abs/path") // -> "/abs/path"
21
+ * ```
22
+ */
23
+ function resolveAbsolutePath(configPath, basePath = process.cwd()) {
24
+ return path.default.isAbsolute(configPath) ? configPath : path.default.join(basePath, configPath);
25
+ }
26
+ /**
27
+ * Get the absolute path to the weglot directory
28
+ *
29
+ * @param config - Config with sourceRoot and weglotDir
30
+ * @returns Absolute path to weglot directory
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * getWeglotDir({ sourceRoot: "src", weglotDir: "weglot" })
35
+ * // -> "/full/path/to/src/weglot"
36
+ * ```
37
+ */
38
+ function getWeglotDir(config) {
39
+ const rootPath = resolveAbsolutePath(config.sourceRoot);
40
+ return path.default.join(rootPath, config.weglotDir);
41
+ }
42
+ function getCacheDir(config) {
43
+ const weglotDir = getWeglotDir(config);
44
+ return path.default.join(weglotDir, "cache");
45
+ }
46
+
47
+ //#endregion
48
+ exports.getCacheDir = getCacheDir;
49
+ exports.getWeglotDir = getWeglotDir;
@@ -0,0 +1,47 @@
1
+ import path from "path";
2
+
3
+ //#region src/utils/path-helpers.ts
4
+ /**
5
+ * Path resolution utilities
6
+ * Centralize path construction logic to eliminate duplication
7
+ */
8
+ /**
9
+ * Resolve a path to absolute, using cwd as base if relative
10
+ *
11
+ * @param configPath - Path from config (may be relative or absolute)
12
+ * @param basePath - Base path to resolve against (defaults to cwd)
13
+ * @returns Absolute path
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * resolveAbsolutePath("src") // -> "/full/path/to/cwd/src"
18
+ * resolveAbsolutePath("/abs/path") // -> "/abs/path"
19
+ * ```
20
+ */
21
+ function resolveAbsolutePath(configPath, basePath = process.cwd()) {
22
+ return path.isAbsolute(configPath) ? configPath : path.join(basePath, configPath);
23
+ }
24
+ /**
25
+ * Get the absolute path to the weglot directory
26
+ *
27
+ * @param config - Config with sourceRoot and weglotDir
28
+ * @returns Absolute path to weglot directory
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * getWeglotDir({ sourceRoot: "src", weglotDir: "weglot" })
33
+ * // -> "/full/path/to/src/weglot"
34
+ * ```
35
+ */
36
+ function getWeglotDir(config) {
37
+ const rootPath = resolveAbsolutePath(config.sourceRoot);
38
+ return path.join(rootPath, config.weglotDir);
39
+ }
40
+ function getCacheDir(config) {
41
+ const weglotDir = getWeglotDir(config);
42
+ return path.join(weglotDir, "cache");
43
+ }
44
+
45
+ //#endregion
46
+ export { getCacheDir, getWeglotDir };
47
+ //# sourceMappingURL=path-helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-helpers.mjs","names":[],"sources":["../../src/utils/path-helpers.ts"],"sourcesContent":["/**\n * Path resolution utilities\n * Centralize path construction logic to eliminate duplication\n */\n\nimport path from \"path\";\nimport type { PathConfig } from \"../types\";\n\n/**\n * Resolve a path to absolute, using cwd as base if relative\n *\n * @param configPath - Path from config (may be relative or absolute)\n * @param basePath - Base path to resolve against (defaults to cwd)\n * @returns Absolute path\n *\n * @example\n * ```typescript\n * resolveAbsolutePath(\"src\") // -> \"/full/path/to/cwd/src\"\n * resolveAbsolutePath(\"/abs/path\") // -> \"/abs/path\"\n * ```\n */\nexport function resolveAbsolutePath(\n configPath: string,\n basePath: string = process.cwd(),\n): string {\n return path.isAbsolute(configPath)\n ? configPath\n : path.join(basePath, configPath);\n}\n\n/**\n * Get the absolute path to the weglot directory\n *\n * @param config - Config with sourceRoot and weglotDir\n * @returns Absolute path to weglot directory\n *\n * @example\n * ```typescript\n * getWeglotDir({ sourceRoot: \"src\", weglotDir: \"weglot\" })\n * // -> \"/full/path/to/src/weglot\"\n * ```\n */\nexport function getWeglotDir(config: PathConfig): string {\n const rootPath = resolveAbsolutePath(config.sourceRoot);\n return path.join(rootPath, config.weglotDir);\n}\n\nexport function getCacheDir(config: PathConfig): string {\n const weglotDir = getWeglotDir(config);\n return path.join(weglotDir, \"cache\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,oBACd,YACA,WAAmB,QAAQ,KAAK,EACxB;AACR,QAAO,KAAK,WAAW,WAAW,GAC9B,aACA,KAAK,KAAK,UAAU,WAAW;;;;;;;;;;;;;;AAerC,SAAgB,aAAa,QAA4B;CACvD,MAAM,WAAW,oBAAoB,OAAO,WAAW;AACvD,QAAO,KAAK,KAAK,UAAU,OAAO,UAAU;;AAG9C,SAAgB,YAAY,QAA4B;CACtD,MAAM,YAAY,aAAa,OAAO;AACtC,QAAO,KAAK,KAAK,WAAW,QAAQ"}
@@ -0,0 +1,42 @@
1
+
2
+ //#region src/utils/timeout.ts
3
+ /**
4
+ * Timeout utilities for preventing operations from hanging indefinitely
5
+ */
6
+ /**
7
+ * Wrap a promise with a timeout
8
+ * If the promise doesn't resolve/reject within the timeout, it will reject with a TimeoutError
9
+ *
10
+ * @param promise - The promise to wrap
11
+ * @param timeoutMs - Timeout in milliseconds
12
+ * @param operationName - Name of the operation for error messages
13
+ * @returns Promise that resolves/rejects with timeout protection
14
+ */
15
+ function withTimeout(promise, timeoutMs, operationName = "Operation") {
16
+ return Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new TimeoutError(`${operationName} timed out after ${timeoutMs}ms`, timeoutMs)), timeoutMs))]);
17
+ }
18
+ /**
19
+ * Custom error for timeout operations
20
+ */
21
+ var TimeoutError = class extends Error {
22
+ constructor(message, timeoutMs) {
23
+ super(message);
24
+ this.timeoutMs = timeoutMs;
25
+ this.name = "TimeoutError";
26
+ }
27
+ };
28
+ /**
29
+ * Default timeout values (in milliseconds)
30
+ */
31
+ const DEFAULT_TIMEOUTS = {
32
+ FILE_IO: 1e4,
33
+ METADATA: 15e3,
34
+ AI_API: 6e4,
35
+ HTTP_REQUEST: 3e4,
36
+ SERVER_START: 3e4,
37
+ TRANSLATION: 12e4
38
+ };
39
+
40
+ //#endregion
41
+ exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS;
42
+ exports.withTimeout = withTimeout;
@@ -0,0 +1,41 @@
1
+ //#region src/utils/timeout.ts
2
+ /**
3
+ * Timeout utilities for preventing operations from hanging indefinitely
4
+ */
5
+ /**
6
+ * Wrap a promise with a timeout
7
+ * If the promise doesn't resolve/reject within the timeout, it will reject with a TimeoutError
8
+ *
9
+ * @param promise - The promise to wrap
10
+ * @param timeoutMs - Timeout in milliseconds
11
+ * @param operationName - Name of the operation for error messages
12
+ * @returns Promise that resolves/rejects with timeout protection
13
+ */
14
+ function withTimeout(promise, timeoutMs, operationName = "Operation") {
15
+ return Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new TimeoutError(`${operationName} timed out after ${timeoutMs}ms`, timeoutMs)), timeoutMs))]);
16
+ }
17
+ /**
18
+ * Custom error for timeout operations
19
+ */
20
+ var TimeoutError = class extends Error {
21
+ constructor(message, timeoutMs) {
22
+ super(message);
23
+ this.timeoutMs = timeoutMs;
24
+ this.name = "TimeoutError";
25
+ }
26
+ };
27
+ /**
28
+ * Default timeout values (in milliseconds)
29
+ */
30
+ const DEFAULT_TIMEOUTS = {
31
+ FILE_IO: 1e4,
32
+ METADATA: 15e3,
33
+ AI_API: 6e4,
34
+ HTTP_REQUEST: 3e4,
35
+ SERVER_START: 3e4,
36
+ TRANSLATION: 12e4
37
+ };
38
+
39
+ //#endregion
40
+ export { DEFAULT_TIMEOUTS, withTimeout };
41
+ //# sourceMappingURL=timeout.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.mjs","names":["timeoutMs: number"],"sources":["../../src/utils/timeout.ts"],"sourcesContent":["/**\n * Timeout utilities for preventing operations from hanging indefinitely\n */\n\n/**\n * Wrap a promise with a timeout\n * If the promise doesn't resolve/reject within the timeout, it will reject with a TimeoutError\n *\n * @param promise - The promise to wrap\n * @param timeoutMs - Timeout in milliseconds\n * @param operationName - Name of the operation for error messages\n * @returns Promise that resolves/rejects with timeout protection\n */\nexport function withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n operationName: string = \"Operation\",\n): Promise<T> {\n return Promise.race([\n promise,\n new Promise<T>((_, reject) =>\n setTimeout(\n () =>\n reject(\n new TimeoutError(\n `${operationName} timed out after ${timeoutMs}ms`,\n timeoutMs,\n ),\n ),\n timeoutMs,\n ),\n ),\n ]);\n}\n\n/**\n * Custom error for timeout operations\n */\nexport class TimeoutError extends Error {\n constructor(\n message: string,\n public readonly timeoutMs: number,\n ) {\n super(message);\n this.name = \"TimeoutError\";\n }\n}\n\n/**\n * Default timeout values (in milliseconds)\n */\nexport const DEFAULT_TIMEOUTS = {\n /** File I/O operations (read/write) */\n FILE_IO: 10_000, // 10 seconds\n\n /** Metadata operations (loading/saving) */\n METADATA: 15_000, // 15 seconds\n\n /** AI API calls for translation */\n AI_API: 60_000, // 60 seconds\n\n /** HTTP requests to translation server */\n HTTP_REQUEST: 30_000, // 30 seconds\n\n /** Server initialization */\n SERVER_START: 30_000, // 30 seconds\n\n /** Translation service full operation */\n TRANSLATION: 120_000, // 2 minutes\n} as const;\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,YACd,SACA,WACA,gBAAwB,aACZ;AACZ,QAAO,QAAQ,KAAK,CAClB,SACA,IAAI,SAAY,GAAG,WACjB,iBAEI,OACE,IAAI,aACF,GAAG,cAAc,mBAAmB,UAAU,KAC9C,UACD,CACF,EACH,UACD,CACF,CACF,CAAC;;;;;AAMJ,IAAa,eAAb,cAAkC,MAAM;CACtC,YACE,SACA,AAAgBA,WAChB;AACA,QAAM,QAAQ;EAFE;AAGhB,OAAK,OAAO;;;;;;AAOhB,MAAa,mBAAmB;CAE9B,SAAS;CAGT,UAAU;CAGV,QAAQ;CAGR,cAAc;CAGd,cAAc;CAGd,aAAa;CACd"}
@@ -0,0 +1,56 @@
1
+ const require_path_helpers = require('../utils/path-helpers.cjs');
2
+
3
+ //#region src/virtual/code-generator.ts
4
+ /**
5
+ * Generate complete config module
6
+ * Exports serverUrl and cacheDir constants
7
+ */
8
+ function generateConfigModule(config) {
9
+ const serverUrl = config.dev.translationServerUrl;
10
+ const cacheDir = require_path_helpers.getCacheDir(config);
11
+ return `export const serverUrl = ${JSON.stringify(serverUrl)};
12
+ export const cacheDir = ${JSON.stringify(cacheDir)};
13
+ export const sourceLocale = ${JSON.stringify(config.sourceLocale)};
14
+ export const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};
15
+ export const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};
16
+ `;
17
+ }
18
+ /**
19
+ * Generate complete locale/server module
20
+ * Exports async getServerLocale() function
21
+ */
22
+ function generateServerLocaleModule(config) {
23
+ return `
24
+ import { createNextCookieLocaleResolver } from '@weglot/translate-react/react/next';
25
+ export const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });
26
+ `;
27
+ }
28
+ /**
29
+ * Generate complete locale/client module
30
+ * Exports getClientLocale() and persistLocale() functions
31
+ */
32
+ function generateClientLocaleModule(config) {
33
+ const cookieName = config.localePersistence.config.name;
34
+ const maxAge = config.localePersistence.config.maxAge;
35
+ return `
36
+ export function getClientLocale() {
37
+ if (typeof document !== 'undefined') {
38
+ const match = document.cookie.match(/${cookieName}=([^;]+)/);
39
+ if (match) return match[1];
40
+ }
41
+ // Fallback to source locale
42
+ return ${JSON.stringify(config.sourceLocale)};
43
+ }
44
+
45
+ export function persistLocale(locale) {
46
+ if (typeof document !== 'undefined') {
47
+ document.cookie = \`${cookieName}=\${locale}; path=/; max-age=${maxAge}\`;
48
+ }
49
+ }
50
+ `;
51
+ }
52
+
53
+ //#endregion
54
+ exports.generateClientLocaleModule = generateClientLocaleModule;
55
+ exports.generateConfigModule = generateConfigModule;
56
+ exports.generateServerLocaleModule = generateServerLocaleModule;
@@ -0,0 +1,55 @@
1
+ import { getCacheDir } from "../utils/path-helpers.mjs";
2
+
3
+ //#region src/virtual/code-generator.ts
4
+ /**
5
+ * Generate complete config module
6
+ * Exports serverUrl and cacheDir constants
7
+ */
8
+ function generateConfigModule(config) {
9
+ const serverUrl = config.dev.translationServerUrl;
10
+ const cacheDir = getCacheDir(config);
11
+ return `export const serverUrl = ${JSON.stringify(serverUrl)};
12
+ export const cacheDir = ${JSON.stringify(cacheDir)};
13
+ export const sourceLocale = ${JSON.stringify(config.sourceLocale)};
14
+ export const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};
15
+ export const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};
16
+ `;
17
+ }
18
+ /**
19
+ * Generate complete locale/server module
20
+ * Exports async getServerLocale() function
21
+ */
22
+ function generateServerLocaleModule(config) {
23
+ return `
24
+ import { createNextCookieLocaleResolver } from '@weglot/translate-react/react/next';
25
+ export const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });
26
+ `;
27
+ }
28
+ /**
29
+ * Generate complete locale/client module
30
+ * Exports getClientLocale() and persistLocale() functions
31
+ */
32
+ function generateClientLocaleModule(config) {
33
+ const cookieName = config.localePersistence.config.name;
34
+ const maxAge = config.localePersistence.config.maxAge;
35
+ return `
36
+ export function getClientLocale() {
37
+ if (typeof document !== 'undefined') {
38
+ const match = document.cookie.match(/${cookieName}=([^;]+)/);
39
+ if (match) return match[1];
40
+ }
41
+ // Fallback to source locale
42
+ return ${JSON.stringify(config.sourceLocale)};
43
+ }
44
+
45
+ export function persistLocale(locale) {
46
+ if (typeof document !== 'undefined') {
47
+ document.cookie = \`${cookieName}=\${locale}; path=/; max-age=${maxAge}\`;
48
+ }
49
+ }
50
+ `;
51
+ }
52
+
53
+ //#endregion
54
+ export { generateClientLocaleModule, generateConfigModule, generateServerLocaleModule };
55
+ //# sourceMappingURL=code-generator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-generator.mjs","names":[],"sources":["../../src/virtual/code-generator.ts"],"sourcesContent":["/**\n * Shared code generation for virtual modules\n * Used by both unplugin (virtual modules) and Turbopack loaders\n *\n * This module provides FULL module generators, not just function bodies.\n * Both loaders and unplugin use these to generate complete modules.\n */\n\nimport type { WeglotConfig } from \"../types\";\nimport { getCacheDir } from \"../utils/path-helpers\";\n\n/**\n * Generate complete config module\n * Exports serverUrl and cacheDir constants\n */\nexport function generateConfigModule(config: WeglotConfig): string {\n const serverUrl = config.dev.translationServerUrl;\n const cacheDir = getCacheDir(config);\n\n return `export const serverUrl = ${JSON.stringify(serverUrl)};\nexport const cacheDir = ${JSON.stringify(cacheDir)};\nexport const sourceLocale = ${JSON.stringify(config.sourceLocale)};\nexport const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};\nexport const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};\n`;\n}\n\n/**\n * Generate complete locale/server module\n * Exports async getServerLocale() function\n */\nexport function generateServerLocaleModule(config: WeglotConfig): string {\n return `\nimport { createNextCookieLocaleResolver } from '@weglot/translate-react/react/next';\nexport const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });\n`;\n}\n\n/**\n * Generate complete locale/client module\n * Exports getClientLocale() and persistLocale() functions\n */\nexport function generateClientLocaleModule(config: WeglotConfig): string {\n const cookieName = config.localePersistence.config.name;\n const maxAge = config.localePersistence.config.maxAge;\n\n return `\nexport function getClientLocale() {\n if (typeof document !== 'undefined') {\n const match = document.cookie.match(/${cookieName}=([^;]+)/);\n if (match) return match[1];\n }\n // Fallback to source locale\n return ${JSON.stringify(config.sourceLocale)};\n}\n\nexport function persistLocale(locale) {\n if (typeof document !== 'undefined') {\n document.cookie = \\`${cookieName}=\\${locale}; path=/; max-age=${maxAge}\\`;\n }\n}\n`;\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,qBAAqB,QAA8B;CACjE,MAAM,YAAY,OAAO,IAAI;CAC7B,MAAM,WAAW,YAAY,OAAO;AAEpC,QAAO,4BAA4B,KAAK,UAAU,UAAU,CAAC;0BACrC,KAAK,UAAU,SAAS,CAAC;8BACrB,KAAK,UAAU,OAAO,aAAa,CAAC;4BACtC,KAAK,UAAU,OAAO,cAAc,EAAE,CAAC,CAAC;mCACjC,KAAK,UAAU,OAAO,qBAAqB,EAAE,CAAC;;;;;;;AAQjF,SAAgB,2BAA2B,QAA8B;AACvE,QAAO;;gFAEuE,KAAK,UAAU,OAAO,kBAAkB,OAAO,CAAC,mBAAmB,KAAK,UAAU,OAAO,aAAa,CAAC;;;;;;;AAQvL,SAAgB,2BAA2B,QAA8B;CACvE,MAAM,aAAa,OAAO,kBAAkB,OAAO;CACnD,MAAM,SAAS,OAAO,kBAAkB,OAAO;AAE/C,QAAO;;;2CAGkC,WAAW;;;;WAI3C,KAAK,UAAU,OAAO,aAAa,CAAC;;;;;0BAKrB,WAAW,+BAA+B,OAAO"}
@@ -0,0 +1,16 @@
1
+
2
+ //#region src/virtual/config.ts
3
+ const serverUrl = "__SERVER_URL__";
4
+ const cacheDir = "__CACHE_DIR__";
5
+ const sourceLocale = "__SOURCE_LOCALE__";
6
+ /** Public locale to the language code the translate API expects. */
7
+ const apiLocales = {};
8
+ /** Which inline elements the project's engine permits inside a segment. */
9
+ const translationEngine = 3;
10
+
11
+ //#endregion
12
+ exports.apiLocales = apiLocales;
13
+ exports.cacheDir = cacheDir;
14
+ exports.serverUrl = serverUrl;
15
+ exports.sourceLocale = sourceLocale;
16
+ exports.translationEngine = translationEngine;
@@ -0,0 +1,13 @@
1
+ import { LocaleCode } from "../locale.cjs";
2
+
3
+ //#region src/virtual/config.d.ts
4
+ declare const serverUrl = "__SERVER_URL__";
5
+ declare const cacheDir = "__CACHE_DIR__";
6
+ declare const sourceLocale: LocaleCode;
7
+ /** Public locale to the language code the translate API expects. */
8
+ declare const apiLocales: Record<string, LocaleCode>;
9
+ /** Which inline elements the project's engine permits inside a segment. */
10
+ declare const translationEngine: number;
11
+ //#endregion
12
+ export { apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
13
+ //# sourceMappingURL=config.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.cts","names":[],"sources":["../../src/virtual/config.ts"],"sourcesContent":[],"mappings":";;;cAEa,SAAA;cACA,QAAA;AADA,cAEA,YAFS,EAE6B,UAF7B;AACtB;AACa,cAGA,UAHsC,EAG1B,MAH0B,CAAA,MAAU,EAGrB,UAHqB,CAAA;AAG7D;AAGa,cAAA,iBAA6B,EAAA,MAAA"}
@@ -0,0 +1,13 @@
1
+ import { LocaleCode } from "../locale.mjs";
2
+
3
+ //#region src/virtual/config.d.ts
4
+ declare const serverUrl = "__SERVER_URL__";
5
+ declare const cacheDir = "__CACHE_DIR__";
6
+ declare const sourceLocale: LocaleCode;
7
+ /** Public locale to the language code the translate API expects. */
8
+ declare const apiLocales: Record<string, LocaleCode>;
9
+ /** Which inline elements the project's engine permits inside a segment. */
10
+ declare const translationEngine: number;
11
+ //#endregion
12
+ export { apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
13
+ //# sourceMappingURL=config.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.mts","names":[],"sources":["../../src/virtual/config.ts"],"sourcesContent":[],"mappings":";;;cAEa,SAAA;cACA,QAAA;AADA,cAEA,YAFS,EAE6B,UAF7B;AACtB;AACa,cAGA,UAHsC,EAG1B,MAH0B,CAAA,MAAU,EAGrB,UAHqB,CAAA;AAG7D;AAGa,cAAA,iBAA6B,EAAA,MAAA"}
@@ -0,0 +1,12 @@
1
+ //#region src/virtual/config.ts
2
+ const serverUrl = "__SERVER_URL__";
3
+ const cacheDir = "__CACHE_DIR__";
4
+ const sourceLocale = "__SOURCE_LOCALE__";
5
+ /** Public locale to the language code the translate API expects. */
6
+ const apiLocales = {};
7
+ /** Which inline elements the project's engine permits inside a segment. */
8
+ const translationEngine = 3;
9
+
10
+ //#endregion
11
+ export { apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
12
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.mjs","names":["apiLocales: Record<string, LocaleCode>","translationEngine: number"],"sources":["../../src/virtual/config.ts"],"sourcesContent":["import type { LocaleCode } from \"../locale\";\n\nexport const serverUrl = \"__SERVER_URL__\";\nexport const cacheDir = \"__CACHE_DIR__\";\nexport const sourceLocale = \"__SOURCE_LOCALE__\" as LocaleCode;\n\n/** Public locale to the language code the translate API expects. */\nexport const apiLocales: Record<string, LocaleCode> = {};\n\n/** Which inline elements the project's engine permits inside a segment. */\nexport const translationEngine: number = 3;\n"],"mappings":";AAEA,MAAa,YAAY;AACzB,MAAa,WAAW;AACxB,MAAa,eAAe;;AAG5B,MAAaA,aAAyC,EAAE;;AAGxD,MAAaC,oBAA4B"}
@@ -0,0 +1,23 @@
1
+
2
+ //#region src/virtual/locale/client.ts
3
+ /**
4
+ * Get the current locale on the client
5
+ * Reads from cookie
6
+ * @returns Resolved locale code
7
+ */
8
+ function getClientLocale() {
9
+ return "en";
10
+ }
11
+ const __NOOP_PERSIST_LOCALE__ = () => {};
12
+ /**
13
+ * Persist the locale on the client
14
+ * Writes to cookie
15
+ * @param locale - Locale code to persist
16
+ */
17
+ function persistLocale(locale) {
18
+ return __NOOP_PERSIST_LOCALE__();
19
+ }
20
+
21
+ //#endregion
22
+ exports.getClientLocale = getClientLocale;
23
+ exports.persistLocale = persistLocale;
@@ -0,0 +1,19 @@
1
+ import { LocaleCode } from "../../locale.cjs";
2
+
3
+ //#region src/virtual/locale/client.d.ts
4
+
5
+ /**
6
+ * Get the current locale on the client
7
+ * Reads from cookie
8
+ * @returns Resolved locale code
9
+ */
10
+ declare function getClientLocale(): LocaleCode;
11
+ /**
12
+ * Persist the locale on the client
13
+ * Writes to cookie
14
+ * @param locale - Locale code to persist
15
+ */
16
+ declare function persistLocale(locale: LocaleCode): void;
17
+ //#endregion
18
+ export { getClientLocale, persistLocale };
19
+ //# sourceMappingURL=client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../../../src/virtual/locale/client.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAWA;;iBAXgB,eAAA,CAAA,GAAmB;;;;;;iBAWnB,aAAA,SAAsB"}
@@ -0,0 +1,19 @@
1
+ import { LocaleCode } from "../../locale.mjs";
2
+
3
+ //#region src/virtual/locale/client.d.ts
4
+
5
+ /**
6
+ * Get the current locale on the client
7
+ * Reads from cookie
8
+ * @returns Resolved locale code
9
+ */
10
+ declare function getClientLocale(): LocaleCode;
11
+ /**
12
+ * Persist the locale on the client
13
+ * Writes to cookie
14
+ * @param locale - Locale code to persist
15
+ */
16
+ declare function persistLocale(locale: LocaleCode): void;
17
+ //#endregion
18
+ export { getClientLocale, persistLocale };
19
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.mts","names":[],"sources":["../../../src/virtual/locale/client.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAWA;;iBAXgB,eAAA,CAAA,GAAmB;;;;;;iBAWnB,aAAA,SAAsB"}
@@ -0,0 +1,22 @@
1
+ //#region src/virtual/locale/client.ts
2
+ /**
3
+ * Get the current locale on the client
4
+ * Reads from cookie
5
+ * @returns Resolved locale code
6
+ */
7
+ function getClientLocale() {
8
+ return "en";
9
+ }
10
+ const __NOOP_PERSIST_LOCALE__ = () => {};
11
+ /**
12
+ * Persist the locale on the client
13
+ * Writes to cookie
14
+ * @param locale - Locale code to persist
15
+ */
16
+ function persistLocale(locale) {
17
+ return __NOOP_PERSIST_LOCALE__();
18
+ }
19
+
20
+ //#endregion
21
+ export { getClientLocale, persistLocale };
22
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../../src/virtual/locale/client.ts"],"sourcesContent":["import type { LocaleCode } from \"../../locale\";\n\n/**\n * Get the current locale on the client\n * Reads from cookie\n * @returns Resolved locale code\n */\nexport function getClientLocale(): LocaleCode {\n return \"en\";\n}\n\nconst __NOOP_PERSIST_LOCALE__ = () => {};\n\n/**\n * Persist the locale on the client\n * Writes to cookie\n * @param locale - Locale code to persist\n */\nexport function persistLocale(locale: LocaleCode): void {\n return __NOOP_PERSIST_LOCALE__();\n}\n"],"mappings":";;;;;;AAOA,SAAgB,kBAA8B;AAC5C,QAAO;;AAGT,MAAM,gCAAgC;;;;;;AAOtC,SAAgB,cAAc,QAA0B;AACtD,QAAO,yBAAyB"}
@@ -0,0 +1,13 @@
1
+
2
+ //#region src/virtual/locale/server.ts
3
+ /**
4
+ * Get the current locale on the server
5
+ * Uses cookies, headers, or other server-side mechanisms
6
+ * @returns Resolved locale code
7
+ */
8
+ async function getServerLocale() {
9
+ return "en";
10
+ }
11
+
12
+ //#endregion
13
+ exports.getServerLocale = getServerLocale;