@fluenti/vite-plugin 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.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/client.d.ts +9 -0
- package/dist/index.cjs +273 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +965 -0
- package/dist/index.js.map +1 -0
- package/dist/src/build-transform.d.ts +18 -0
- package/dist/src/build-transform.d.ts.map +1 -0
- package/dist/src/framework-detect.d.ts +2 -0
- package/dist/src/framework-detect.d.ts.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/mode-detect.d.ts +17 -0
- package/dist/src/mode-detect.d.ts.map +1 -0
- package/dist/src/route-resolve.d.ts +41 -0
- package/dist/src/route-resolve.d.ts.map +1 -0
- package/dist/src/scope-transform.d.ts +3 -0
- package/dist/src/scope-transform.d.ts.map +1 -0
- package/dist/src/sfc-transform.d.ts +2 -0
- package/dist/src/sfc-transform.d.ts.map +1 -0
- package/dist/src/solid-jsx-transform.d.ts +6 -0
- package/dist/src/solid-jsx-transform.d.ts.map +1 -0
- package/dist/src/trans-transform.d.ts +3 -0
- package/dist/src/trans-transform.d.ts.map +1 -0
- package/dist/src/types.d.ts +15 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/virtual-modules.d.ts +33 -0
- package/dist/src/virtual-modules.d.ts.map +1 -0
- package/dist/src/vt-transform.d.ts +57 -0
- package/dist/src/vt-transform.d.ts.map +1 -0
- package/dist/tests/build-transform.test.d.ts +2 -0
- package/dist/tests/build-transform.test.d.ts.map +1 -0
- package/dist/tests/mode-detect.test.d.ts +2 -0
- package/dist/tests/mode-detect.test.d.ts.map +1 -0
- package/dist/tests/per-route-splitting.test.d.ts +2 -0
- package/dist/tests/per-route-splitting.test.d.ts.map +1 -0
- package/dist/tests/route-resolve.test.d.ts +2 -0
- package/dist/tests/route-resolve.test.d.ts.map +1 -0
- package/dist/tests/scope-transform.test.d.ts +2 -0
- package/dist/tests/scope-transform.test.d.ts.map +1 -0
- package/dist/tests/trans-transform.test.d.ts +2 -0
- package/dist/tests/trans-transform.test.d.ts.map +1 -0
- package/dist/tests/virtual-modules.test.d.ts +2 -0
- package/dist/tests/virtual-modules.test.d.ts.map +1 -0
- package/dist/tests/vite-plugin.test.d.ts +2 -0
- package/dist/tests/vite-plugin.test.d.ts.map +1 -0
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Fluenti Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# @fluenti/vite-plugin
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@fluenti/vite-plugin)
|
|
4
|
+
[](https://bundlephobia.com/package/@fluenti/vite-plugin)
|
|
5
|
+
[](https://github.com/usefluenti/fluenti/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
**The build-time engine behind Fluenti.** This plugin compiles away i18n at build time so your production bundle ships zero runtime interpretation overhead. It uses internal virtual modules to wire locale chunks automatically, so app code can stay on Fluenti's public authoring and runtime APIs.
|
|
8
|
+
|
|
9
|
+
## How It Works
|
|
10
|
+
|
|
11
|
+
Traditional i18n libraries parse and evaluate message strings at runtime. Fluenti takes a different approach: **everything happens at build time**.
|
|
12
|
+
|
|
13
|
+
During Vite's transform pipeline, `@fluenti/vite-plugin` rewrites your i18n patterns directly in the AST:
|
|
14
|
+
|
|
15
|
+
- **`v-t` directive** is a Vue compiler `nodeTransform`, not a runtime directive. It rewrites `<h1 v-t>Hello</h1>` into `<h1>{{ $t('abc123') }}</h1>` during template compilation.
|
|
16
|
+
- **`<Trans>`, `<Plural>`, `<Select>` components** are compiled into optimized render calls -- no component overhead at runtime.
|
|
17
|
+
- **Direct-import `t`** -- `import { t } from '@fluenti/react' | '@fluenti/vue' | '@fluenti/solid'` is the primary compile-time path
|
|
18
|
+
|
|
19
|
+
The result: your users get fully resolved translations with the same performance as hardcoded strings.
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @fluenti/vite-plugin
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Configure
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// vite.config.ts
|
|
33
|
+
import fluenti from '@fluenti/vite-plugin'
|
|
34
|
+
|
|
35
|
+
export default {
|
|
36
|
+
plugins: [
|
|
37
|
+
fluenti({
|
|
38
|
+
framework: 'vue', // 'vue' | 'react' | 'solid' | 'auto'
|
|
39
|
+
sourceLocale: 'en',
|
|
40
|
+
locales: ['en', 'ja', 'zh-CN'],
|
|
41
|
+
splitting: 'dynamic', // 'dynamic' | 'static' | false
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
That's it. The plugin auto-detects your framework when set to `'auto'`, manages locale chunks internally, and handles HMR during development.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
### Internal virtual modules
|
|
52
|
+
|
|
53
|
+
The plugin uses Vite virtual modules under the hood to connect transformed message lookups to the compiled locale catalogs. Those modules are internal implementation details; application code should stay on `import { t }`, `useI18n()`, `setLocale()`, `preloadLocale()`, `loadMessages()`, and framework-level `chunkLoader` APIs.
|
|
54
|
+
|
|
55
|
+
### Code Splitting
|
|
56
|
+
|
|
57
|
+
Control how message catalogs are bundled with the `splitting` option:
|
|
58
|
+
|
|
59
|
+
| Strategy | Behavior | Best For |
|
|
60
|
+
|----------|----------|----------|
|
|
61
|
+
| `'dynamic'` | Default locale loaded statically; others lazy-loaded on `switchLocale()` (default) | SPAs with multiple locales |
|
|
62
|
+
| `'static'` | All messages for a single locale inlined at build time | SSR, static site generation |
|
|
63
|
+
| `false` | All messages bundled in a single chunk | Small apps, simple setups |
|
|
64
|
+
|
|
65
|
+
### Vue Template Transform
|
|
66
|
+
|
|
67
|
+
The `v-t` directive is compiled away during Vue template compilation via a `nodeTransform` injected into `@vitejs/plugin-vue`:
|
|
68
|
+
|
|
69
|
+
```vue
|
|
70
|
+
<!-- What you write -->
|
|
71
|
+
<p v-t>Welcome back</p>
|
|
72
|
+
<img v-t.alt alt="Profile photo" />
|
|
73
|
+
<span v-t.plural="count">one apple | {count} apples</span>
|
|
74
|
+
|
|
75
|
+
<!-- What ships to the browser -->
|
|
76
|
+
<p>{{ $t('a1b2c3') }}</p>
|
|
77
|
+
<img :alt="$t('d4e5f6')" />
|
|
78
|
+
<span>{{ $t('g7h8i9', { count }) }}</span>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Rich text with nested elements is supported through `$vtRich()`, and `<Trans>`, `<Plural>`, `<Select>` components are all compiled into optimized output.
|
|
82
|
+
|
|
83
|
+
### Client-Side `t` Transform
|
|
84
|
+
|
|
85
|
+
The plugin uses **AST scope analysis** to detect Fluenti's direct-import `t` inside supported component/setup scopes and rewrites it to the runtime `useI18n()` binding:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
// What you write
|
|
89
|
+
import { t } from '@fluenti/react'
|
|
90
|
+
const msg = t`Hello, ${name}`
|
|
91
|
+
|
|
92
|
+
// What ships to the browser
|
|
93
|
+
const { t } = useI18n()
|
|
94
|
+
const msg = t('Hello, {name}', { name })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Supported direct-import shapes:
|
|
98
|
+
|
|
99
|
+
- `` t`Hello, ${name}` ``
|
|
100
|
+
- `t({ message: 'Hello {name}', context: 'hero' }, { name })`
|
|
101
|
+
|
|
102
|
+
Unsupported direct-import shapes are compile-time errors:
|
|
103
|
+
|
|
104
|
+
- `t('message.id')`
|
|
105
|
+
- `t('Hello {name}', { name })`
|
|
106
|
+
- module-top-level usage outside supported component/setup scopes
|
|
107
|
+
|
|
108
|
+
### HMR for Catalogs
|
|
109
|
+
|
|
110
|
+
During development, editing a message catalog triggers instant hot module replacement. The plugin watches your `catalogDir` and invalidates the relevant virtual modules so translations update in the browser without a full page reload.
|
|
111
|
+
|
|
112
|
+
## Configuration
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
interface FluentiPluginOptions {
|
|
116
|
+
/** Framework mode — set to 'auto' to detect from source code.
|
|
117
|
+
* @default 'auto' */
|
|
118
|
+
framework?: 'vue' | 'react' | 'solid' | 'auto'
|
|
119
|
+
|
|
120
|
+
/** Directory containing compiled message catalogs.
|
|
121
|
+
* @default 'src/locales/compiled' */
|
|
122
|
+
catalogDir?: string
|
|
123
|
+
|
|
124
|
+
/** The source (default) locale.
|
|
125
|
+
* @default 'en' */
|
|
126
|
+
sourceLocale?: string
|
|
127
|
+
|
|
128
|
+
/** All available locales.
|
|
129
|
+
* @default [sourceLocale] */
|
|
130
|
+
locales?: string[]
|
|
131
|
+
|
|
132
|
+
/** Code splitting strategy.
|
|
133
|
+
* @default 'dynamic' */
|
|
134
|
+
splitting?: 'dynamic' | 'static' | false
|
|
135
|
+
|
|
136
|
+
/** Locale used for static build-time inlining.
|
|
137
|
+
* @default sourceLocale */
|
|
138
|
+
defaultBuildLocale?: string
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Examples
|
|
144
|
+
|
|
145
|
+
**Vue with dynamic splitting:**
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import vue from '@vitejs/plugin-vue'
|
|
149
|
+
import fluenti from '@fluenti/vite-plugin'
|
|
150
|
+
|
|
151
|
+
export default {
|
|
152
|
+
plugins: [
|
|
153
|
+
vue(),
|
|
154
|
+
fluenti({
|
|
155
|
+
framework: 'vue',
|
|
156
|
+
sourceLocale: 'en',
|
|
157
|
+
locales: ['en', 'ja', 'zh-CN'],
|
|
158
|
+
splitting: 'dynamic',
|
|
159
|
+
}),
|
|
160
|
+
],
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**SSR with static inlining:**
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import fluenti from '@fluenti/vite-plugin'
|
|
168
|
+
|
|
169
|
+
export default {
|
|
170
|
+
plugins: [
|
|
171
|
+
fluenti({
|
|
172
|
+
splitting: 'static',
|
|
173
|
+
defaultBuildLocale: 'en',
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Peer Dependencies
|
|
180
|
+
|
|
181
|
+
- `vite` ^5, ^6, or ^8
|
|
182
|
+
|
|
183
|
+
## Documentation
|
|
184
|
+
|
|
185
|
+
Full documentation at [fluenti.dev](https://fluenti.dev).
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
[MIT](https://github.com/usefluenti/fluenti/blob/main/LICENSE)
|
package/client.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global tagged template function transformed by @fluenti/vite-plugin.
|
|
3
|
+
* Transforms `t`message`` into compiled i18n calls at build time.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Prefer `const { t } = useI18n()` which provides the same
|
|
6
|
+
* tagged template support without a magic global. The plugin will optimize
|
|
7
|
+
* tagged templates via AST scope analysis when `t` comes from `useI18n()`.
|
|
8
|
+
*/
|
|
9
|
+
declare function t(strings: TemplateStringsArray, ...values: unknown[]): string
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
let e=require(`node:path`),t=require(`@fluenti/core`),n=require(`@fluenti/core/internal`),r=require(`node:fs`);var i=`dev`;function a(e){i=e===`build`?`build`:`dev`}function o(e){return e?.mode===`build`||i===`build`||process.env.NODE_ENV===`production`}function s(e){return l(e,`dynamic`)}function c(e){return l(e,`static`)}function l(e,t){let r=(0,n.parseSourceModule)(e);if(!r||r.type!==`Program`)return{code:e,needsCatalogImport:!1,usedHashes:new Set};let i=u(r),a=[],o=new Set;if((0,n.walkSourceAst)(r,n=>{let r=f(e,n,i,t,o);if(r){a.push(r);return}h(n,o)}),a.length===0)return{code:e,needsCatalogImport:!1,usedHashes:o};let s=e;for(let e=a.length-1;e>=0;e--){let{start:t,end:n,replacement:r}=a[e];s=s.slice(0,t)+r+s.slice(n)}return{code:s,needsCatalogImport:!0,usedHashes:o}}function u(e){let t=new Set,r=new Set,i=new Set,a=new Set;for(let t of e.body)if(w(t))for(let e of t.specifiers){if(!T(e))continue;let t=P(e);t&&(t===`useI18n`&&r.add(e.local.name),t===`getI18n`&&i.add(e.local.name),t===`unref`&&a.add(e.local.name))}return(0,n.walkSourceAst)(e,e=>{if(!E(e)||!e.init||!D(e.id))return;if(A(e.init)&&j(e.init.callee)&&r.has(e.init.callee.name)){d(e.id,t);return}let n=e.init.type===`AwaitExpression`?e.init.argument:null;n&&A(n)&&j(n.callee)&&i.has(n.callee.name)&&d(e.id,t)}),{tracked:t,unref:a}}function d(e,t){for(let n of e.properties)!k(n)||n.computed||!j(n.key)||n.key.name!==`t`||j(n.value)&&t.add(n.value.name)}function f(e,n,r,i,a){if(!A(n)||n.start==null||n.end==null)return;let o=p(e,n,r);if(!o)return;let{catalogId:s}=o;a.add(s);let c=(0,t.hashMessage)(s),l=i===`dynamic`?`__catalog[${JSON.stringify(s)}]`:`_${c}`,u=o.valuesSource?`${l}(${o.valuesSource})`:l;return{start:n.start,end:n.end,replacement:u}}function p(e,t,n){if(t.arguments.length===0)return;let r=t.callee,i=j(r)&&(n.tracked.has(r.name)||r.name===`$t`),a=ie(r)&&!r.computed&&j(r.property)&&(r.property.name===`$t`||r.property.name===`t`&&j(r.object)&&(r.object.name===`_ctx`||r.object.name===`$setup`)),o=A(r)&&j(r.callee)&&n.unref.has(r.callee.name)&&r.arguments.length===1&&j(r.arguments[0])&&n.tracked.has(r.arguments[0].name);if(!i&&!a&&!o)return;let s=m(t.arguments[0]);if(!s)return;let c=t.arguments[1]&&t.arguments[1].start!=null&&t.arguments[1].end!=null?e.slice(t.arguments[1].start,t.arguments[1].end):void 0;return c===void 0?{catalogId:s}:{catalogId:s,valuesSource:c}}function m(e){let n=S(e);if(n!==void 0)return(0,t.hashMessage)(n);if(!O(e))return;let r,i,a;for(let t of e.properties){if(!k(t)||t.computed)continue;let e=C(t.key);if(!e)continue;let n=S(t.value);n!==void 0&&(e===`id`&&(r=n),e===`message`&&(i=n),e===`context`&&(a=n))}if(r)return r;if(i)return(0,t.hashMessage)(i,a)}function h(e,n){if(!M(e))return;let r=re(e.openingElement.name);if(r){if(r===`Trans`){let r=v(e.openingElement,`__id`)??v(e.openingElement,`id`);if(r){n.add(r);return}let i=v(e.openingElement,`__message`),a=v(e.openingElement,`context`);i&&n.add((0,t.hashMessage)(i,a));return}if(r===`Plural`){let t=g(e.openingElement);t&&n.add(t);return}if(r===`Select`){let t=_(e.openingElement);t&&n.add(t)}}}function g(e){let n=v(e,`id`);if(n)return n;let r=v(e,`context`),i=y(e,`offset`),a=[v(e,`zero`)===void 0?void 0:`=0 {${v(e,`zero`)}}`,v(e,`one`)===void 0?void 0:`one {${v(e,`one`)}}`,v(e,`two`)===void 0?void 0:`two {${v(e,`two`)}}`,v(e,`few`)===void 0?void 0:`few {${v(e,`few`)}}`,v(e,`many`)===void 0?void 0:`many {${v(e,`many`)}}`,v(e,`other`)===void 0?void 0:`other {${v(e,`other`)}}`].filter(Boolean);if(a.length!==0)return(0,t.hashMessage)(`{count, plural,${typeof i==`number`?` offset:${i}`:``} ${a.join(` `)}}`,r)}function _(e){let n=v(e,`id`);if(n)return n;let r=v(e,`context`),i=ee(e);if(!(!i||i.other===void 0))return(0,t.hashMessage)(`{value, select, ${[...Object.keys(i).filter(e=>e!==`other`).sort(),`other`].map(e=>`${e} {${i[e]}}`).join(` `)}}`,r)}function ee(e){let t=ne(e,`options`);if(t){let n=v(e,`other`);return{...t,...n===void 0?{}:{other:n}}}let n={};for(let t of e.attributes){if(!N(t))continue;let e=t.name.name;if([`value`,`id`,`context`,`comment`,`options`].includes(e))continue;let r=x(t);r!==void 0&&(n[e]=r)}return Object.keys(n).length>0?n:void 0}function te(e){if(!O(e))return;let t={};for(let n of e.properties){if(!k(n)||n.computed)return;let e=C(n.key),r=S(n.value);if(!e||r===void 0)return;t[e]=r}return t}function ne(e,t){let n=b(e,t);if(n?.value&&n.value.type===`JSXExpressionContainer`)return te(n.value.expression)}function v(e,t){return x(b(e,t))}function y(e,t){let n=b(e,t);if(!n?.value||n.value.type!==`JSXExpressionContainer`)return;let r=n.value.expression;return r.type===`NumericLiteral`?r.value:void 0}function b(e,t){return e.attributes.find(e=>N(e)&&e.name.name===t)}function x(e){if(e?.value){if(e.value.type===`StringLiteral`)return e.value.value;if(e.value.type===`JSXExpressionContainer`)return S(e.value.expression)}}function re(e){return e.type===`JSXIdentifier`?e.name:void 0}function S(e){if(e.type===`StringLiteral`)return e.value;if(e.type===`TemplateLiteral`){let t=e;if(t.expressions.length===0&&t.quasis.length===1)return t.quasis[0].value.cooked??t.quasis[0].value.raw}}function C(e){if(j(e))return e.name;if(e.type===`StringLiteral`)return e.value}function w(e){return e.type===`ImportDeclaration`}function T(e){return e.type===`ImportSpecifier`}function E(e){return e.type===`VariableDeclarator`}function D(e){return e.type===`ObjectPattern`}function O(e){return e.type===`ObjectExpression`}function k(e){return e.type===`ObjectProperty`}function A(e){return e.type===`CallExpression`}function ie(e){return e.type===`MemberExpression`}function j(e){return e?.type===`Identifier`}function M(e){return e.type===`JSXElement`}function N(e){return e.type===`JSXAttribute`}function P(e){let t=e.imported;if(t.type===`Identifier`)return t.name;if(t.type===`StringLiteral`)return t.value}function F(e,n,r){return n===`dynamic`?`import { __catalog } from 'virtual:fluenti/runtime';\n${e}`:n===`per-route`?`import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}`:`import { ${[...r].map(e=>`_${(0,t.hashMessage)(e)}`).join(`, `)} } from 'virtual:fluenti/messages';\n${e}`}var I=`virtual:fluenti/runtime`,L=`virtual:fluenti/messages`,R=`virtual:fluenti/route-runtime`,z=`\0virtual:fluenti/runtime`,B=`\0virtual:fluenti/messages`,V=`\0virtual:fluenti/route-runtime`;function H(e){if(e===I)return z;if(e===L)return B;if(e===R)return V}function U(e,t){if(e===z)return W(t);if(e===B)return G(t);if(e===V)return K(t)}function W(t){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a,framework:o}=t,s=a||i,c=(0,e.resolve)(process.cwd(),n),l=`fluenti.runtime.${o}`,u=r.filter(e=>e!==s);return o===`react`?`
|
|
2
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
3
|
+
|
|
4
|
+
const __catalog = { ...__defaultMsgs }
|
|
5
|
+
let __currentLocale = '${s}'
|
|
6
|
+
const __loadedLocales = new Set(['${s}'])
|
|
7
|
+
let __loading = false
|
|
8
|
+
const __cache = new Map()
|
|
9
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
10
|
+
|
|
11
|
+
const __loaders = {
|
|
12
|
+
${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
|
|
13
|
+
`)}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function __switchLocale(locale) {
|
|
17
|
+
if (__loadedLocales.has(locale)) {
|
|
18
|
+
Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
|
|
19
|
+
__currentLocale = locale
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
__loading = true
|
|
23
|
+
try {
|
|
24
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
25
|
+
__cache.set(locale, mod)
|
|
26
|
+
__loadedLocales.add(locale)
|
|
27
|
+
Object.assign(__catalog, mod)
|
|
28
|
+
__currentLocale = locale
|
|
29
|
+
} finally {
|
|
30
|
+
__loading = false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function __preloadLocale(locale) {
|
|
35
|
+
if (__loadedLocales.has(locale) || !__loaders[locale]) return
|
|
36
|
+
try {
|
|
37
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
38
|
+
__cache.set(locale, mod)
|
|
39
|
+
__loadedLocales.add(locale)
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
44
|
+
|
|
45
|
+
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
46
|
+
`:o===`vue`?`
|
|
47
|
+
import { shallowReactive, triggerRef, ref } from 'vue'
|
|
48
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
49
|
+
|
|
50
|
+
const __catalog = shallowReactive({ ...__defaultMsgs })
|
|
51
|
+
const __currentLocale = ref('${s}')
|
|
52
|
+
const __loadedLocales = new Set(['${s}'])
|
|
53
|
+
const __loading = ref(false)
|
|
54
|
+
const __cache = new Map()
|
|
55
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
56
|
+
|
|
57
|
+
const __loaders = {
|
|
58
|
+
${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
|
|
59
|
+
`)}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function __switchLocale(locale) {
|
|
63
|
+
if (__loadedLocales.has(locale)) {
|
|
64
|
+
Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
|
|
65
|
+
__currentLocale.value = locale
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
__loading.value = true
|
|
69
|
+
try {
|
|
70
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
71
|
+
__cache.set(locale, mod)
|
|
72
|
+
__loadedLocales.add(locale)
|
|
73
|
+
Object.assign(__catalog, mod)
|
|
74
|
+
__currentLocale.value = locale
|
|
75
|
+
} finally {
|
|
76
|
+
__loading.value = false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function __preloadLocale(locale) {
|
|
81
|
+
if (__loadedLocales.has(locale) || !__loaders[locale]) return
|
|
82
|
+
try {
|
|
83
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
84
|
+
__cache.set(locale, mod)
|
|
85
|
+
__loadedLocales.add(locale)
|
|
86
|
+
} catch {}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
90
|
+
|
|
91
|
+
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
92
|
+
`:`
|
|
93
|
+
import { createSignal } from 'solid-js'
|
|
94
|
+
import { createStore, reconcile } from 'solid-js/store'
|
|
95
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
96
|
+
|
|
97
|
+
const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
|
|
98
|
+
const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
|
|
99
|
+
const __loadedLocales = new Set(['${s}'])
|
|
100
|
+
const [__loading, __setLoading] = createSignal(false)
|
|
101
|
+
const __cache = new Map()
|
|
102
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
103
|
+
|
|
104
|
+
const __loaders = {
|
|
105
|
+
${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
|
|
106
|
+
`)}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function __switchLocale(locale) {
|
|
110
|
+
if (__loadedLocales.has(locale)) {
|
|
111
|
+
__setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))
|
|
112
|
+
__setCurrentLocale(locale)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
__setLoading(true)
|
|
116
|
+
try {
|
|
117
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
118
|
+
__cache.set(locale, mod)
|
|
119
|
+
__loadedLocales.add(locale)
|
|
120
|
+
__setCatalog(reconcile(mod))
|
|
121
|
+
__setCurrentLocale(locale)
|
|
122
|
+
} finally {
|
|
123
|
+
__setLoading(false)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function __preloadLocale(locale) {
|
|
128
|
+
if (__loadedLocales.has(locale) || !__loaders[locale]) return
|
|
129
|
+
try {
|
|
130
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
131
|
+
__cache.set(locale, mod)
|
|
132
|
+
__loadedLocales.add(locale)
|
|
133
|
+
} catch {}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
137
|
+
|
|
138
|
+
export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
|
|
139
|
+
`}function G(t){let{catalogDir:n,defaultBuildLocale:r,sourceLocale:i}=t,a=r||i;return`export * from '${(0,e.resolve)(process.cwd(),n)}/${a}.js'\n`}function K(t){let{catalogDir:n,locales:r,sourceLocale:i,defaultBuildLocale:a,framework:o}=t,s=a||i,c=(0,e.resolve)(process.cwd(),n),l=`fluenti.runtime.${o}`,u=r.filter(e=>e!==s);return o===`vue`?`
|
|
140
|
+
import { shallowReactive, ref } from 'vue'
|
|
141
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
142
|
+
|
|
143
|
+
const __catalog = shallowReactive({ ...__defaultMsgs })
|
|
144
|
+
const __currentLocale = ref('${s}')
|
|
145
|
+
const __loadedLocales = new Set(['${s}'])
|
|
146
|
+
const __loading = ref(false)
|
|
147
|
+
const __cache = new Map()
|
|
148
|
+
const __loadedRoutes = new Set()
|
|
149
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
150
|
+
|
|
151
|
+
const __loaders = {
|
|
152
|
+
${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
|
|
153
|
+
`)}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const __routeLoaders = {}
|
|
157
|
+
|
|
158
|
+
function __registerRouteLoader(routeId, locale, loader) {
|
|
159
|
+
const key = routeId + ':' + locale
|
|
160
|
+
__routeLoaders[key] = loader
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function __loadRoute(routeId, locale) {
|
|
164
|
+
const key = routeId + ':' + (locale || __currentLocale.value)
|
|
165
|
+
if (__loadedRoutes.has(key)) return
|
|
166
|
+
const loader = __routeLoaders[key]
|
|
167
|
+
if (!loader) return
|
|
168
|
+
const mod = __normalizeMessages(await loader())
|
|
169
|
+
Object.assign(__catalog, mod)
|
|
170
|
+
__loadedRoutes.add(key)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function __switchLocale(locale) {
|
|
174
|
+
if (locale === __currentLocale.value) return
|
|
175
|
+
__loading.value = true
|
|
176
|
+
try {
|
|
177
|
+
if (__cache.has(locale)) {
|
|
178
|
+
Object.assign(__catalog, __cache.get(locale))
|
|
179
|
+
} else {
|
|
180
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
181
|
+
__cache.set(locale, mod)
|
|
182
|
+
Object.assign(__catalog, mod)
|
|
183
|
+
}
|
|
184
|
+
__loadedLocales.add(locale)
|
|
185
|
+
__currentLocale.value = locale
|
|
186
|
+
} finally {
|
|
187
|
+
__loading.value = false
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function __preloadLocale(locale) {
|
|
192
|
+
if (__cache.has(locale) || !__loaders[locale]) return
|
|
193
|
+
try {
|
|
194
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
195
|
+
__cache.set(locale, mod)
|
|
196
|
+
__loadedLocales.add(locale)
|
|
197
|
+
} catch {}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
201
|
+
|
|
202
|
+
export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
|
|
203
|
+
`:`
|
|
204
|
+
import { createSignal } from 'solid-js'
|
|
205
|
+
import { createStore, reconcile } from 'solid-js/store'
|
|
206
|
+
import __defaultMsgs from '${c}/${s}.js'
|
|
207
|
+
|
|
208
|
+
const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
|
|
209
|
+
const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
|
|
210
|
+
const __loadedLocales = new Set(['${s}'])
|
|
211
|
+
const [__loading, __setLoading] = createSignal(false)
|
|
212
|
+
const __cache = new Map()
|
|
213
|
+
const __loadedRoutes = new Set()
|
|
214
|
+
const __normalizeMessages = (mod) => mod.default ?? mod
|
|
215
|
+
|
|
216
|
+
const __loaders = {
|
|
217
|
+
${u.map(e=>` '${e}': () => import('${c}/${e}.js'),`).join(`
|
|
218
|
+
`)}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const __routeLoaders = {}
|
|
222
|
+
|
|
223
|
+
function __registerRouteLoader(routeId, locale, loader) {
|
|
224
|
+
const key = routeId + ':' + locale
|
|
225
|
+
__routeLoaders[key] = loader
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function __loadRoute(routeId, locale) {
|
|
229
|
+
const key = routeId + ':' + (locale || __currentLocale())
|
|
230
|
+
if (__loadedRoutes.has(key)) return
|
|
231
|
+
const loader = __routeLoaders[key]
|
|
232
|
+
if (!loader) return
|
|
233
|
+
const mod = __normalizeMessages(await loader())
|
|
234
|
+
__setCatalog(reconcile({ ...__catalog, ...mod }))
|
|
235
|
+
__loadedRoutes.add(key)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function __switchLocale(locale) {
|
|
239
|
+
if (locale === __currentLocale()) return
|
|
240
|
+
__setLoading(true)
|
|
241
|
+
try {
|
|
242
|
+
if (__cache.has(locale)) {
|
|
243
|
+
__setCatalog(reconcile(__cache.get(locale)))
|
|
244
|
+
} else {
|
|
245
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
246
|
+
__cache.set(locale, mod)
|
|
247
|
+
__setCatalog(reconcile(mod))
|
|
248
|
+
}
|
|
249
|
+
__loadedLocales.add(locale)
|
|
250
|
+
__setCurrentLocale(locale)
|
|
251
|
+
} finally {
|
|
252
|
+
__setLoading(false)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function __preloadLocale(locale) {
|
|
257
|
+
if (__cache.has(locale) || !__loaders[locale]) return
|
|
258
|
+
try {
|
|
259
|
+
const mod = __normalizeMessages(await __loaders[locale]())
|
|
260
|
+
__cache.set(locale, mod)
|
|
261
|
+
__loadedLocales.add(locale)
|
|
262
|
+
} catch {}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
|
|
266
|
+
|
|
267
|
+
export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
|
|
268
|
+
`}function q(e){let t=(e.includes(`/`)?e.slice(e.lastIndexOf(`/`)+1):e).replace(/\.[^.]+$/,``);return t.replace(/-[a-zA-Z0-9]{4,}$/,``)||t}function ae(e){let t=new Map,n=e.split(`
|
|
269
|
+
`);for(let e=0;e<n.length;e++){let r=n[e],i=r.match(/^(?:\/\*.*?\*\/\s*)?export\s+const\s+_([a-z0-9]+)\s*=\s*/);if(!i)continue;let a=i[1],o=r,s=0,c=0,l=0;for(let e of r.slice(i[0].length))e===`{`&&s++,e===`}`&&s--,e===`(`&&c++,e===`)`&&c--,e==="`"&&(l=l===0?1:0);for(;(s>0||c>0||l>0)&&e+1<n.length;){e++;let t=n[e];o+=`
|
|
270
|
+
`+t;for(let e of t)e===`{`&&s++,e===`}`&&s--,e===`(`&&c++,e===`)`&&c--,e==="`"&&(l=l===0?1:0)}t.set(a,o)}return t}function J(e,n){let r=[],i=[];for(let a of e){let e=(0,t.hashMessage)(a),o=n.get(e);o&&(r.push(o),i.push(` '${se(a)}': _${e},`))}return i.length>0&&r.push(``,`export default {`,...i,`}`),r.join(`
|
|
271
|
+
`)+`
|
|
272
|
+
`}function oe(t,n){try{return(0,r.readFileSync)((0,e.resolve)(t,`${n}.js`),`utf-8`)}catch{return}}function se(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\r/g,`\\r`).replace(/\n/g,`\\n`)}function Y(e,t){return e.endsWith(`.vue`)?`vue`:t.includes(`@fluenti/solid`)||t.includes(`solid-js`)||t.includes(`createSignal`)||t.includes(`createMemo`)?`solid`:t.includes(`@fluenti/react`)||t.includes(`react`)||t.includes(`useState`)||t.includes(`useEffect`)||t.includes(`jsx`)?`react`:`vue`}function X(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`)}function Z(e,n){return`{ id: '${X(n?.id??(0,t.hashMessage)(e,n?.context))}', message: '${X(e)}' }`}function ce(e){let t=e.match(/<template(\s[^>]*)?>/);if(!t)return e;let n=t.index+t[0].length,r=e.lastIndexOf(`</template>`);if(r<0)return e;let i=e.slice(0,n),a=e.slice(n,r),o=e.slice(r),s=/\bv-t\b/.test(a),c=/<Trans[\s>]/.test(a),l=/<Plural[\s/>]/.test(a);return!s&&!c&&!l?e:(s&&(a=le(a),a=de(a)),c&&(a=fe(a)),l&&(a=pe(a)),i+a+o)}function le(e){return e.replace(/<(\w+)(\s[^>]*?)\bv-t\.(\w+)\b([^>]*?)>/g,(e,t,n,r,i)=>{if(r===`plural`)return e;let a=n+i,o=RegExp(`\\b${r}="([^"]*)"`),s=a.match(o);if(!s)return e;let c=s[1],l=Z(c),u=n.replace(/\s*\bv-t\.\w+\b/,``),d=i.replace(/\s*\bv-t\.\w+\b/,``),f=RegExp(`\\s*\\b${r}="[^"]*"`);return u=u.replace(f,``),d=d.replace(f,``),`<${t}${u} :${r}="$t(${l})"${d}>`})}function ue(e){let t=[];return{message:e.replace(/\{\{\s*([^}]+?)\s*\}\}/g,(e,n)=>{let r=n.trim(),i;if(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(r))i=r;else if(/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(r)&&!r.endsWith(`.`)){let e=r.split(`.`);i=e[e.length-1]}else i=String(t.length);return t.push(`${i}: ${r}`),`{${i}}`}),vars:t}}function de(e){return e.replace(/<(\w+)(\s[^>]*?)\bv-t(?::([a-zA-Z0-9_.]+))?(?:\.plural)?(?:="([^"]*)")?\b([^>]*)>([\s\S]*?)<\/\1>/g,(e,t,n,r,i,a,o)=>{let s=e.includes(`v-t.plural`),c=n.replace(/\s*\bv-t(?::[a-zA-Z0-9_.]+)?(?:\.plural)?(?:="[^"]*")?\b/,``),l=a.replace(/\s*\bv-t(?::[a-zA-Z0-9_.]+)?(?:\.plural)?(?:="[^"]*")?\b/,``);if(s&&i){let e=o.trim().split(`|`).map(e=>e.trim());return`<${t}${c}${l}>{{ $t(${Z(`{${i}, plural, ${(e.length===2?[`one`,`other`]:[`one`,`other`,`zero`,`few`,`many`].slice(0,e.length)).map((t,n)=>`${t} {${e[n]??``}}`).join(` `)}}`,{id:r})}, { ${i} }) }}</${t}>`}let u=o.trim();if(/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(u)){let e=[],n=0;return`<${t}${c}${l} v-html="$vtRich(${Z(u.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,(t,r,i,a)=>{let o=n++,s={},c=/(\w+)="([^"]*)"/g,l;for(;(l=c.exec(i))!==null;)s[l[1]]=l[2];return e.push({tag:r,attrs:s}),`<${o}>${a}</${o}>`}),{id:r})}, ${`[${e.map(e=>{let t=Object.entries(e.attrs).map(([e,t])=>`${e}: '${X(t)}'`).join(`, `);return`{ tag: '${e.tag}', attrs: { ${t} } }`}).join(`, `)}]`})"></${t}>`}let{message:d,vars:f}=ue(u),p=Z(d,{id:r});return f.length>0?`<${t}${c}${l}>{{ $t(${p}, { ${f.join(`, `)} }) }}</${t}>`:`<${t}${c}${l}>{{ $t(${p}) }}</${t}>`})}function fe(e){return e.replace(/<Trans(\s[^>]*)?>(?!\s*$)([\s\S]*?)<\/Trans>/g,(e,t,n)=>{let r=t??``;if(/\bmessage\s*=/.test(r))return e;let i=Q(r,`id`);if(i.kind===`dynamic`)return e;let a=Q(r,`context`);if(!i.value&&a.kind===`dynamic`)return e;let o=r.match(/\btag\s*=\s*"([^"]*)"/)?.[1]??`span`,s=r.replace(/\s*\btag\s*=\s*"[^"]*"/,``).replace(/\s*\bid\s*=\s*"[^"]*"/,``).replace(/\s*:id\s*=\s*"[^"]*"/,``).replace(/\s*\bcontext\s*=\s*"[^"]*"/,``).replace(/\s*:context\s*=\s*"[^"]*"/,``).replace(/\s*\bcomment\s*=\s*"[^"]*"/,``).replace(/\s*:comment\s*=\s*"[^"]*"/,``),c=n.trim();if(/<(\w+)(\s[^>]*)?>[\s\S]*?<\/\1>/g.test(c)){let e=[],t=0;return`<${o}${s} v-html="$vtRich(${Z(c.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,(n,r,i,a)=>{let o=t++,s={},c=/(\w[\w-]*)="([^"]*)"/g,l;for(;(l=c.exec(i))!==null;)s[l[1]]=l[2];return e.push({tag:r,attrs:s}),`<${o}>${a}</${o}>`}),{id:i.value,context:a.value})}, ${`[${e.map(e=>{let t=Object.entries(e.attrs).map(([e,t])=>`${e}: '${X(t)}'`).join(`, `);return`{ tag: '${e.tag}', attrs: { ${t} } }`}).join(`, `)}]`})"></${o}>`}return`<${o}${s}>{{ $t(${Z(c,{id:i.value,context:a.value})}) }}</${o}>`})}function pe(e){return e=e.replace(/<Plural(\s[^>]*?)>([\s\S]*?)<\/Plural>/g,(e,t,n)=>{let r=t??``,i=Q(r,`id`),a=Q(r,`context`);if(i.kind===`dynamic`||!i.value&&a.kind===`dynamic`)return e;let o=/<template\s+#(\w+)\s*>([\s\S]*?)<\/template>/g,s=[],c;for(;(c=o.exec(n))!==null;)s.push({cat:c[1],content:c[2].trim()});if(s.length===0)return e;let l=r.match(/:value\s*=\s*"([^"]*)"/);if(!l)return e;let u=l[1],d=r.match(/\btag\s*=\s*"([^"]*)"/)?.[1]??`span`,f=[`zero`,`one`,`two`,`few`,`many`,`other`],p=[],m=[];for(let e of f){let t=s.find(t=>t.cat===e);if(!t)continue;let n=t.content,r=/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,i=n;if(r.test(n)){let e=p.length,t=0;i=n.replace(/<(\w+)((?:\s[^>]*)?)>([\s\S]*?)<\/\1>/g,(n,r,i,a)=>{let o=e+ t++,s={},c=/(\w[\w-]*)="([^"]*)"/g,l;for(;(l=c.exec(i))!==null;)s[l[1]]=l[2];return p.push({tag:r,attrs:s}),`<${o}>${a}</${o}>`})}let a=e===`zero`?`=0`:e;m.push(`${a} {${i}}`)}if(m.length===0)return e;let h=Z(`{count, plural, ${m.join(` `)}}`,{id:i.value,context:a.value}),g=r;g=g.replace(/:value\s*=\s*"[^"]*"/,``),g=g.replace(/\btag\s*=\s*"[^"]*"/,``),g=g.replace(/\s*\bid\s*=\s*"[^"]*"/,``),g=g.replace(/\s*:id\s*=\s*"[^"]*"/,``),g=g.replace(/\s*\bcontext\s*=\s*"[^"]*"/,``),g=g.replace(/\s*:context\s*=\s*"[^"]*"/,``),g=g.replace(/\s*\bcomment\s*=\s*"[^"]*"/,``),g=g.replace(/\s*:comment\s*=\s*"[^"]*"/,``),g=g.replace(/\s+/g,` `).trim();let _=g?` ${g}`:``;return p.length>0?`<${d}${_} v-html="$vtRich(${h}, ${`[${p.map(e=>{let t=Object.entries(e.attrs).map(([e,t])=>`${e}: '${X(t)}'`).join(`, `);return`{ tag: '${e.tag}', attrs: { ${t} } }`}).join(`, `)}]`}, { count: ${u} })"></${d}>`:`<${d}${_} v-text="$t(${h}, { count: ${u} })"></${d}>`}),e.replace(/<Plural(\s[^>]*?)\/?>(?:<\/Plural>)?/g,(e,t)=>{let n=t??``,r=Q(n,`id`),i=Q(n,`context`);if(r.kind===`dynamic`||!r.value&&i.kind===`dynamic`)return e;let a=n.match(/:value\s*=\s*"([^"]*)"/);if(!a)return e;let o=a[1],s=n.match(/\btag\s*=\s*"([^"]*)"/)?.[1]??`span`,c=[`zero`,`one`,`two`,`few`,`many`,`other`],l=[];for(let e of c){let t=RegExp(`(?<!:)\\b${e}\\s*=\\s*"([^"]*)"`),r=n.match(t);if(r){let t=e===`zero`?`=0`:e;l.push(`${t} {${r[1]}}`)}}if(l.length===0)return e;let u=Z(`{count, plural, ${l.join(` `)}}`,{id:r.value,context:i.value}),d=n;d=d.replace(/:value\s*=\s*"[^"]*"/,``),d=d.replace(/\btag\s*=\s*"[^"]*"/,``),d=d.replace(/\s*\bid\s*=\s*"[^"]*"/,``),d=d.replace(/\s*:id\s*=\s*"[^"]*"/,``),d=d.replace(/\s*\bcontext\s*=\s*"[^"]*"/,``),d=d.replace(/\s*:context\s*=\s*"[^"]*"/,``),d=d.replace(/\s*\bcomment\s*=\s*"[^"]*"/,``),d=d.replace(/\s*:comment\s*=\s*"[^"]*"/,``);for(let e of c)d=d.replace(RegExp(`(?<!:)\\b${e}\\s*=\\s*"[^"]*"`),``);return d=d.replace(/\s+/g,` `).trim(),`<${s}${d?` ${d}`:``} v-text="$t(${u}, { count: ${o} })"></${s}>`})}function Q(e,t){if(RegExp(`(?:^|\\s):${t}\\s*=`).test(e))return{kind:`dynamic`};let n=e.match(RegExp(`\\b${t}\\s*=\\s*"([^"]*)"`));return n?{kind:`static`,value:n[1]??``}:{kind:`missing`}}function $(e){return{code:e,changed:!1}}var me=`virtual:fluenti/messages/`,he=`\0virtual:fluenti/messages/`;function ge(t){let r=t?.catalogDir??`src/locales/compiled`,i=t?.framework??`auto`,l=t?.splitting??!1,u=t?.sourceLocale??`en`,d=t?.locales??[u],f=t?.defaultBuildLocale??u,p=`vue`,m={name:`fluenti:virtual`,configResolved(e){a(e.command)},resolveId(e){if(e.startsWith(me))return`\0`+e;if(l){let t=H(e);if(t)return t}},load(e){if(e.startsWith(he))return`export { default } from '${`${r}/${e.slice(26)}.js`}'`;if(l){let t=U(e,{catalogDir:r,locales:d,sourceLocale:u,defaultBuildLocale:f,framework:p});if(t)return t}}},h={name:`fluenti:vue-template`,enforce:`pre`,transform(e,t){if(!t.endsWith(`.vue`)||!/\bv-t\b/.test(e)&&!/<Trans[\s>]/.test(e)&&!/<Plural[\s/>]/.test(e))return;let n=ce(e);if(n!==e)return{code:n,map:null}}},g={name:`fluenti:script-transform`,enforce:`pre`,transform(e,t){if(t.includes(`node_modules`)||!t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)||t.includes(`.vue`)&&!t.includes(`type=script`))return;let r=e,a=!1;if(t.match(/\.[jt]sx(\?|$)/)&&/<Trans[\s>]/.test(r)){let e=(0,n.transformTransComponents)(r);e.transformed&&(r=e.code,a=!0)}if(_e(r)){let e=i===`auto`?Y(t,r):i,a=(0,n.scopeTransform)(r,{framework:e,allowTopLevelImportedT:e===`vue`&&t.includes(`.vue`)});if(a.transformed)return{code:a.code,map:null}}return a?{code:r,map:null}:void 0}},_=new Map;return[m,h,{name:`fluenti:solid-jsx`,enforce:`pre`,transform(e,t){if(!t.match(/\.[tj]sx(\?|$)/)||t.includes(`node_modules`)||!/<Trans[\s>]/.test(e)&&!/<Plural[\s/>]/.test(e)||(i===`auto`?Y(t,e):i)!==`solid`)return;let n=$(e);if(n.changed)return{code:n.code,map:null}}},g,{name:`fluenti:build-split`,transform(e,t){if(!l||!o(this.environment)||t.includes(`node_modules`)||!t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/))return;p=i===`auto`?Y(t,e):i;let n=l===`static`?`static`:`dynamic`,r=n===`static`?c(e):s(e);if(l===`per-route`&&r.usedHashes.size>0&&_.set(t,r.usedHashes),!r.needsCatalogImport)return;let a=l===`per-route`?`per-route`:n;return{code:F(r.code,a,r.usedHashes),map:null}},generateBundle(t,n){if(l!==`per-route`||_.size===0)return;let i=new Map;for(let[e,t]of Object.entries(n)){if(t.type!==`chunk`)continue;let n=new Set;for(let e of Object.keys(t.modules)){let t=_.get(e);if(t)for(let e of t)n.add(e)}n.size>0&&i.set(e,n)}if(i.size===0)return;let a=new Map;for(let[e,t]of i)for(let n of t){let t=a.get(n)??[];t.push(e),a.set(n,t)}let o=new Set,s=new Map;for(let[e,t]of a)if(t.length>1)o.add(e);else{let n=q(t[0]),r=s.get(n)??new Set;r.add(e),s.set(n,r)}let c=(0,e.resolve)(process.cwd(),r);for(let e of d){let t=oe(c,e);if(!t)continue;let n=ae(t);if(o.size>0){let t=J(o,n);this.emitFile({type:`asset`,fileName:`_fluenti/shared-${e}.js`,source:t})}for(let[t,r]of s){let i=J(r,n);this.emitFile({type:`asset`,fileName:`_fluenti/${t}-${e}.js`,source:i})}}}},{name:`fluenti:dev`,configureServer(e){},hotUpdate({file:e}){if(e.includes(r)){let e=[...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e])=>e.includes(`virtual:fluenti`)).map(([,e])=>e);if(e.length>0)return e}}}]}function _e(e){return/(?<![.\w$])t\(\s*['"]/.test(e)||/[A-Za-z_$][\w$]*\(\s*\{/.test(e)||/[A-Za-z_$][\w$]*`/.test(e)&&(e.includes(`useI18n`)||e.includes(`getI18n`))?!0:/import\s*\{[^}]*\bt(?:\s+as\s+[A-Za-z_$][\w$]*)?\b[^}]*\}/.test(e)&&/@fluenti\/(react|vue|solid|next\/__generated)/.test(e)}module.exports=ge;
|
|
273
|
+
//# sourceMappingURL=index.cjs.map
|