zintljs 0.1.0-alpha.7
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 +21 -0
- package/README.md +253 -0
- package/dist/assemble-DJKgHgSM.mjs +348 -0
- package/dist/facets.d.mts +56 -0
- package/dist/facets.mjs +3 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/macro.d.mts +148 -0
- package/dist/macro.mjs +130 -0
- package/dist/types-DTRiQkFi.d.mts +243 -0
- package/dist/vite.d.mts +43 -0
- package/dist/vite.mjs +1056 -0
- package/package.json +82 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { t as FacetsInput } from "./types-DTRiQkFi.mjs";
|
|
2
|
+
import { AssetTargetConfig, BaseFacet, BundlerFacet, CapabilityFlags, CatalogManager, CodegenFacet, CompiledExtractionState, CompilerCapabilities, CompilerCapabilities as CompilerCapabilities$1, CompilerContext, CompilerSystemView, ContentFacet, ExtractionContribution, ExtractionFacet, FacetConcern, HtmlProjectionPayload, IOManager, LocaleDetectionContext, MultiplexDetectionContext, MustacheRule, RuntimeFacet, SfcBlockRule, SfcRule, SsrFacet, SsrWrapParams, SuppressionRule, TagMapEntry, TargetDescriptor, TargetPlugin, ZintlFacet, ZintlFacet as ZintlFacet$1 } from "@zintljs/compiler";
|
|
3
|
+
export * from "@zintljs/compiler/facets";
|
|
4
|
+
//#region src/facets/resolve.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a flat list of facet objects into the capabilities handed to the compiler.
|
|
7
|
+
*/
|
|
8
|
+
declare function resolveFacets(facets?: ZintlFacet$1[]): CompilerCapabilities$1;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/facets/detect.d.ts
|
|
11
|
+
type Framework = "react" | "vue" | "svelte" | "nextjs";
|
|
12
|
+
/** The framework assumed when detection finds nothing. */
|
|
13
|
+
declare const FALLBACK_FRAMEWORK: Framework;
|
|
14
|
+
interface DetectionInput {
|
|
15
|
+
/** Plugin names from the resolved bundler config. */
|
|
16
|
+
pluginNames?: string[];
|
|
17
|
+
/** Project root, scanned for a package.json. */
|
|
18
|
+
root?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Detect frameworks from bundler plugin names and the project's package.json.
|
|
22
|
+
*
|
|
23
|
+
* Returns an empty array when nothing matched — callers decide whether to apply
|
|
24
|
+
* {@link FALLBACK_FRAMEWORK}, so the guess stays visible rather than buried.
|
|
25
|
+
*/
|
|
26
|
+
declare function detectFrameworks({ pluginNames, root }: DetectionInput): Framework[];
|
|
27
|
+
/** Detect, falling back to {@link FALLBACK_FRAMEWORK} when nothing matched. */
|
|
28
|
+
declare function detectFrameworksOrFallback(input: DetectionInput): Framework[];
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/facets/assemble.d.ts
|
|
31
|
+
interface AssembleInput {
|
|
32
|
+
/** Frameworks detected for this project. */
|
|
33
|
+
frameworks: Framework[];
|
|
34
|
+
/** Whether this build targets SSR. */
|
|
35
|
+
ssr?: boolean;
|
|
36
|
+
/** User-declared facets; defaults to `["auto"]`. */
|
|
37
|
+
facets?: FacetsInput[];
|
|
38
|
+
/** Asset facet configuration drawn from plugin options. */
|
|
39
|
+
assetsTarget?: (string | AssetTargetConfig)[];
|
|
40
|
+
virtualAssets?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The facet set that `"auto"` expands to.
|
|
44
|
+
*/
|
|
45
|
+
declare function autoFacets(input: AssembleInput): ZintlFacet$1[];
|
|
46
|
+
/**
|
|
47
|
+
* Flatten user facet input, expanding `"auto"`, thunks and nested arrays.
|
|
48
|
+
*/
|
|
49
|
+
declare function flattenFacets(inputs: FacetsInput[], auto: ZintlFacet$1[]): ZintlFacet$1[];
|
|
50
|
+
/**
|
|
51
|
+
* The complete facet list for a project: user input (with `"auto"` expanded)
|
|
52
|
+
* plus the always-injected Vite bundler facet.
|
|
53
|
+
*/
|
|
54
|
+
declare function assembleFacets(input: AssembleInput): ZintlFacet$1[];
|
|
55
|
+
//#endregion
|
|
56
|
+
export { type BaseFacet, type BundlerFacet, type CapabilityFlags, type CatalogManager, type CodegenFacet, type CompiledExtractionState, type CompilerCapabilities, type CompilerContext, type CompilerSystemView, type ContentFacet, type ExtractionContribution, type ExtractionFacet, FALLBACK_FRAMEWORK, type FacetConcern, type Framework, type HtmlProjectionPayload, type IOManager, type LocaleDetectionContext, type MultiplexDetectionContext, type MustacheRule, type RuntimeFacet, type SfcBlockRule, type SfcRule, type SsrFacet, type SsrWrapParams, type SuppressionRule, type TagMapEntry, type TargetDescriptor, type TargetPlugin, type ZintlFacet, assembleFacets, autoFacets, detectFrameworks, detectFrameworksOrFallback, flattenFacets, resolveFacets };
|
package/dist/facets.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as detectFrameworks, i as FALLBACK_FRAMEWORK, n as autoFacets, o as detectFrameworksOrFallback, r as flattenFacets, s as resolveFacets, t as assembleFacets } from "./assemble-DJKgHgSM.mjs";
|
|
2
|
+
export * from "@zintljs/compiler/facets";
|
|
3
|
+
export { FALLBACK_FRAMEWORK, assembleFacets, autoFacets, detectFrameworks, detectFrameworksOrFallback, flattenFacets, resolveFacets };
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
package/dist/macro.d.mts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
//#region src/macro.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module zintl/macro
|
|
4
|
+
*
|
|
5
|
+
* The macro facade — everything you write in application code.
|
|
6
|
+
*
|
|
7
|
+
* These are compiler markers, not a runtime library. At build time the Zintl
|
|
8
|
+
* plugin rewrites each call and each import in this module to its real runtime
|
|
9
|
+
* equivalent, which is why the bodies you see here look like no-ops. They are:
|
|
10
|
+
* the bodies are the fallback for an untransformed environment (a plain `tsc`
|
|
11
|
+
* run, a unit test without the plugin), where the app must still work in the
|
|
12
|
+
* source locale rather than crash.
|
|
13
|
+
*
|
|
14
|
+
* The plugin itself lives at `zintl/vite`, not here.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The i18n handle a resolved {@link zintl} anchor gives you.
|
|
18
|
+
*
|
|
19
|
+
* Rarely needed — most apps `await zintl(locale)` for the side effect and read
|
|
20
|
+
* the locale later with {@link getLocale}. It is there for the cases where you
|
|
21
|
+
* want to act on the boundary you just created.
|
|
22
|
+
*/
|
|
23
|
+
interface ZintlInstance {
|
|
24
|
+
/**
|
|
25
|
+
* The locale at the moment this anchor resolved.
|
|
26
|
+
*
|
|
27
|
+
* A snapshot, not a live value: a later `setLocale` does not change it. Use
|
|
28
|
+
* {@link getLocale} for the current locale.
|
|
29
|
+
*/
|
|
30
|
+
readonly locale: string;
|
|
31
|
+
/** Log translation misses and catalog loads for this boundary. */
|
|
32
|
+
debug: boolean;
|
|
33
|
+
/** Switch the active locale, loading any catalogs it needs. */
|
|
34
|
+
setLocale(locale?: string | null): Promise<void>;
|
|
35
|
+
/** Run `listener` on every locale or catalog change. Returns an unsubscribe function. */
|
|
36
|
+
subscribe(listener: () => void): () => void;
|
|
37
|
+
/** Translate a key against this boundary. See {@link t}. */
|
|
38
|
+
t(key: string, params?: Record<string, any>): string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Declare an internationalization boundary — the trust anchor.
|
|
42
|
+
*
|
|
43
|
+
* Awaiting `zintl()` sets the active locale and loads the catalogs for every
|
|
44
|
+
* string reachable from this file. Everything downstream of it is extracted and
|
|
45
|
+
* translated with no further annotation: no wrapper functions, no key maps.
|
|
46
|
+
*
|
|
47
|
+
* Every call is an **independent** anchor with its own catalog boundary and
|
|
48
|
+
* hydration lifecycle, whether it sits at module level or inside a function. A
|
|
49
|
+
* nested call opts out of any parent context rather than inheriting it, so
|
|
50
|
+
* loading stays deterministic.
|
|
51
|
+
*
|
|
52
|
+
* What you pass decides how much work happens at runtime:
|
|
53
|
+
*
|
|
54
|
+
* - `zintl("ar")` — a static literal. The compiler inlines that catalog into the
|
|
55
|
+
* generated loader, so the boundary is ready with no network round-trip.
|
|
56
|
+
* - `zintl(userLang)` — an expression. Catalogs load lazily for whichever locale
|
|
57
|
+
* is asked for.
|
|
58
|
+
* - `zintl()` — no argument. Reads `document.documentElement.lang`.
|
|
59
|
+
* - `zintl("*")` — every locale is a valid target. Together with `zintl()`, this
|
|
60
|
+
* is what the plugin looks for when auto-detecting `multiplex` builds.
|
|
61
|
+
*
|
|
62
|
+
* @param locale - The locale to activate. Omit to read it from the document.
|
|
63
|
+
* @returns The boundary's i18n handle, once its catalogs have loaded.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { zintl } from "zintljs/macro";
|
|
68
|
+
*
|
|
69
|
+
* await zintl(new URLSearchParams(location.search).get("lang") ?? "en");
|
|
70
|
+
*
|
|
71
|
+
* // Extracted automatically — no wrapper needed.
|
|
72
|
+
* document.querySelector("#app")!.innerHTML = `<h1>Welcome back!</h1>`;
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @zintl-macro
|
|
76
|
+
*/
|
|
77
|
+
declare function zintl(_locale?: string): Promise<ZintlInstance>;
|
|
78
|
+
/**
|
|
79
|
+
* Translate an explicit key.
|
|
80
|
+
*
|
|
81
|
+
* The escape hatch, not the main road: Zintl extracts string literals, template
|
|
82
|
+
* literals, JSX and HTML on its own, so reach for `t()` only when the string is
|
|
83
|
+
* not in the source — a key assembled at runtime, or one arriving from data.
|
|
84
|
+
*
|
|
85
|
+
* `params` fills the `{name}` placeholders in a message, and feeds the plural
|
|
86
|
+
* and select branches the compiler bakes from the catalog's ZCU form. Context
|
|
87
|
+
* variables bound with `@zintl-pass` arrive the same way, which is how a target
|
|
88
|
+
* language can vary on gender or count that the source string never mentions.
|
|
89
|
+
*
|
|
90
|
+
* @param key - The message key, as it appears in the catalog.
|
|
91
|
+
* @param _params - Values for the message's placeholders and grammatical branches.
|
|
92
|
+
* @returns The translation for the active locale, or `key` itself if there is none.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* t("cart.items", { count: cart.length })
|
|
97
|
+
* t(`status.${order.state}`)
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @zintl-macro
|
|
101
|
+
*/
|
|
102
|
+
declare function t(key: string, _params?: Record<string, any>): string;
|
|
103
|
+
/**
|
|
104
|
+
* The locale currently active.
|
|
105
|
+
*
|
|
106
|
+
* The plugin rewrites this import to the real runtime binding, so it reflects
|
|
107
|
+
* the live store — including a locale set after the anchor resolved. Returns
|
|
108
|
+
* `""` when no boundary has been established yet.
|
|
109
|
+
*/
|
|
110
|
+
declare function getLocale(): string;
|
|
111
|
+
/**
|
|
112
|
+
* Switch the active locale, loading whatever catalogs it needs.
|
|
113
|
+
*
|
|
114
|
+
* Resolves once the new locale is in effect. If the catalogs are already
|
|
115
|
+
* present — inlined for a static anchor, or loaded earlier — the switch applies
|
|
116
|
+
* synchronously and subscribers see it before the promise settles.
|
|
117
|
+
*
|
|
118
|
+
* Passing `null` or `undefined` is a no-op, so a value straight from a router or
|
|
119
|
+
* a query string needs no guard.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* document.querySelector("#lang")!.addEventListener("change", (e) => {
|
|
124
|
+
* void setLocale((e.target as HTMLSelectElement).value);
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare function setLocale(_locale?: string | null): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Run `listener` whenever the locale or the loaded catalogs change.
|
|
131
|
+
*
|
|
132
|
+
* The building block for wiring Zintl into a UI framework by hand. Call the
|
|
133
|
+
* returned function to unsubscribe. Framework integrations built from the
|
|
134
|
+
* `"auto"` facets already do this for you — React components, for instance, are
|
|
135
|
+
* re-rendered through `useSyncExternalStore` without any subscription of yours.
|
|
136
|
+
*
|
|
137
|
+
* @returns An unsubscribe function.
|
|
138
|
+
*/
|
|
139
|
+
declare function subscribe(_listener: () => void): () => void;
|
|
140
|
+
/**
|
|
141
|
+
* A counter that increments on every locale or catalog change.
|
|
142
|
+
*
|
|
143
|
+
* The snapshot half of a `useSyncExternalStore`-style pairing with
|
|
144
|
+
* {@link subscribe}: compare it to know whether anything translated has moved.
|
|
145
|
+
*/
|
|
146
|
+
declare function getStoreVersion(): number;
|
|
147
|
+
//#endregion
|
|
148
|
+
export { ZintlInstance, getLocale, getStoreVersion, setLocale, subscribe, t, zintl };
|
package/dist/macro.mjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/macro.ts
|
|
2
|
+
/**
|
|
3
|
+
* Declare an internationalization boundary — the trust anchor.
|
|
4
|
+
*
|
|
5
|
+
* Awaiting `zintl()` sets the active locale and loads the catalogs for every
|
|
6
|
+
* string reachable from this file. Everything downstream of it is extracted and
|
|
7
|
+
* translated with no further annotation: no wrapper functions, no key maps.
|
|
8
|
+
*
|
|
9
|
+
* Every call is an **independent** anchor with its own catalog boundary and
|
|
10
|
+
* hydration lifecycle, whether it sits at module level or inside a function. A
|
|
11
|
+
* nested call opts out of any parent context rather than inheriting it, so
|
|
12
|
+
* loading stays deterministic.
|
|
13
|
+
*
|
|
14
|
+
* What you pass decides how much work happens at runtime:
|
|
15
|
+
*
|
|
16
|
+
* - `zintl("ar")` — a static literal. The compiler inlines that catalog into the
|
|
17
|
+
* generated loader, so the boundary is ready with no network round-trip.
|
|
18
|
+
* - `zintl(userLang)` — an expression. Catalogs load lazily for whichever locale
|
|
19
|
+
* is asked for.
|
|
20
|
+
* - `zintl()` — no argument. Reads `document.documentElement.lang`.
|
|
21
|
+
* - `zintl("*")` — every locale is a valid target. Together with `zintl()`, this
|
|
22
|
+
* is what the plugin looks for when auto-detecting `multiplex` builds.
|
|
23
|
+
*
|
|
24
|
+
* @param locale - The locale to activate. Omit to read it from the document.
|
|
25
|
+
* @returns The boundary's i18n handle, once its catalogs have loaded.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { zintl } from "zintljs/macro";
|
|
30
|
+
*
|
|
31
|
+
* await zintl(new URLSearchParams(location.search).get("lang") ?? "en");
|
|
32
|
+
*
|
|
33
|
+
* // Extracted automatically — no wrapper needed.
|
|
34
|
+
* document.querySelector("#app")!.innerHTML = `<h1>Welcome back!</h1>`;
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @zintl-macro
|
|
38
|
+
*/
|
|
39
|
+
async function zintl(_locale) {
|
|
40
|
+
return {
|
|
41
|
+
locale: "",
|
|
42
|
+
debug: false,
|
|
43
|
+
setLocale: () => Promise.resolve(),
|
|
44
|
+
subscribe: () => () => {},
|
|
45
|
+
t: (key) => key
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Translate an explicit key.
|
|
50
|
+
*
|
|
51
|
+
* The escape hatch, not the main road: Zintl extracts string literals, template
|
|
52
|
+
* literals, JSX and HTML on its own, so reach for `t()` only when the string is
|
|
53
|
+
* not in the source — a key assembled at runtime, or one arriving from data.
|
|
54
|
+
*
|
|
55
|
+
* `params` fills the `{name}` placeholders in a message, and feeds the plural
|
|
56
|
+
* and select branches the compiler bakes from the catalog's ZCU form. Context
|
|
57
|
+
* variables bound with `@zintl-pass` arrive the same way, which is how a target
|
|
58
|
+
* language can vary on gender or count that the source string never mentions.
|
|
59
|
+
*
|
|
60
|
+
* @param key - The message key, as it appears in the catalog.
|
|
61
|
+
* @param _params - Values for the message's placeholders and grammatical branches.
|
|
62
|
+
* @returns The translation for the active locale, or `key` itself if there is none.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* t("cart.items", { count: cart.length })
|
|
67
|
+
* t(`status.${order.state}`)
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @zintl-macro
|
|
71
|
+
*/
|
|
72
|
+
function t(key, _params = {}) {
|
|
73
|
+
return key;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The locale currently active.
|
|
77
|
+
*
|
|
78
|
+
* The plugin rewrites this import to the real runtime binding, so it reflects
|
|
79
|
+
* the live store — including a locale set after the anchor resolved. Returns
|
|
80
|
+
* `""` when no boundary has been established yet.
|
|
81
|
+
*/
|
|
82
|
+
function getLocale() {
|
|
83
|
+
if (typeof globalThis !== "undefined" && globalThis.__zintl_active) return globalThis.__zintl_active.locale;
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Switch the active locale, loading whatever catalogs it needs.
|
|
88
|
+
*
|
|
89
|
+
* Resolves once the new locale is in effect. If the catalogs are already
|
|
90
|
+
* present — inlined for a static anchor, or loaded earlier — the switch applies
|
|
91
|
+
* synchronously and subscribers see it before the promise settles.
|
|
92
|
+
*
|
|
93
|
+
* Passing `null` or `undefined` is a no-op, so a value straight from a router or
|
|
94
|
+
* a query string needs no guard.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* document.querySelector("#lang")!.addEventListener("change", (e) => {
|
|
99
|
+
* void setLocale((e.target as HTMLSelectElement).value);
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
function setLocale(_locale) {
|
|
104
|
+
return Promise.resolve();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Run `listener` whenever the locale or the loaded catalogs change.
|
|
108
|
+
*
|
|
109
|
+
* The building block for wiring Zintl into a UI framework by hand. Call the
|
|
110
|
+
* returned function to unsubscribe. Framework integrations built from the
|
|
111
|
+
* `"auto"` facets already do this for you — React components, for instance, are
|
|
112
|
+
* re-rendered through `useSyncExternalStore` without any subscription of yours.
|
|
113
|
+
*
|
|
114
|
+
* @returns An unsubscribe function.
|
|
115
|
+
*/
|
|
116
|
+
function subscribe(_listener) {
|
|
117
|
+
return () => {};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A counter that increments on every locale or catalog change.
|
|
121
|
+
*
|
|
122
|
+
* The snapshot half of a `useSyncExternalStore`-style pairing with
|
|
123
|
+
* {@link subscribe}: compare it to know whether anything translated has moved.
|
|
124
|
+
*/
|
|
125
|
+
function getStoreVersion() {
|
|
126
|
+
if (typeof globalThis !== "undefined" && globalThis.__zintl_active) return globalThis.__zintl_active.version;
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { getLocale, getStoreVersion, setLocale, subscribe, t, zintl };
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { AssetTargetConfig, CatalogFormatContext, LogLevel, ZintlFacet } from "@zintljs/compiler";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* What a user may write in `facets: [...]`.
|
|
5
|
+
*
|
|
6
|
+
* Accepts the `"auto"` sentinel (expanded by framework detection), bare facets,
|
|
7
|
+
* arrays, and thunks — all flattened during assembly before resolution.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* zintl({ facets: ["auto", myFacet()] }) // keep the defaults, add one
|
|
12
|
+
* zintl({ facets: [reactFacet(), ssrFacet()] }) // opt out of "auto" entirely
|
|
13
|
+
* zintl({ facets: [() => expensiveFacet()] }) // thunk, evaluated at assembly
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
type FacetsInput = "auto" | ZintlFacet | ZintlFacet[] | (() => ZintlFacet | ZintlFacet[]) | FacetsInput[];
|
|
17
|
+
/**
|
|
18
|
+
* Options for the Zintl Vite plugin.
|
|
19
|
+
*
|
|
20
|
+
* Every field is optional; the defaults are tuned for a typical app, and a
|
|
21
|
+
* working setup is usually just `locales`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // vite.config.ts
|
|
26
|
+
* import { defineConfig } from "vite";
|
|
27
|
+
* import zintl from "zintljs/vite";
|
|
28
|
+
*
|
|
29
|
+
* export default defineConfig({
|
|
30
|
+
* plugins: [zintl({ locales: ["en", "ar", "fr"] })],
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
interface Options {
|
|
35
|
+
/**
|
|
36
|
+
* The locale your source code is written in.
|
|
37
|
+
*
|
|
38
|
+
* This locale is **diskless**. Zintl never writes a catalog for it: a file of
|
|
39
|
+
* `{ "Hello": "Hello" }` carries no information, so the compiler virtualizes
|
|
40
|
+
* it from the extraction manifest instead. You will not find it in
|
|
41
|
+
* {@link Options.outputDir | `outputDir`}, and that is not a bug.
|
|
42
|
+
*
|
|
43
|
+
* @default "en"
|
|
44
|
+
*/
|
|
45
|
+
sourceLocale?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Every locale the app ships, including {@link Options.sourceLocale | `sourceLocale`}.
|
|
48
|
+
*
|
|
49
|
+
* Each entry gets a catalog written under {@link Options.outputDir | `outputDir`}
|
|
50
|
+
* (except the source locale), and becomes a value you can pass to `zintl()`.
|
|
51
|
+
*
|
|
52
|
+
* @default ["en"]
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* locales: ["en", "ar", "fr"]
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
locales?: string[];
|
|
59
|
+
/**
|
|
60
|
+
* Where translation catalogs are written, relative to the project root.
|
|
61
|
+
*
|
|
62
|
+
* These files are yours: commit them, edit them, hand them to translators.
|
|
63
|
+
* The compiler writes new keys in and reconciles renames, but never discards
|
|
64
|
+
* a translation you have written (see {@link Options.prune | `prune`}).
|
|
65
|
+
*
|
|
66
|
+
* @default "./zintl"
|
|
67
|
+
*/
|
|
68
|
+
outputDir?: string;
|
|
69
|
+
/**
|
|
70
|
+
* How catalog files are named inside {@link Options.outputDir | `outputDir`}.
|
|
71
|
+
*
|
|
72
|
+
* A token string, or a function returning a path relative to `outputDir`.
|
|
73
|
+
* Supported tokens:
|
|
74
|
+
*
|
|
75
|
+
* - `[locale]` — the target locale, e.g. `ar`
|
|
76
|
+
* - `[path]` — the boundary's source path, e.g. `src/pages/Home.ts`
|
|
77
|
+
* - `[dir]` — its directory, e.g. `src/pages` (empty for the root)
|
|
78
|
+
* - `[name]` — its filename with extension, e.g. `Home.ts`
|
|
79
|
+
* - `[func]` — the enclosing function, for anchors nested inside one (empty otherwise)
|
|
80
|
+
* - `[bId]` — the full boundary id; `:` and `/` become `_`
|
|
81
|
+
* - `[hash]` — the boundary's stable short hash
|
|
82
|
+
*
|
|
83
|
+
* Grouping many boundaries into one file is supported: point several at the
|
|
84
|
+
* same name and they are merged.
|
|
85
|
+
*
|
|
86
|
+
* @default `<path>[.<func>].<locale>.json`, e.g. `src/pages/Home.ts.ar.json`
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* catalogFormat: "[locale]/[dir]/[name].json" // ar/src/pages/Home.ts.json
|
|
90
|
+
* catalogFormat: "[locale].json" // one file per locale
|
|
91
|
+
* catalogFormat: ({ locale, name }) => `${locale}/${name}.json`
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
catalogFormat?: string | ((ctx: CatalogFormatContext) => string);
|
|
95
|
+
/**
|
|
96
|
+
* How similar an edited string must be to a remembered one before its
|
|
97
|
+
* translation is carried forward instead of being dropped.
|
|
98
|
+
*
|
|
99
|
+
* A ratio from `0` to `1`. Fixing a typo in a source string is the case this
|
|
100
|
+
* exists for: the translation moves to the new key and no translator is
|
|
101
|
+
* involved. Raising it toward `1` demands near-identical strings and loses
|
|
102
|
+
* more translations to small edits; lowering it risks a translation landing on
|
|
103
|
+
* an unrelated string.
|
|
104
|
+
*
|
|
105
|
+
* Escape hatch — the default is usually right, and a threshold cannot fix a
|
|
106
|
+
* string that was genuinely rewritten.
|
|
107
|
+
*
|
|
108
|
+
* @default 0.6
|
|
109
|
+
*/
|
|
110
|
+
similarityThreshold?: number;
|
|
111
|
+
/**
|
|
112
|
+
* How much Zintl prints.
|
|
113
|
+
*
|
|
114
|
+
* The `ZINTL_LOG_LEVEL` environment variable overrides this when set. Under
|
|
115
|
+
* test (`NODE_ENV=test` or Vitest) the effective level is `"silent"` unless
|
|
116
|
+
* {@link Options.debug | `debug`} is on.
|
|
117
|
+
*
|
|
118
|
+
* @default Vite's own `logLevel`, falling back to `"info"`
|
|
119
|
+
*/
|
|
120
|
+
logLevel?: LogLevel;
|
|
121
|
+
/**
|
|
122
|
+
* Where the compiler keeps its own bookkeeping — the extraction manifest,
|
|
123
|
+
* boundary graph and translation hive.
|
|
124
|
+
*
|
|
125
|
+
* Build artifacts, not source. They live outside your repo by default and you
|
|
126
|
+
* should not need to move them.
|
|
127
|
+
*
|
|
128
|
+
* Escape hatch — mainly useful for test harnesses and sandboxes.
|
|
129
|
+
*
|
|
130
|
+
* @default `<root>/node_modules/.zintl`
|
|
131
|
+
*/
|
|
132
|
+
metadataDir?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Verbose compiler tracing.
|
|
135
|
+
*
|
|
136
|
+
* `true` enables everything. A **string** is a scope filter, matched against
|
|
137
|
+
* the prefix of each debug channel, so you can watch one subsystem instead of
|
|
138
|
+
* the whole pipeline. The `DEBUG` environment variable (`DEBUG=zintl:*`,
|
|
139
|
+
* `DEBUG=*`, or `DEBUG=zintl:<prefix>`) turns the same tracing on.
|
|
140
|
+
*
|
|
141
|
+
* @default false
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* debug: true // everything
|
|
145
|
+
* debug: "boundary" // only the boundary-graph channels
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
debug?: boolean | string;
|
|
149
|
+
/**
|
|
150
|
+
* Remove keys from catalogs once no source string produces them.
|
|
151
|
+
*
|
|
152
|
+
* On by default, so deleting a component takes its dead keys with it. Turn it
|
|
153
|
+
* off if catalogs are edited by a system that expects keys to survive their
|
|
154
|
+
* source — the cost is that catalogs only ever grow.
|
|
155
|
+
*
|
|
156
|
+
* Pruning runs after reconciliation, so a renamed or retyped string is carried
|
|
157
|
+
* forward rather than pruned and re-added.
|
|
158
|
+
*
|
|
159
|
+
* @default true
|
|
160
|
+
*/
|
|
161
|
+
prune?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Verify on-disk catalogs against the extraction manifest and repair drift.
|
|
164
|
+
*
|
|
165
|
+
* The check that catches a hand-edited catalog that no longer matches the
|
|
166
|
+
* code. It costs a pass over every catalog, which is why it is on for builds
|
|
167
|
+
* and off while serving.
|
|
168
|
+
*
|
|
169
|
+
* Escape hatch — set `false` to skip it in a slow CI build, `true` to catch
|
|
170
|
+
* drift during development.
|
|
171
|
+
*
|
|
172
|
+
* @default `true` for `vite build`, `false` for `vite dev`
|
|
173
|
+
*/
|
|
174
|
+
verifyIntegrity?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Build every locale as its own set of HTML entries, instead of one app that
|
|
177
|
+
* loads catalogs at runtime.
|
|
178
|
+
*
|
|
179
|
+
* Detected automatically: an anchor written `zintl()` or `zintl("*")` defers
|
|
180
|
+
* the locale to the document or the URL, which is exactly the multiplex shape,
|
|
181
|
+
* so the plugin scans your entries and decides.
|
|
182
|
+
*
|
|
183
|
+
* Escape hatch — set it explicitly only when the scan gets it wrong.
|
|
184
|
+
*
|
|
185
|
+
* @default auto-detected from your entry files
|
|
186
|
+
*/
|
|
187
|
+
multiplex?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Static content files to localize alongside your code, as extensions or
|
|
190
|
+
* glob configs.
|
|
191
|
+
*
|
|
192
|
+
* A bare extension expands to `**\/*.<ext>`. When a target's
|
|
193
|
+
* {@link AssetTargetConfig.strategy | `strategy`} is not given it is inferred
|
|
194
|
+
* from the extension: `.md`/`.mdx` merge frontmatter, `.txt` passes through as
|
|
195
|
+
* text, anything else is copied as binary.
|
|
196
|
+
*
|
|
197
|
+
* @default ["md", "txt"]
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* assetsTarget: ["md", "txt", "mdx"]
|
|
201
|
+
* assetsTarget: [{ targetPattern: "content/**\/*.md", outputPattern: "[locale]/[dir]/[name][ext]" }]
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
assetsTarget?: (string | AssetTargetConfig)[];
|
|
205
|
+
/**
|
|
206
|
+
* Serve localized assets from virtual modules instead of writing them to disk.
|
|
207
|
+
*
|
|
208
|
+
* With the default (`false`), a localized copy of each matched asset is
|
|
209
|
+
* written next to your catalogs, so you can read and edit the translated
|
|
210
|
+
* Markdown directly. With `true` nothing is written: the localized content is
|
|
211
|
+
* kept in the translation hive and served through virtual modules, which keeps
|
|
212
|
+
* the working tree clean at the cost of not being able to edit the output as a
|
|
213
|
+
* file.
|
|
214
|
+
*
|
|
215
|
+
* @default false
|
|
216
|
+
*/
|
|
217
|
+
virtualAssets?: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Which capabilities the compiler is built with — framework support, SSR,
|
|
220
|
+
* client locale sync, asset handling.
|
|
221
|
+
*
|
|
222
|
+
* `"auto"` covers almost every project. It detects your framework from the
|
|
223
|
+
* Vite plugins and `package.json`, then adds the baselines: vanilla DOM and
|
|
224
|
+
* HTML extraction, static assets, client-side locale sync for SPAs, and SSR
|
|
225
|
+
* wrapping for SSR builds. The Vite bundler facet is always appended and
|
|
226
|
+
* cannot be opted out of.
|
|
227
|
+
*
|
|
228
|
+
* Listing facets without `"auto"` opts out of all of that and gives you
|
|
229
|
+
* exactly what you name. Two facets that claim the same file extension, or
|
|
230
|
+
* that provide the same hook at the same priority, are a hard error rather
|
|
231
|
+
* than a silent winner.
|
|
232
|
+
*
|
|
233
|
+
* @default ["auto"]
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* facets: ["auto", myMarkdownFacet()] // defaults plus your own
|
|
237
|
+
* facets: [reactFacet(), ssrFacet()] // exactly these, nothing implicit
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
facets?: FacetsInput[];
|
|
241
|
+
}
|
|
242
|
+
//#endregion
|
|
243
|
+
export { Options as n, FacetsInput as t };
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { n as Options, t as FacetsInput } from "./types-DTRiQkFi.mjs";
|
|
2
|
+
import { AssetMergeStrategy, AssetTargetConfig, CatalogFormatContext, LogLevel } from "@zintljs/compiler";
|
|
3
|
+
//#region src/vite.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Zintl Vite plugin.
|
|
6
|
+
*
|
|
7
|
+
* Add it once, and Zintl takes over internationalization from there: it
|
|
8
|
+
* extracts the strings reachable from every `zintl()` anchor, writes a catalog
|
|
9
|
+
* per locale into {@link Options.outputDir | `outputDir`}, splits those catalogs
|
|
10
|
+
* along your bundler's own code-splitting boundaries, and rewrites the macros
|
|
11
|
+
* into a runtime with no message parser shipped to the client.
|
|
12
|
+
*
|
|
13
|
+
* Returns two Vite plugins — a `pre` pass that localizes HTML entries before
|
|
14
|
+
* anything else touches them, and the main `zintl` plugin. Pass the array
|
|
15
|
+
* straight to `plugins`; Vite flattens it.
|
|
16
|
+
*
|
|
17
|
+
* Catalogs are written for you but owned by you: edit them, commit them, hand
|
|
18
|
+
* them to translators. Renamed and lightly edited source strings carry their
|
|
19
|
+
* translations forward instead of resetting (see
|
|
20
|
+
* {@link Options.similarityThreshold | `similarityThreshold`}).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // vite.config.ts
|
|
25
|
+
* import { defineConfig } from "vite";
|
|
26
|
+
* import zintl from "zintljs/vite";
|
|
27
|
+
*
|
|
28
|
+
* export default defineConfig({
|
|
29
|
+
* plugins: [
|
|
30
|
+
* zintl({
|
|
31
|
+
* sourceLocale: "en",
|
|
32
|
+
* locales: ["en", "ar", "fr"],
|
|
33
|
+
* outputDir: "./src/locales",
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see {@link Options} for every option and its default.
|
|
40
|
+
*/
|
|
41
|
+
declare const vite: (options: Options) => import("vite").Plugin<any>[];
|
|
42
|
+
//#endregion
|
|
43
|
+
export { type AssetMergeStrategy, type AssetTargetConfig, type CatalogFormatContext, type FacetsInput, type LogLevel, type Options, type Options as ZintlOptions, vite as default, vite as "module.exports" };
|