@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.
- package/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +199 -2
- package/build/_virtual/rolldown_runtime.cjs +29 -0
- package/build/_virtual/rolldown_runtime.mjs +7 -0
- package/build/index.cjs +0 -0
- package/build/index.d.cts +2 -0
- package/build/index.d.mts +2 -0
- package/build/index.mjs +1 -0
- package/build/locale.d.cts +6 -0
- package/build/locale.d.cts.map +1 -0
- package/build/locale.d.mts +6 -0
- package/build/locale.d.mts.map +1 -0
- package/build/metadata/manager.cjs +119 -0
- package/build/metadata/manager.mjs +114 -0
- package/build/metadata/manager.mjs.map +1 -0
- package/build/plugin/build-translator.cjs +210 -0
- package/build/plugin/build-translator.mjs +208 -0
- package/build/plugin/build-translator.mjs.map +1 -0
- package/build/plugin/cleanup.cjs +20 -0
- package/build/plugin/cleanup.mjs +20 -0
- package/build/plugin/cleanup.mjs.map +1 -0
- package/build/plugin/index.cjs +0 -0
- package/build/plugin/index.d.cts +2 -0
- package/build/plugin/index.d.mts +2 -0
- package/build/plugin/index.mjs +1 -0
- package/build/plugin/next-compiler-loader.cjs +40 -0
- package/build/plugin/next-compiler-loader.d.cts +12 -0
- package/build/plugin/next-compiler-loader.d.cts.map +1 -0
- package/build/plugin/next-compiler-loader.d.mts +13 -0
- package/build/plugin/next-compiler-loader.d.mts.map +1 -0
- package/build/plugin/next-compiler-loader.mjs +41 -0
- package/build/plugin/next-compiler-loader.mjs.map +1 -0
- package/build/plugin/next-config-loader.cjs +13 -0
- package/build/plugin/next-config-loader.d.cts +8 -0
- package/build/plugin/next-config-loader.d.cts.map +1 -0
- package/build/plugin/next-config-loader.d.mts +9 -0
- package/build/plugin/next-config-loader.d.mts.map +1 -0
- package/build/plugin/next-config-loader.mjs +14 -0
- package/build/plugin/next-config-loader.mjs.map +1 -0
- package/build/plugin/next-locale-client-loader.cjs +9 -0
- package/build/plugin/next-locale-client-loader.d.cts +8 -0
- package/build/plugin/next-locale-client-loader.d.cts.map +1 -0
- package/build/plugin/next-locale-client-loader.d.mts +9 -0
- package/build/plugin/next-locale-client-loader.d.mts.map +1 -0
- package/build/plugin/next-locale-client-loader.mjs +10 -0
- package/build/plugin/next-locale-client-loader.mjs.map +1 -0
- package/build/plugin/next-locale-server-loader.cjs +9 -0
- package/build/plugin/next-locale-server-loader.d.cts +8 -0
- package/build/plugin/next-locale-server-loader.d.cts.map +1 -0
- package/build/plugin/next-locale-server-loader.d.mts +9 -0
- package/build/plugin/next-locale-server-loader.d.mts.map +1 -0
- package/build/plugin/next-locale-server-loader.mjs +10 -0
- package/build/plugin/next-locale-server-loader.mjs.map +1 -0
- package/build/plugin/next.cjs +227 -0
- package/build/plugin/next.d.cts +9 -0
- package/build/plugin/next.d.cts.map +1 -0
- package/build/plugin/next.d.mts +9 -0
- package/build/plugin/next.d.mts.map +1 -0
- package/build/plugin/next.mjs +229 -0
- package/build/plugin/next.mjs.map +1 -0
- package/build/plugin/transform/babel-compat.cjs +13 -0
- package/build/plugin/transform/babel-compat.mjs +10 -0
- package/build/plugin/transform/babel-compat.mjs.map +1 -0
- package/build/plugin/transform/expression-strings.cjs +145 -0
- package/build/plugin/transform/expression-strings.mjs +140 -0
- package/build/plugin/transform/expression-strings.mjs.map +1 -0
- package/build/plugin/transform/index.cjs +45 -0
- package/build/plugin/transform/index.mjs +43 -0
- package/build/plugin/transform/index.mjs.map +1 -0
- package/build/plugin/transform/metadata.cjs +142 -0
- package/build/plugin/transform/metadata.mjs +141 -0
- package/build/plugin/transform/metadata.mjs.map +1 -0
- package/build/plugin/transform/process-file.cjs +525 -0
- package/build/plugin/transform/process-file.mjs +524 -0
- package/build/plugin/transform/process-file.mjs.map +1 -0
- package/build/plugin/transform/use-i18n.cjs +8 -0
- package/build/plugin/transform/use-i18n.mjs +7 -0
- package/build/plugin/transform/use-i18n.mjs.map +1 -0
- package/build/plugin/transform/utils.cjs +237 -0
- package/build/plugin/transform/utils.mjs +219 -0
- package/build/plugin/transform/utils.mjs.map +1 -0
- package/build/plugin/unplugin.cjs +188 -0
- package/build/plugin/unplugin.d.cts +8 -0
- package/build/plugin/unplugin.d.cts.map +1 -0
- package/build/plugin/unplugin.d.mts +8 -0
- package/build/plugin/unplugin.d.mts.map +1 -0
- package/build/plugin/unplugin.mjs +188 -0
- package/build/plugin/unplugin.mjs.map +1 -0
- package/build/plugin/vite.cjs +27 -0
- package/build/plugin/vite.d.cts +9 -0
- package/build/plugin/vite.d.cts.map +1 -0
- package/build/plugin/vite.d.mts +9 -0
- package/build/plugin/vite.d.mts.map +1 -0
- package/build/plugin/vite.mjs +28 -0
- package/build/plugin/vite.mjs.map +1 -0
- package/build/plugin/webpack.cjs +26 -0
- package/build/plugin/webpack.d.cts +8 -0
- package/build/plugin/webpack.d.cts.map +1 -0
- package/build/plugin/webpack.d.mts +8 -0
- package/build/plugin/webpack.d.mts.map +1 -0
- package/build/plugin/webpack.mjs +27 -0
- package/build/plugin/webpack.mjs.map +1 -0
- package/build/react/client/index.cjs +9 -0
- package/build/react/client/index.d.cts +5 -0
- package/build/react/client/index.d.mts +5 -0
- package/build/react/client/index.mjs +6 -0
- package/build/react/client/useTranslation.cjs +71 -0
- package/build/react/client/useTranslation.d.cts +42 -0
- package/build/react/client/useTranslation.d.cts.map +1 -0
- package/build/react/client/useTranslation.d.mts +42 -0
- package/build/react/client/useTranslation.d.mts.map +1 -0
- package/build/react/client/useTranslation.mjs +71 -0
- package/build/react/client/useTranslation.mjs.map +1 -0
- package/build/react/next/client.cjs +25 -0
- package/build/react/next/client.d.cts +9 -0
- package/build/react/next/client.d.cts.map +1 -0
- package/build/react/next/client.d.mts +9 -0
- package/build/react/next/client.d.mts.map +1 -0
- package/build/react/next/client.mjs +24 -0
- package/build/react/next/client.mjs.map +1 -0
- package/build/react/next/cookie-locale-resolver.cjs +29 -0
- package/build/react/next/cookie-locale-resolver.d.cts +33 -0
- package/build/react/next/cookie-locale-resolver.d.cts.map +1 -0
- package/build/react/next/cookie-locale-resolver.d.mts +33 -0
- package/build/react/next/cookie-locale-resolver.d.mts.map +1 -0
- package/build/react/next/cookie-locale-resolver.mjs +29 -0
- package/build/react/next/cookie-locale-resolver.mjs.map +1 -0
- package/build/react/next/server.cjs +21 -0
- package/build/react/next/server.d.cts +13 -0
- package/build/react/next/server.d.cts.map +1 -0
- package/build/react/next/server.d.mts +14 -0
- package/build/react/next/server.d.mts.map +1 -0
- package/build/react/next/server.mjs +20 -0
- package/build/react/next/server.mjs.map +1 -0
- package/build/react/server/ServerWeglotProvider.cjs +19 -0
- package/build/react/server/ServerWeglotProvider.d.cts +12 -0
- package/build/react/server/ServerWeglotProvider.d.cts.map +1 -0
- package/build/react/server/ServerWeglotProvider.d.mts +12 -0
- package/build/react/server/ServerWeglotProvider.d.mts.map +1 -0
- package/build/react/server/ServerWeglotProvider.mjs +19 -0
- package/build/react/server/ServerWeglotProvider.mjs.map +1 -0
- package/build/react/server/index.cjs +7 -0
- package/build/react/server/index.d.cts +4 -0
- package/build/react/server/index.d.mts +4 -0
- package/build/react/server/index.mjs +5 -0
- package/build/react/server/useTranslation.cjs +60 -0
- package/build/react/server/useTranslation.d.cts +36 -0
- package/build/react/server/useTranslation.d.cts.map +1 -0
- package/build/react/server/useTranslation.d.mts +36 -0
- package/build/react/server/useTranslation.d.mts.map +1 -0
- package/build/react/server/useTranslation.mjs +60 -0
- package/build/react/server/useTranslation.mjs.map +1 -0
- package/build/react/server-only/index.cjs +42 -0
- package/build/react/server-only/index.d.cts +38 -0
- package/build/react/server-only/index.d.cts.map +1 -0
- package/build/react/server-only/index.d.mts +38 -0
- package/build/react/server-only/index.d.mts.map +1 -0
- package/build/react/server-only/index.mjs +42 -0
- package/build/react/server-only/index.mjs.map +1 -0
- package/build/react/server-only/translations.cjs +86 -0
- package/build/react/server-only/translations.mjs +86 -0
- package/build/react/server-only/translations.mjs.map +1 -0
- package/build/react/shared/LocaleSwitcher.cjs +61 -0
- package/build/react/shared/LocaleSwitcher.d.cts +71 -0
- package/build/react/shared/LocaleSwitcher.d.cts.map +1 -0
- package/build/react/shared/LocaleSwitcher.d.mts +71 -0
- package/build/react/shared/LocaleSwitcher.d.mts.map +1 -0
- package/build/react/shared/LocaleSwitcher.mjs +61 -0
- package/build/react/shared/LocaleSwitcher.mjs.map +1 -0
- package/build/react/shared/WeglotContext.cjs +14 -0
- package/build/react/shared/WeglotContext.d.cts +34 -0
- package/build/react/shared/WeglotContext.d.cts.map +1 -0
- package/build/react/shared/WeglotContext.d.mts +34 -0
- package/build/react/shared/WeglotContext.d.mts.map +1 -0
- package/build/react/shared/WeglotContext.mjs +13 -0
- package/build/react/shared/WeglotContext.mjs.map +1 -0
- package/build/react/shared/WeglotProvider.cjs +250 -0
- package/build/react/shared/WeglotProvider.d.cts +60 -0
- package/build/react/shared/WeglotProvider.d.cts.map +1 -0
- package/build/react/shared/WeglotProvider.d.mts +60 -0
- package/build/react/shared/WeglotProvider.d.mts.map +1 -0
- package/build/react/shared/WeglotProvider.mjs +250 -0
- package/build/react/shared/WeglotProvider.mjs.map +1 -0
- package/build/react/shared/render-rich-text.cjs +56 -0
- package/build/react/shared/render-rich-text.d.cts +16 -0
- package/build/react/shared/render-rich-text.d.cts.map +1 -0
- package/build/react/shared/render-rich-text.d.mts +16 -0
- package/build/react/shared/render-rich-text.d.mts.map +1 -0
- package/build/react/shared/render-rich-text.mjs +55 -0
- package/build/react/shared/render-rich-text.mjs.map +1 -0
- package/build/react/shared/utils.cjs +34 -0
- package/build/react/shared/utils.mjs +35 -0
- package/build/react/shared/utils.mjs.map +1 -0
- package/build/react/types.d.cts +16 -0
- package/build/react/types.d.cts.map +1 -0
- package/build/react/types.d.mts +16 -0
- package/build/react/types.d.mts.map +1 -0
- package/build/runtime/html/segmenter.cjs +226 -0
- package/build/runtime/html/segmenter.mjs +225 -0
- package/build/runtime/html/segmenter.mjs.map +1 -0
- package/build/runtime/index.cjs +6 -0
- package/build/runtime/index.d.cts +2 -0
- package/build/runtime/index.d.mts +2 -0
- package/build/runtime/index.mjs +3 -0
- package/build/runtime/translate-dynamic.cjs +144 -0
- package/build/runtime/translate-dynamic.d.cts +29 -0
- package/build/runtime/translate-dynamic.d.cts.map +1 -0
- package/build/runtime/translate-dynamic.d.mts +29 -0
- package/build/runtime/translate-dynamic.d.mts.map +1 -0
- package/build/runtime/translate-dynamic.mjs +141 -0
- package/build/runtime/translate-dynamic.mjs.map +1 -0
- package/build/translation-server/logger.cjs +37 -0
- package/build/translation-server/logger.mjs +37 -0
- package/build/translation-server/logger.mjs.map +1 -0
- package/build/translation-server/translation-server.cjs +451 -0
- package/build/translation-server/translation-server.mjs +448 -0
- package/build/translation-server/translation-server.mjs.map +1 -0
- package/build/translators/api.cjs +12 -0
- package/build/translators/api.mjs +12 -0
- package/build/translators/api.mjs.map +1 -0
- package/build/translators/cache-factory.cjs +26 -0
- package/build/translators/cache-factory.mjs +27 -0
- package/build/translators/cache-factory.mjs.map +1 -0
- package/build/translators/local-cache.cjs +132 -0
- package/build/translators/local-cache.mjs +130 -0
- package/build/translators/local-cache.mjs.map +1 -0
- package/build/translators/translation-service.cjs +139 -0
- package/build/translators/translation-service.mjs +140 -0
- package/build/translators/translation-service.mjs.map +1 -0
- package/build/translators/weglot/api-client.cjs +131 -0
- package/build/translators/weglot/api-client.mjs +130 -0
- package/build/translators/weglot/api-client.mjs.map +1 -0
- package/build/translators/weglot/definitions/definitions.generated.cjs +53 -0
- package/build/translators/weglot/definitions/definitions.generated.mjs +52 -0
- package/build/translators/weglot/definitions/definitions.generated.mjs.map +1 -0
- package/build/translators/weglot/engine.cjs +43 -0
- package/build/translators/weglot/engine.mjs +40 -0
- package/build/translators/weglot/engine.mjs.map +1 -0
- package/build/translators/weglot/translator.cjs +67 -0
- package/build/translators/weglot/translator.mjs +68 -0
- package/build/translators/weglot/translator.mjs.map +1 -0
- package/build/translators/weglot/wire-format.cjs +128 -0
- package/build/translators/weglot/wire-format.mjs +129 -0
- package/build/translators/weglot/wire-format.mjs.map +1 -0
- package/build/types.d.cts +153 -0
- package/build/types.d.cts.map +1 -0
- package/build/types.d.mts +153 -0
- package/build/types.d.mts.map +1 -0
- package/build/utils/config-factory.cjs +100 -0
- package/build/utils/config-factory.mjs +97 -0
- package/build/utils/config-factory.mjs.map +1 -0
- package/build/utils/hash.cjs +17 -0
- package/build/utils/hash.mjs +16 -0
- package/build/utils/hash.mjs.map +1 -0
- package/build/utils/is-valid-locale.cjs +13 -0
- package/build/utils/is-valid-locale.mjs +13 -0
- package/build/utils/is-valid-locale.mjs.map +1 -0
- package/build/utils/logger.cjs +51 -0
- package/build/utils/logger.mjs +50 -0
- package/build/utils/logger.mjs.map +1 -0
- package/build/utils/path-helpers.cjs +49 -0
- package/build/utils/path-helpers.mjs +47 -0
- package/build/utils/path-helpers.mjs.map +1 -0
- package/build/utils/timeout.cjs +42 -0
- package/build/utils/timeout.mjs +41 -0
- package/build/utils/timeout.mjs.map +1 -0
- package/build/virtual/code-generator.cjs +58 -0
- package/build/virtual/code-generator.mjs +57 -0
- package/build/virtual/code-generator.mjs.map +1 -0
- package/build/virtual/config.cjs +19 -0
- package/build/virtual/config.d.cts +15 -0
- package/build/virtual/config.d.cts.map +1 -0
- package/build/virtual/config.d.mts +15 -0
- package/build/virtual/config.d.mts.map +1 -0
- package/build/virtual/config.mjs +14 -0
- package/build/virtual/config.mjs.map +1 -0
- package/build/virtual/locale/client.cjs +23 -0
- package/build/virtual/locale/client.d.cts +19 -0
- package/build/virtual/locale/client.d.cts.map +1 -0
- package/build/virtual/locale/client.d.mts +19 -0
- package/build/virtual/locale/client.d.mts.map +1 -0
- package/build/virtual/locale/client.mjs +22 -0
- package/build/virtual/locale/client.mjs.map +1 -0
- package/build/virtual/locale/server.cjs +13 -0
- package/build/virtual/locale/server.d.cts +13 -0
- package/build/virtual/locale/server.d.cts.map +1 -0
- package/build/virtual/locale/server.d.mts +13 -0
- package/build/virtual/locale/server.d.mts.map +1 -0
- package/build/virtual/locale/server.mjs +13 -0
- package/build/virtual/locale/server.mjs.map +1 -0
- package/package.json +260 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DEFAULT_API_BASE_URL, WeglotApiClient } from "../translators/weglot/api-client.mjs";
|
|
2
|
+
import { resolveTranslationEngine } from "../translators/weglot/engine.mjs";
|
|
3
|
+
import "dotenv/config";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/config-factory.ts
|
|
6
|
+
/**
|
|
7
|
+
* Default configuration values
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
sourceRoot: "src",
|
|
11
|
+
weglotDir: "weglot",
|
|
12
|
+
useDirective: false,
|
|
13
|
+
translatableAttributes: {},
|
|
14
|
+
dev: { translationServerStartPort: 6e4 },
|
|
15
|
+
localePersistence: {
|
|
16
|
+
type: "cookie",
|
|
17
|
+
config: {
|
|
18
|
+
name: "locale",
|
|
19
|
+
maxAge: 31536e3
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
buildMode: "translate"
|
|
23
|
+
};
|
|
24
|
+
const DEFAULT_TRANSLATION_TIMEOUT = {
|
|
25
|
+
production: 300,
|
|
26
|
+
development: 10
|
|
27
|
+
};
|
|
28
|
+
function timeoutFromEnv() {
|
|
29
|
+
const raw = process.env.WEGLOT_TRANSLATION_TIMEOUT;
|
|
30
|
+
if (!raw) return void 0;
|
|
31
|
+
const value = Number(raw);
|
|
32
|
+
return Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a LoaderConfig with defaults applied
|
|
36
|
+
*
|
|
37
|
+
* @param options - Partial config to override defaults
|
|
38
|
+
* @returns Complete LoaderConfig with all defaults applied
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
function createWeglotConfig(options) {
|
|
42
|
+
const cleanOptions = { ...options };
|
|
43
|
+
const cleanObject = (obj) => {
|
|
44
|
+
if (!obj || typeof obj !== "object") return;
|
|
45
|
+
Object.keys(obj).forEach((key) => {
|
|
46
|
+
if (obj[key] === void 0) delete obj[key];
|
|
47
|
+
else if (obj[key] && typeof obj[key] === "object" && !Array.isArray(obj[key])) cleanObject(obj[key]);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
cleanObject(cleanOptions);
|
|
51
|
+
const apiKey = cleanOptions.apiKey ?? process.env.WEGLOT_API_KEY;
|
|
52
|
+
if (!apiKey) throw new Error("Weglot project key is missing. Pass `apiKey` in the plugin options or set the WEGLOT_API_KEY environment variable.");
|
|
53
|
+
const environment = cleanOptions.environment ?? (process.env.NODE_ENV === "development" ? "development" : "production");
|
|
54
|
+
return {
|
|
55
|
+
...DEFAULT_CONFIG,
|
|
56
|
+
...cleanOptions,
|
|
57
|
+
apiKey,
|
|
58
|
+
sourceLocale: cleanOptions.sourceLocale ?? "",
|
|
59
|
+
targetLocales: cleanOptions.targetLocales ?? [],
|
|
60
|
+
apiLocales: cleanOptions.apiLocales ?? {},
|
|
61
|
+
translationEngine: resolveTranslationEngine(cleanOptions.translationEngine),
|
|
62
|
+
apiBaseUrl: cleanOptions.apiBaseUrl ?? "",
|
|
63
|
+
translationTimeout: cleanOptions.translationTimeout ?? timeoutFromEnv() ?? DEFAULT_TRANSLATION_TIMEOUT[environment],
|
|
64
|
+
environment,
|
|
65
|
+
cacheType: cleanOptions.cacheType ?? "local",
|
|
66
|
+
dev: {
|
|
67
|
+
...DEFAULT_CONFIG.dev,
|
|
68
|
+
...cleanOptions.dev
|
|
69
|
+
},
|
|
70
|
+
localePersistence: {
|
|
71
|
+
...DEFAULT_CONFIG.localePersistence,
|
|
72
|
+
...cleanOptions.localePersistence,
|
|
73
|
+
config: {
|
|
74
|
+
...DEFAULT_CONFIG.localePersistence.config,
|
|
75
|
+
...cleanOptions.localePersistence?.config
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Fetches source/target locales from the Weglot project settings.
|
|
82
|
+
* Idempotent: no-ops when locales are already resolved (e.g. passed
|
|
83
|
+
* through Next.js loader options).
|
|
84
|
+
*/
|
|
85
|
+
async function resolveProjectLanguages(config, client = new WeglotApiClient(config.apiKey)) {
|
|
86
|
+
if (config.sourceLocale && config.targetLocales.length > 0 && config.apiBaseUrl) return;
|
|
87
|
+
const settings = await client.fetchSettings();
|
|
88
|
+
config.sourceLocale = settings.sourceLocale;
|
|
89
|
+
config.targetLocales = settings.targetLocales;
|
|
90
|
+
config.apiLocales = settings.apiLocales;
|
|
91
|
+
config.apiBaseUrl = settings.apiBaseUrl || DEFAULT_API_BASE_URL;
|
|
92
|
+
config.translationEngine = resolveTranslationEngine(settings.translationEngine);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { createWeglotConfig, resolveProjectLanguages };
|
|
97
|
+
//# sourceMappingURL=config-factory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-factory.mjs","names":[],"sources":["../../src/utils/config-factory.ts"],"sourcesContent":["/**\n * Config factory for creating LoaderConfig instances\n */\nimport \"dotenv/config\";\nimport type {\n WeglotConfig,\n WeglotInternalFields,\n PartialWeglotConfig,\n} from \"../types\";\nimport {\n DEFAULT_API_BASE_URL,\n WeglotApiClient,\n} from \"../translators/weglot/api-client\";\nimport { resolveTranslationEngine } from \"../translators/weglot/engine\";\n\n/**\n * Default configuration values\n */\nexport const DEFAULT_CONFIG = {\n sourceRoot: \"src\",\n weglotDir: \"weglot\",\n useDirective: false,\n translatableAttributes: {},\n dev: {\n translationServerStartPort: 60000,\n },\n localePersistence: {\n type: \"cookie\" as const,\n config: {\n name: \"locale\",\n maxAge: 31536000,\n },\n },\n buildMode: \"translate\",\n} satisfies Omit<\n WeglotConfig,\n // weglotDir is an internal field for public-config purposes, but (unlike\n // the other internal fields) it still has a static default here rather\n // than being resolved at runtime, so it stays out of this Omit.\n \"apiKey\" | \"translationTimeout\" | Exclude<WeglotInternalFields, \"weglotDir\">\n>;\n\n// Dev stays short: a server component waits on it, and the client gives up at 30s.\nconst DEFAULT_TRANSLATION_TIMEOUT = { production: 300, development: 10 };\n\nfunction timeoutFromEnv(): number | undefined {\n const raw = process.env.WEGLOT_TRANSLATION_TIMEOUT;\n if (!raw) return undefined;\n const value = Number(raw);\n return Number.isFinite(value) && value >= 0 ? value : undefined;\n}\n\n/**\n * Create a LoaderConfig with defaults applied\n *\n * @param options - Partial config to override defaults\n * @returns Complete LoaderConfig with all defaults applied\n *\n */\nexport function createWeglotConfig(\n options: PartialWeglotConfig & Partial<Pick<WeglotConfig, WeglotInternalFields>>,\n): WeglotConfig {\n const cleanOptions = { ...options };\n\n const cleanObject = (obj: any) => {\n if (!obj || typeof obj !== \"object\") return;\n Object.keys(obj).forEach((key) => {\n if (obj[key] === undefined) {\n delete obj[key];\n } else if (\n obj[key] &&\n typeof obj[key] === \"object\" &&\n !Array.isArray(obj[key])\n ) {\n cleanObject(obj[key]);\n }\n });\n };\n\n cleanObject(cleanOptions);\n\n const apiKey = cleanOptions.apiKey ?? process.env.WEGLOT_API_KEY;\n if (!apiKey) {\n throw new Error(\n \"Weglot project key is missing. Pass `apiKey` in the plugin options or set the WEGLOT_API_KEY environment variable.\",\n );\n }\n\n const environment =\n cleanOptions.environment ??\n (process.env.NODE_ENV === \"development\" ? \"development\" : \"production\");\n\n return {\n ...DEFAULT_CONFIG,\n ...cleanOptions,\n apiKey,\n sourceLocale: cleanOptions.sourceLocale ?? \"\",\n targetLocales: cleanOptions.targetLocales ?? [],\n apiLocales: cleanOptions.apiLocales ?? {},\n translationEngine: resolveTranslationEngine(cleanOptions.translationEngine),\n apiBaseUrl: cleanOptions.apiBaseUrl ?? \"\",\n translationTimeout:\n cleanOptions.translationTimeout ??\n timeoutFromEnv() ??\n DEFAULT_TRANSLATION_TIMEOUT[environment],\n environment,\n cacheType: cleanOptions.cacheType ?? \"local\",\n dev: {\n ...DEFAULT_CONFIG.dev,\n ...cleanOptions.dev,\n },\n localePersistence: {\n ...DEFAULT_CONFIG.localePersistence,\n ...cleanOptions.localePersistence,\n config: {\n ...DEFAULT_CONFIG.localePersistence.config,\n ...cleanOptions.localePersistence?.config,\n },\n },\n };\n}\n\n/**\n * Fetches source/target locales from the Weglot project settings.\n * Idempotent: no-ops when locales are already resolved (e.g. passed\n * through Next.js loader options).\n */\nexport async function resolveProjectLanguages(\n config: WeglotConfig,\n client: WeglotApiClient = new WeglotApiClient(config.apiKey),\n): Promise<void> {\n if (\n config.sourceLocale &&\n config.targetLocales.length > 0 &&\n config.apiBaseUrl\n ) {\n return;\n }\n const settings = await client.fetchSettings();\n config.sourceLocale = settings.sourceLocale;\n config.targetLocales = settings.targetLocales;\n config.apiLocales = settings.apiLocales;\n config.apiBaseUrl = settings.apiBaseUrl || DEFAULT_API_BASE_URL;\n config.translationEngine = resolveTranslationEngine(\n settings.translationEngine,\n );\n}\n"],"mappings":";;;;;;;;AAkBA,MAAa,iBAAiB;CAC5B,YAAY;CACZ,WAAW;CACX,cAAc;CACd,wBAAwB,EAAE;CAC1B,KAAK,EACH,4BAA4B,KAC7B;CACD,mBAAmB;EACjB,MAAM;EACN,QAAQ;GACN,MAAM;GACN,QAAQ;GACT;EACF;CACD,WAAW;CACZ;AASD,MAAM,8BAA8B;CAAE,YAAY;CAAK,aAAa;CAAI;AAExE,SAAS,iBAAqC;CAC5C,MAAM,MAAM,QAAQ,IAAI;AACxB,KAAI,CAAC,IAAK,QAAO;CACjB,MAAM,QAAQ,OAAO,IAAI;AACzB,QAAO,OAAO,SAAS,MAAM,IAAI,SAAS,IAAI,QAAQ;;;;;;;;;AAUxD,SAAgB,mBACd,SACc;CACd,MAAM,eAAe,EAAE,GAAG,SAAS;CAEnC,MAAM,eAAe,QAAa;AAChC,MAAI,CAAC,OAAO,OAAO,QAAQ,SAAU;AACrC,SAAO,KAAK,IAAI,CAAC,SAAS,QAAQ;AAChC,OAAI,IAAI,SAAS,OACf,QAAO,IAAI;YAEX,IAAI,QACJ,OAAO,IAAI,SAAS,YACpB,CAAC,MAAM,QAAQ,IAAI,KAAK,CAExB,aAAY,IAAI,KAAK;IAEvB;;AAGJ,aAAY,aAAa;CAEzB,MAAM,SAAS,aAAa,UAAU,QAAQ,IAAI;AAClD,KAAI,CAAC,OACH,OAAM,IAAI,MACR,qHACD;CAGH,MAAM,cACJ,aAAa,gBACZ,QAAQ,IAAI,aAAa,gBAAgB,gBAAgB;AAE5D,QAAO;EACL,GAAG;EACH,GAAG;EACH;EACA,cAAc,aAAa,gBAAgB;EAC3C,eAAe,aAAa,iBAAiB,EAAE;EAC/C,YAAY,aAAa,cAAc,EAAE;EACzC,mBAAmB,yBAAyB,aAAa,kBAAkB;EAC3E,YAAY,aAAa,cAAc;EACvC,oBACE,aAAa,sBACb,gBAAgB,IAChB,4BAA4B;EAC9B;EACA,WAAW,aAAa,aAAa;EACrC,KAAK;GACH,GAAG,eAAe;GAClB,GAAG,aAAa;GACjB;EACD,mBAAmB;GACjB,GAAG,eAAe;GAClB,GAAG,aAAa;GAChB,QAAQ;IACN,GAAG,eAAe,kBAAkB;IACpC,GAAG,aAAa,mBAAmB;IACpC;GACF;EACF;;;;;;;AAQH,eAAsB,wBACpB,QACA,SAA0B,IAAI,gBAAgB,OAAO,OAAO,EAC7C;AACf,KACE,OAAO,gBACP,OAAO,cAAc,SAAS,KAC9B,OAAO,WAEP;CAEF,MAAM,WAAW,MAAM,OAAO,eAAe;AAC7C,QAAO,eAAe,SAAS;AAC/B,QAAO,gBAAgB,SAAS;AAChC,QAAO,aAAa,SAAS;AAC7B,QAAO,aAAa,SAAS,cAAc;AAC3C,QAAO,oBAAoB,yBACzB,SAAS,kBACV"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let crypto = require("crypto");
|
|
3
|
+
crypto = require_rolldown_runtime.__toESM(crypto);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/hash.ts
|
|
6
|
+
/**
|
|
7
|
+
* Generate a hash for a translation entry
|
|
8
|
+
* Hash is based on: sourceText + context
|
|
9
|
+
* This ensures that the same text in different components or files gets different hashes
|
|
10
|
+
*/
|
|
11
|
+
function generateTranslationHash(sourceText, context) {
|
|
12
|
+
const input = `${sourceText}::${Object.entries(context).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => `${key}:${value}`).join("::")}`;
|
|
13
|
+
return crypto.default.createHash("md5").update(input).digest("hex").substring(0, 12);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.generateTranslationHash = generateTranslationHash;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hash.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate a hash for a translation entry
|
|
6
|
+
* Hash is based on: sourceText + context
|
|
7
|
+
* This ensures that the same text in different components or files gets different hashes
|
|
8
|
+
*/
|
|
9
|
+
function generateTranslationHash(sourceText, context) {
|
|
10
|
+
const input = `${sourceText}::${Object.entries(context).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => `${key}:${value}`).join("::")}`;
|
|
11
|
+
return crypto.createHash("md5").update(input).digest("hex").substring(0, 12);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { generateTranslationHash };
|
|
16
|
+
//# sourceMappingURL=hash.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.mjs","names":[],"sources":["../../src/utils/hash.ts"],"sourcesContent":["import crypto from \"crypto\";\n\n/*\n * If we find md5 too slow, we can use FNV-1a\n *\n * function generateHash(text: string): string {\n * let hash = 2166136261;\n * for (let i = 0; i < text.length; i++) {\n * hash ^= text.charCodeAt(i);\n * hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 12);\n * }\n * return (hash >>> 0).toString(36).padStart(7, '0').slice(0, 12);\n * }\n *\n */\n\n/**\n * Generate a hash for a translation entry\n * Hash is based on: sourceText + context\n * This ensures that the same text in different components or files gets different hashes\n */\nexport function generateTranslationHash(\n sourceText: string,\n context: Record<string, any>,\n): string {\n const input = `${sourceText}::${Object.entries(context)\n .sort((a, b) => a[0].localeCompare(b[0]))\n .map(([key, value]) => `${key}:${value}`)\n .join(\"::\")}`;\n return crypto.createHash(\"md5\").update(input).digest(\"hex\").substring(0, 12); // Use first 12 chars for brevity\n}\n\n/**\n * Validate that a hash matches the expected format\n */\nexport function isValidHash(hash: string): boolean {\n return /^[a-f0-9]{12}$/.test(hash);\n}\n"],"mappings":";;;;;;;;AAqBA,SAAgB,wBACd,YACA,SACQ;CACR,MAAM,QAAQ,GAAG,WAAW,IAAI,OAAO,QAAQ,QAAQ,CACpD,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,CAAC,CACxC,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,QAAQ,CACxC,KAAK,KAAK;AACb,QAAO,OAAO,WAAW,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM,CAAC,UAAU,GAAG,GAAG"}
|
|
@@ -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,58 @@
|
|
|
1
|
+
const require_api_client = require('../translators/weglot/api-client.cjs');
|
|
2
|
+
const require_path_helpers = require('../utils/path-helpers.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/virtual/code-generator.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate complete config module
|
|
7
|
+
* Exports serverUrl and cacheDir constants
|
|
8
|
+
*/
|
|
9
|
+
function generateConfigModule(config) {
|
|
10
|
+
const serverUrl = config.dev.translationServerUrl;
|
|
11
|
+
const cacheDir = require_path_helpers.getCacheDir(config);
|
|
12
|
+
return `export const serverUrl = ${JSON.stringify(serverUrl)};
|
|
13
|
+
export const cacheDir = ${JSON.stringify(cacheDir)};
|
|
14
|
+
export const sourceLocale = ${JSON.stringify(config.sourceLocale)};
|
|
15
|
+
export const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};
|
|
16
|
+
export const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};
|
|
17
|
+
export const apiBaseUrl = ${JSON.stringify(config.apiBaseUrl || require_api_client.DEFAULT_API_BASE_URL)};
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate complete locale/server module
|
|
22
|
+
* Exports async getServerLocale() function
|
|
23
|
+
*/
|
|
24
|
+
function generateServerLocaleModule(config) {
|
|
25
|
+
return `
|
|
26
|
+
import { createNextCookieLocaleResolver } from '@weglot/translate-react/react/next';
|
|
27
|
+
export const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate complete locale/client module
|
|
32
|
+
* Exports getClientLocale() and persistLocale() functions
|
|
33
|
+
*/
|
|
34
|
+
function generateClientLocaleModule(config) {
|
|
35
|
+
const cookieName = config.localePersistence.config.name;
|
|
36
|
+
const maxAge = config.localePersistence.config.maxAge;
|
|
37
|
+
return `
|
|
38
|
+
export function getClientLocale() {
|
|
39
|
+
if (typeof document !== 'undefined') {
|
|
40
|
+
const match = document.cookie.match(/${cookieName}=([^;]+)/);
|
|
41
|
+
if (match) return match[1];
|
|
42
|
+
}
|
|
43
|
+
// Fallback to source locale
|
|
44
|
+
return ${JSON.stringify(config.sourceLocale)};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function persistLocale(locale) {
|
|
48
|
+
if (typeof document !== 'undefined') {
|
|
49
|
+
document.cookie = \`${cookieName}=\${locale}; path=/; max-age=${maxAge}\`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.generateClientLocaleModule = generateClientLocaleModule;
|
|
57
|
+
exports.generateConfigModule = generateConfigModule;
|
|
58
|
+
exports.generateServerLocaleModule = generateServerLocaleModule;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DEFAULT_API_BASE_URL } from "../translators/weglot/api-client.mjs";
|
|
2
|
+
import { getCacheDir } from "../utils/path-helpers.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/virtual/code-generator.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate complete config module
|
|
7
|
+
* Exports serverUrl and cacheDir constants
|
|
8
|
+
*/
|
|
9
|
+
function generateConfigModule(config) {
|
|
10
|
+
const serverUrl = config.dev.translationServerUrl;
|
|
11
|
+
const cacheDir = getCacheDir(config);
|
|
12
|
+
return `export const serverUrl = ${JSON.stringify(serverUrl)};
|
|
13
|
+
export const cacheDir = ${JSON.stringify(cacheDir)};
|
|
14
|
+
export const sourceLocale = ${JSON.stringify(config.sourceLocale)};
|
|
15
|
+
export const apiLocales = ${JSON.stringify(config.apiLocales ?? {})};
|
|
16
|
+
export const translationEngine = ${JSON.stringify(config.translationEngine ?? 3)};
|
|
17
|
+
export const apiBaseUrl = ${JSON.stringify(config.apiBaseUrl || DEFAULT_API_BASE_URL)};
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate complete locale/server module
|
|
22
|
+
* Exports async getServerLocale() function
|
|
23
|
+
*/
|
|
24
|
+
function generateServerLocaleModule(config) {
|
|
25
|
+
return `
|
|
26
|
+
import { createNextCookieLocaleResolver } from '@weglot/translate-react/react/next';
|
|
27
|
+
export const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate complete locale/client module
|
|
32
|
+
* Exports getClientLocale() and persistLocale() functions
|
|
33
|
+
*/
|
|
34
|
+
function generateClientLocaleModule(config) {
|
|
35
|
+
const cookieName = config.localePersistence.config.name;
|
|
36
|
+
const maxAge = config.localePersistence.config.maxAge;
|
|
37
|
+
return `
|
|
38
|
+
export function getClientLocale() {
|
|
39
|
+
if (typeof document !== 'undefined') {
|
|
40
|
+
const match = document.cookie.match(/${cookieName}=([^;]+)/);
|
|
41
|
+
if (match) return match[1];
|
|
42
|
+
}
|
|
43
|
+
// Fallback to source locale
|
|
44
|
+
return ${JSON.stringify(config.sourceLocale)};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function persistLocale(locale) {
|
|
48
|
+
if (typeof document !== 'undefined') {
|
|
49
|
+
document.cookie = \`${cookieName}=\${locale}; path=/; max-age=${maxAge}\`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { generateClientLocaleModule, generateConfigModule, generateServerLocaleModule };
|
|
57
|
+
//# 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\";\nimport { DEFAULT_API_BASE_URL } from \"../translators/weglot/api-client\";\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)};\nexport const apiBaseUrl = ${JSON.stringify(config.apiBaseUrl || DEFAULT_API_BASE_URL)};\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":";;;;;;;;AAgBA,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;4BACrD,KAAK,UAAU,OAAO,cAAc,qBAAqB,CAAC;;;;;;;AAQtF,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,19 @@
|
|
|
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
|
+
/** The project's regional API host. */
|
|
11
|
+
const apiBaseUrl = "https://api.weglot.com";
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.apiBaseUrl = apiBaseUrl;
|
|
15
|
+
exports.apiLocales = apiLocales;
|
|
16
|
+
exports.cacheDir = cacheDir;
|
|
17
|
+
exports.serverUrl = serverUrl;
|
|
18
|
+
exports.sourceLocale = sourceLocale;
|
|
19
|
+
exports.translationEngine = translationEngine;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
/** The project's regional API host. */
|
|
12
|
+
declare const apiBaseUrl: string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { apiBaseUrl, apiLocales, cacheDir, serverUrl, sourceLocale, translationEngine };
|
|
15
|
+
//# sourceMappingURL=config.d.cts.map
|