@gringow/gringow-nextjs 0.0.3 → 0.0.4
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/README.md +264 -46
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,89 +1,221 @@
|
|
|
1
1
|
# @gringow/gringow-nextjs
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@gringow/gringow-nextjs)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
- Scans source files for `g\`...\`` template literals using the glob pattern from `gringow.config.*` (via
|
|
8
|
-
`@gringow/gringow` config loading).
|
|
9
|
-
- On Turbopack, hooks into `headers()` and triggers a single cache build on first call.
|
|
10
|
-
- The Webpack path currently returns the provided Next config unchanged (no hooks wired yet).
|
|
11
|
-
- No CLI flags (`--gringow=build|clear|reset`) are implemented.
|
|
6
|
+
⚠️ **Experimental** Next.js integration for Gringow AI-powered translations. Currently targets Turbopack with minimal build-time cache generation.
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
## ⚠️ Status: Experimental
|
|
9
|
+
|
|
10
|
+
This package is in early development and provides basic functionality. For production use, consider:
|
|
11
|
+
- **[@gringow/gringow-vite](https://www.npmjs.com/package/@gringow/gringow-vite)** - Production-ready Vite plugin
|
|
12
|
+
- **[@gringow/cli](https://www.npmjs.com/package/@gringow/gringow-cli)** - CLI cache builder
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- 🎯 **Turbopack-First** - Built for Next.js 15+ with Turbopack
|
|
17
|
+
- 🔍 **Auto-Extraction** - Scans for `g` tagged templates
|
|
18
|
+
- 💾 **Cache Building** - Generates translations on first request
|
|
19
|
+
- ⚡ **Minimal Setup** - Simple configuration wrapper
|
|
20
|
+
|
|
21
|
+
## Current Limitations
|
|
22
|
+
|
|
23
|
+
- **Turbopack only** - Webpack integration is a stub (no build hooks)
|
|
24
|
+
- **No CLI flags** - `--gringow=build|clear|reset` not implemented
|
|
25
|
+
- **Headers hook** - Cache builds during `headers()` call (not ideal)
|
|
26
|
+
- **No cache pruning** - Stale entries not removed automatically
|
|
27
|
+
|
|
28
|
+
**Contributions welcome** to improve Webpack support and add proper build hooks!
|
|
14
29
|
|
|
15
30
|
## Installation
|
|
31
|
+
|
|
16
32
|
```bash
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
# Using pnpm
|
|
34
|
+
pnpm add @gringow/gringow-nextjs @gringow/gringow @gringow/gringow-react
|
|
35
|
+
|
|
36
|
+
# Using npm
|
|
37
|
+
npm install @gringow/gringow-nextjs @gringow/gringow @gringow/gringow-react
|
|
38
|
+
|
|
39
|
+
# Using yarn
|
|
40
|
+
yarn add @gringow/gringow-nextjs @gringow/gringow @gringow/gringow-react
|
|
20
41
|
```
|
|
21
42
|
|
|
22
|
-
##
|
|
23
|
-
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
### 1. Configure Next.js
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
24
48
|
// next.config.ts
|
|
25
49
|
import type { NextConfig } from 'next'
|
|
26
50
|
import GringowNextjsPlugin from '@gringow/gringow-nextjs'
|
|
27
51
|
|
|
28
|
-
const withGringow = GringowNextjsPlugin({
|
|
52
|
+
const withGringow = GringowNextjsPlugin({
|
|
53
|
+
debug: process.env.NODE_ENV === 'development'
|
|
54
|
+
})
|
|
29
55
|
|
|
30
56
|
const nextConfig: NextConfig = {
|
|
31
|
-
//
|
|
57
|
+
// Your Next.js configuration
|
|
58
|
+
experimental: {
|
|
59
|
+
turbo: {}, // Turbopack recommended
|
|
60
|
+
},
|
|
32
61
|
}
|
|
33
62
|
|
|
34
63
|
export default withGringow(nextConfig)
|
|
35
64
|
```
|
|
36
65
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
1) read `gringow.config.*` for `globby` and LLM settings,
|
|
40
|
-
2) globby-scan files, collecting `g\`...\`` occurrences,
|
|
41
|
-
3) call the core Gringow runtime to populate `gringow/gringow.json`.
|
|
66
|
+
### 2. Create Gringow Config
|
|
42
67
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
```javascript
|
|
69
|
+
// gringow.config.js
|
|
70
|
+
export default {
|
|
71
|
+
llm: {
|
|
72
|
+
choice: 'huggingface',
|
|
73
|
+
model: 'Xenova/nllb-200-distilled-600M',
|
|
74
|
+
},
|
|
75
|
+
languages: ['pt-BR', 'es-ES', 'fr-CA'],
|
|
76
|
+
sourceLanguage: 'en-US',
|
|
77
|
+
globby: './app/**/*.{ts,tsx}', // Adjust to your structure
|
|
47
78
|
}
|
|
48
79
|
```
|
|
49
80
|
|
|
50
|
-
|
|
51
|
-
- Turbopack only, and even there it runs during `headers()` rather than build hooks.
|
|
52
|
-
- Webpack integration is a stub (no cache build hooks yet).
|
|
53
|
-
- Cache pruning and `--gringow` flags are not implemented.
|
|
81
|
+
### 3. Use in Components
|
|
54
82
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
MIT
|
|
83
|
+
```tsx
|
|
84
|
+
// app/page.tsx
|
|
85
|
+
import { g } from '@gringow/gringow-react'
|
|
59
86
|
|
|
60
87
|
export default function HomePage() {
|
|
61
|
-
const name = '
|
|
88
|
+
const name = 'Alice'
|
|
62
89
|
|
|
63
90
|
return (
|
|
64
91
|
<div>
|
|
65
|
-
<h1>{
|
|
66
|
-
<p>{
|
|
92
|
+
<h1>{g`Welcome ${name}!`}</h1>
|
|
93
|
+
<p>{g`This text will be automatically translated.`}</p>
|
|
67
94
|
</div>
|
|
68
95
|
)
|
|
69
96
|
}
|
|
70
97
|
```
|
|
71
98
|
|
|
72
|
-
###
|
|
99
|
+
### 4. Run Development Server
|
|
100
|
+
|
|
73
101
|
```bash
|
|
74
|
-
|
|
75
|
-
|
|
102
|
+
pnpm dev
|
|
103
|
+
|
|
104
|
+
# First request triggers cache build
|
|
105
|
+
# Translations stored in ./gringow/gringow.json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Configuration
|
|
109
|
+
|
|
110
|
+
### Plugin Options
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
interface GringowNextjsPluginOptions {
|
|
114
|
+
debug?: boolean // Log cache build operations (default: false)
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Example:**
|
|
119
|
+
```typescript
|
|
120
|
+
const withGringow = GringowNextjsPlugin({ debug: true })
|
|
121
|
+
```
|
|
76
122
|
|
|
77
|
-
|
|
78
|
-
|
|
123
|
+
### Gringow Config
|
|
124
|
+
|
|
125
|
+
The plugin reads your `gringow.config.js`:
|
|
126
|
+
|
|
127
|
+
- **`globby`** - File patterns to scan (e.g., `'./app/**/*.{ts,tsx}'`)
|
|
128
|
+
- **`llm.*`** - LLM provider configuration
|
|
129
|
+
- **`languages`** - Target translation languages
|
|
130
|
+
- **`cache.dir`** - Cache directory (default: `'./gringow'`)
|
|
131
|
+
|
|
132
|
+
See [@gringow/gringow](https://www.npmjs.com/package/@gringow/gringow) for complete options.
|
|
133
|
+
|
|
134
|
+
## How It Works
|
|
135
|
+
|
|
136
|
+
### Turbopack Flow
|
|
137
|
+
|
|
138
|
+
1. **Plugin wraps** Next.js config with Gringow middleware
|
|
139
|
+
2. **Headers hook** - First `headers()` call triggers cache build
|
|
140
|
+
3. **File scanning** - Uses `globby` pattern from config
|
|
141
|
+
4. **Extraction** - Finds all `g` tagged templates
|
|
142
|
+
5. **Translation** - Calls core library to translate
|
|
143
|
+
6. **Cache write** - Stores in `./gringow/gringow.json`
|
|
144
|
+
|
|
145
|
+
### Webpack Flow
|
|
146
|
+
|
|
147
|
+
Currently returns config unchanged. Build hooks not yet implemented.
|
|
148
|
+
|
|
149
|
+
## Usage Examples
|
|
150
|
+
|
|
151
|
+
### App Router with Server Components
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
// app/page.tsx
|
|
155
|
+
import { g } from '@gringow/gringow-react'
|
|
156
|
+
|
|
157
|
+
export default async function Page() {
|
|
158
|
+
const data = await fetchData()
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<main>
|
|
162
|
+
<h1>{g`Welcome to our platform`}</h1>
|
|
163
|
+
<p>{g`You have ${data.count} items`}</p>
|
|
164
|
+
</main>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
79
167
|
```
|
|
80
168
|
|
|
81
|
-
|
|
169
|
+
### Pages Router
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
// pages/index.tsx
|
|
173
|
+
import { g } from '@gringow/gringow-react'
|
|
174
|
+
import type { NextPage } from 'next'
|
|
175
|
+
|
|
176
|
+
const HomePage: NextPage = () => {
|
|
177
|
+
return (
|
|
178
|
+
<div>
|
|
179
|
+
<h1>{g`Home Page`}</h1>
|
|
180
|
+
<p>{g`Welcome back!`}</p>
|
|
181
|
+
</div>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
82
184
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
185
|
+
export default HomePage
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Client Components
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
'use client'
|
|
192
|
+
|
|
193
|
+
import { g, changeLanguage } from '@gringow/gringow-react'
|
|
194
|
+
import { useEffect } from 'react'
|
|
195
|
+
|
|
196
|
+
export function LanguageSwitcher() {
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
// Initialize Gringow store on client
|
|
199
|
+
import('@gringow/gringow-react/browser')
|
|
200
|
+
import('@gringow/gringow-react/store').then(({ GringowStore }) => {
|
|
201
|
+
GringowStore.cacheUrl = '/gringow/gringow.json'
|
|
202
|
+
GringowStore.language = 'en-US'
|
|
203
|
+
GringowStore.fetchCache()
|
|
204
|
+
})
|
|
205
|
+
}, [])
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div>
|
|
209
|
+
<button onClick={() => changeLanguage('en-US')}>
|
|
210
|
+
{g`English`}
|
|
211
|
+
</button>
|
|
212
|
+
<button onClick={() => changeLanguage('pt-BR')}>
|
|
213
|
+
{g`Portuguese`}
|
|
214
|
+
</button>
|
|
215
|
+
</div>
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
```
|
|
87
219
|
|
|
88
220
|
## Development scripts
|
|
89
221
|
```bash
|
|
@@ -93,3 +225,89 @@ pnpm run watch # Continuous rebuild for local development
|
|
|
93
225
|
|
|
94
226
|
## License
|
|
95
227
|
MIT © Renato Gaspar
|
|
228
|
+
|
|
229
|
+
## Workarounds & Tips
|
|
230
|
+
|
|
231
|
+
### Pre-Build Cache
|
|
232
|
+
|
|
233
|
+
Since CLI flags aren't implemented, generate cache before deployment:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# Use CLI to build cache
|
|
237
|
+
pnpm gringow cache list # or use Vite plugin
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Commit Cache File
|
|
241
|
+
|
|
242
|
+
For faster deployments, commit `gringow/gringow.json`:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
git add gringow/gringow.json
|
|
246
|
+
git commit -m "Add translation cache"
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Use Vite for Development
|
|
250
|
+
|
|
251
|
+
For better DX, develop with Vite and deploy with Next.js:
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"scripts": {
|
|
256
|
+
"dev": "vite",
|
|
257
|
+
"build:translations": "vite build --gringow=build",
|
|
258
|
+
"build": "pnpm build:translations && next build"
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Known Issues
|
|
264
|
+
|
|
265
|
+
- **Webpack**: No build hooks - returns config unchanged
|
|
266
|
+
- **CLI flags**: `--gringow=build|clear|reset` not supported
|
|
267
|
+
- **Cache pruning**: Stale entries not automatically removed
|
|
268
|
+
- **Build timing**: Cache builds on first request, not at build time
|
|
269
|
+
|
|
270
|
+
## Roadmap
|
|
271
|
+
|
|
272
|
+
- [ ] Proper Webpack integration with build hooks
|
|
273
|
+
- [ ] CLI flags support (`--gringow=build|clear|reset`)
|
|
274
|
+
- [ ] Build-time cache generation (not request-time)
|
|
275
|
+
- [ ] Automatic cache pruning
|
|
276
|
+
- [ ] Better error handling and logging
|
|
277
|
+
|
|
278
|
+
**Want to contribute?** PRs welcome on [GitHub](https://github.com/rntgspr/gringow)!
|
|
279
|
+
|
|
280
|
+
## Development
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# Install dependencies
|
|
284
|
+
pnpm install
|
|
285
|
+
|
|
286
|
+
# Build the plugin
|
|
287
|
+
pnpm run build
|
|
288
|
+
|
|
289
|
+
# Watch mode
|
|
290
|
+
pnpm run watch
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Related Packages
|
|
294
|
+
|
|
295
|
+
- **[@gringow/gringow](https://www.npmjs.com/package/@gringow/gringow)** - Core translation library
|
|
296
|
+
- **[@gringow/gringow-react](https://www.npmjs.com/package/@gringow/gringow-react)** - React bindings
|
|
297
|
+
- **[@gringow/gringow-vite](https://www.npmjs.com/package/@gringow/gringow-vite)** - Production-ready Vite plugin (recommended)
|
|
298
|
+
- **[@gringow/gringow-shadow](https://www.npmjs.com/package/@gringow/gringow-shadow)** - Web Component layer
|
|
299
|
+
- **[@gringow/cli](https://www.npmjs.com/package/@gringow/gringow-cli)** - CLI tool
|
|
300
|
+
|
|
301
|
+
## Resources
|
|
302
|
+
|
|
303
|
+
- [Documentation](https://gringow.dev)
|
|
304
|
+
- [GitHub Repository](https://github.com/rntgspr/gringow)
|
|
305
|
+
- [Vite Example](https://github.com/rntgspr/gringow/tree/main/example-gringow-vite)
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
MIT © [Renato Gaspar](https://github.com/rntgspr)
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
**Questions?** Open an issue on [GitHub](https://github.com/rntgspr/gringow/issues)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gringow/gringow-nextjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A Next.js plugin for Gringow AI-powered translation tool",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"globby": "14.1.0",
|
|
43
43
|
"react": "^19.2.0",
|
|
44
44
|
"webpack": "^5.102.1",
|
|
45
|
-
"@gringow/gringow": "0.1.
|
|
46
|
-
"@gringow/gringow-react": "0.0.
|
|
45
|
+
"@gringow/gringow": "0.1.4",
|
|
46
|
+
"@gringow/gringow-react": "0.0.9"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"next": ">=15.0.0"
|