vite-plugin-lingo 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +266 -0
  2. package/dist/index.d.ts +8 -0
  3. package/dist/index.js +10 -0
  4. package/dist/plugin/gettext-parser.d.ts +44 -0
  5. package/dist/plugin/index.cjs +449 -0
  6. package/dist/plugin/index.cjs.map +1 -0
  7. package/dist/plugin/index.d.cts +84 -0
  8. package/dist/plugin/index.d.ts +84 -0
  9. package/dist/plugin/index.js +413 -0
  10. package/dist/plugin/index.js.map +1 -0
  11. package/dist/plugin/middleware.d.ts +10 -0
  12. package/dist/plugin/middleware.js +137 -0
  13. package/dist/plugin/po-parser.d.ts +25 -0
  14. package/dist/plugin/po-parser.js +147 -0
  15. package/dist/plugin/types.d.ts +67 -0
  16. package/dist/plugin/types.js +1 -0
  17. package/dist/ui/App.svelte +92 -0
  18. package/dist/ui/App.svelte.d.ts +3 -0
  19. package/dist/ui/app.css +64 -0
  20. package/dist/ui/components/LanguageList.svelte +166 -0
  21. package/dist/ui/components/LanguageList.svelte.d.ts +6 -0
  22. package/dist/ui/components/ProgressBar.svelte +47 -0
  23. package/dist/ui/components/ProgressBar.svelte.d.ts +9 -0
  24. package/dist/ui/components/SearchBar.svelte +54 -0
  25. package/dist/ui/components/SearchBar.svelte.d.ts +6 -0
  26. package/dist/ui/components/ThemeToggle.svelte +17 -0
  27. package/dist/ui/components/ThemeToggle.svelte.d.ts +18 -0
  28. package/dist/ui/components/TranslationEditor.svelte +418 -0
  29. package/dist/ui/components/TranslationEditor.svelte.d.ts +8 -0
  30. package/dist/ui/index.html +24 -0
  31. package/dist/ui/main.d.ts +3 -0
  32. package/dist/ui/main.js +7 -0
  33. package/dist/ui/stores/refresh-signal.svelte.d.ts +6 -0
  34. package/dist/ui/stores/refresh-signal.svelte.js +11 -0
  35. package/dist/ui-dist/assets/index-B5dZv0sy.css +1 -0
  36. package/dist/ui-dist/assets/index-DsX4xzGF.js +10 -0
  37. package/dist/ui-dist/index.html +25 -0
  38. package/package.json +118 -0
package/README.md ADDED
@@ -0,0 +1,266 @@
1
+ # 🌍 vite-plugin-lingo
2
+
3
+ A **Vite plugin** that provides a visual editor for `.po` (Gettext) translation files. Designed to work seamlessly with [wuchale](https://wuchale.dev/) and other i18n solutions.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/vite-plugin-lingo.svg)](https://www.npmjs.com/package/vite-plugin-lingo)
6
+ [![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
7
+
8
+ ## ✨ Features
9
+
10
+ - 🎨 **Visual Translation Editor** - Browse and edit `.po` files in a beautiful web UI
11
+ - 📊 **Language Overview** - See all locales with translation progress at a glance
12
+ - 🔍 **Search & Filter** - Find translations by text, filter by status
13
+ - ⌨️ **Keyboard Shortcuts** - Ctrl+S save, arrow keys navigate
14
+ - 🔄 **HMR Support** - Live reload when `.po` files change
15
+ - 🛠️ **Framework Agnostic** - Works with React, Vue, Svelte, SolidJS, or any Vite-powered project
16
+ - 🎯 **wuchale Integration** - Auto-detect config and `.po` locations
17
+
18
+ ## 📦 Installation
19
+
20
+ ```bash
21
+ # npm
22
+ npm install vite-plugin-lingo --save-dev
23
+
24
+ # pnpm
25
+ pnpm add -D vite-plugin-lingo
26
+
27
+ # bun (recommended)
28
+ bun add -d vite-plugin-lingo
29
+
30
+ # yarn
31
+ yarn add -D vite-plugin-lingo
32
+ ```
33
+
34
+ ## 🚀 Quick Start
35
+
36
+ ### 1. Add to your Vite config
37
+
38
+ ```ts
39
+ // vite.config.ts
40
+ import { defineConfig } from 'vite';
41
+ import lingo from 'vite-plugin-lingo';
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ lingo({
46
+ route: '/_translations', // Route where editor UI is served
47
+ localesDir: './locales', // Path to .po files
48
+ })
49
+ ]
50
+ });
51
+ ```
52
+
53
+ ### 2. Create your locales directory
54
+
55
+ ```
56
+ your-project/
57
+ ├── locales/
58
+ │ ├── en.po
59
+ │ ├── es.po
60
+ │ └── fr.po
61
+ ├── src/
62
+ └── vite.config.ts
63
+ ```
64
+
65
+ ### 3. Start your dev server
66
+
67
+ ```bash
68
+ bun run dev
69
+ # or
70
+ npm run dev
71
+ ```
72
+
73
+ ### 4. Open the translation editor
74
+
75
+ Navigate to `http://localhost:5173/_translations` to access the visual editor.
76
+
77
+ ## ⚙️ Configuration Options
78
+
79
+ ```ts
80
+ lingo({
81
+ // Route where editor UI is served (default: '/_translations')
82
+ route: '/_translations',
83
+
84
+ // Path to .po files relative to project root (default: './locales')
85
+ localesDir: './locales',
86
+
87
+ // Enable in production (default: false)
88
+ // ⚠️ Only enable with proper authentication!
89
+ production: false,
90
+ })
91
+ ```
92
+
93
+ ## 📖 API Reference
94
+
95
+ ### Plugin Options
96
+
97
+ | Option | Type | Default | Description |
98
+ |--------|------|---------|-------------|
99
+ | `route` | `string` | `'/_translations'` | URL path where the editor is served |
100
+ | `localesDir` | `string` | `'./locales'` | Directory containing `.po` files |
101
+ | `production` | `boolean` | `false` | Enable editor in production builds |
102
+
103
+ ### Exported Types
104
+
105
+ ```ts
106
+ import type {
107
+ PluginOptions,
108
+ Translation,
109
+ Language,
110
+ LanguageStats
111
+ } from 'vite-plugin-lingo';
112
+ ```
113
+
114
+ ## 🔧 How It Works
115
+
116
+ ```
117
+ ┌─────────────────────────────────────────────────────────┐
118
+ │ Vite Dev Server │
119
+ ├─────────────────────────────────────────────────────────┤
120
+ │ ┌─────────────────┐ ┌─────────────────────────────┐ │
121
+ │ │ Your App │ │ vite-plugin-lingo │ │
122
+ │ │ (React/Svelte/ │ │ ├─ Middleware (/_translations)│
123
+ │ │ Vue/Solid) │ │ ├─ API (GET/PUT /api/*) │ │
124
+ │ │ │ │ ├─ Editor UI (Svelte SPA) │ │
125
+ │ │ │ │ └─ File Watcher (.po files) │ │
126
+ │ └─────────────────┘ └─────────────────────────────┘ │
127
+ └─────────────────────────────────────────────────────────┘
128
+
129
+
130
+ ┌─────────────────┐
131
+ │ .po Files │
132
+ │ └─ locales/ │
133
+ │ ├─ en.po │
134
+ │ ├─ es.po │
135
+ │ └─ fr.po │
136
+ └─────────────────┘
137
+ ```
138
+
139
+ ## 📁 .po File Format
140
+
141
+ The plugin works with standard Gettext `.po` files:
142
+
143
+ ```po
144
+ # English translations
145
+ msgid ""
146
+ msgstr ""
147
+ "Language: en\n"
148
+ "Content-Type: text/plain; charset=UTF-8\n"
149
+
150
+ #: src/components/Header.svelte:5
151
+ msgid "Welcome to our website"
152
+ msgstr "Welcome to our website"
153
+
154
+ #: src/components/Header.svelte:10
155
+ msgid "Hello, {name}!"
156
+ msgstr "Hello, {name}!"
157
+ ```
158
+
159
+ ## 🛠️ Development
160
+
161
+ ### Prerequisites
162
+
163
+ - [Bun](https://bun.sh/) (recommended) or Node.js 18+
164
+ - Git
165
+
166
+ ### Setup
167
+
168
+ ```bash
169
+ # Clone the repository
170
+ git clone https://github.com/Michael-Obele/vite-plugin-lingo.git
171
+ cd vite-plugin-lingo
172
+
173
+ # Install dependencies
174
+ bun install
175
+
176
+ # Start development server
177
+ bun run dev
178
+
179
+ # Build the plugin
180
+ bun run build
181
+
182
+ # Run type checking
183
+ bun run check
184
+
185
+ # Run tests
186
+ bun run test
187
+ ```
188
+
189
+ ### Project Structure
190
+
191
+ ```
192
+ vite-plugin-lingo/
193
+ ├── src/
194
+ │ ├── lib/
195
+ │ │ ├── plugin/ # Vite plugin source
196
+ │ │ │ ├── index.ts # Main plugin entry
197
+ │ │ │ ├── middleware.ts # API endpoints
198
+ │ │ │ ├── po-parser.ts # .po file parser
199
+ │ │ │ └── types.ts # TypeScript types
200
+ │ │ └── ui/ # Editor UI (Svelte)
201
+ │ │ ├── App.svelte # Main editor component
202
+ │ │ └── components/ # UI components
203
+ │ └── routes/ # Demo/showcase app
204
+ ├── locales/ # Sample .po files
205
+ ├── dist/ # Built output
206
+ └── package.json
207
+ ```
208
+
209
+ ## 📤 Publishing to npm
210
+
211
+ > 📚 **For detailed publishing instructions, see [PUBLISHING.md](./PUBLISHING.md)**
212
+
213
+ ### Quick Publishing Guide
214
+
215
+ ```bash
216
+ # 1. Login to npm (first time only)
217
+ npm login
218
+
219
+ # 2. Build and verify
220
+ bun run build
221
+
222
+ # 3. Bump version
223
+ npm version patch # or minor/major
224
+
225
+ # 4. Publish
226
+ npm publish
227
+
228
+ # 5. Push tags
229
+ git push && git push --tags
230
+ ```
231
+
232
+ ### Quick Reference
233
+
234
+ | Command | Description |
235
+ |---------|-------------|
236
+ | `npm version patch` | Bug fixes (0.0.1 → 0.0.2) |
237
+ | `npm version minor` | New features (0.0.2 → 0.1.0) |
238
+ | `npm version major` | Breaking changes (0.1.0 → 1.0.0) |
239
+ | `npm publish` | Publish to npm registry |
240
+ | `npm pack --dry-run` | Preview what will be published |
241
+
242
+ ## 🤝 Contributing
243
+
244
+ Contributions are welcome! Please feel free to submit a Pull Request.
245
+
246
+ 1. Fork the repository
247
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
248
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
249
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
250
+ 5. Open a Pull Request
251
+
252
+ ## 📄 License
253
+
254
+ [AGPL-3.0](LICENSE) © [Michael-Obele](https://github.com/Michael-Obele)
255
+
256
+ This is a copyleft license that requires anyone who distributes your code or a derivative work to make the source available under the same terms.
257
+
258
+ ## 🔗 Links
259
+
260
+ - [GitHub Repository](https://github.com/Michael-Obele/vite-plugin-lingo)
261
+ - [npm Package](https://www.npmjs.com/package/vite-plugin-lingo)
262
+ - [Issue Tracker](https://github.com/Michael-Obele/vite-plugin-lingo/issues)
263
+
264
+ ---
265
+
266
+ **Made with ❤️ for the i18n community**
@@ -0,0 +1,8 @@
1
+ export { default as lingoPlugin } from './plugin/index.js';
2
+ export { default } from './plugin/index.js';
3
+ export type { PluginOptions, Translation, Language, LanguageStats } from './plugin/types.js';
4
+ export { default as LingoApp } from './ui/App.svelte';
5
+ export { default as LanguageList } from './ui/components/LanguageList.svelte';
6
+ export { default as TranslationEditor } from './ui/components/TranslationEditor.svelte';
7
+ export { default as SearchBar } from './ui/components/SearchBar.svelte';
8
+ export { default as ProgressBar } from './ui/components/ProgressBar.svelte';
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // Reexport your entry components here
2
+ // Main plugin export
3
+ export { default as lingoPlugin } from './plugin/index.js';
4
+ export { default } from './plugin/index.js';
5
+ // UI components (for customization)
6
+ export { default as LingoApp } from './ui/App.svelte';
7
+ export { default as LanguageList } from './ui/components/LanguageList.svelte';
8
+ export { default as TranslationEditor } from './ui/components/TranslationEditor.svelte';
9
+ export { default as SearchBar } from './ui/components/SearchBar.svelte';
10
+ export { default as ProgressBar } from './ui/components/ProgressBar.svelte';
@@ -0,0 +1,44 @@
1
+ declare module 'gettext-parser' {
2
+ export interface PoComment {
3
+ translator?: string;
4
+ reference?: string;
5
+ extracted?: string;
6
+ flag?: string;
7
+ previous?: string;
8
+ }
9
+
10
+ export interface PoTranslation {
11
+ msgid: string;
12
+ msgctxt?: string;
13
+ msgid_plural?: string;
14
+ msgstr: string[];
15
+ comments?: PoComment;
16
+ }
17
+
18
+ export interface PoTranslations {
19
+ [context: string]: {
20
+ [msgid: string]: PoTranslation;
21
+ };
22
+ }
23
+
24
+ export interface PoData {
25
+ charset?: string;
26
+ headers?: Record<string, string>;
27
+ translations: PoTranslations;
28
+ }
29
+
30
+ export interface ParseOptions {
31
+ defaultCharset?: string;
32
+ validation?: boolean;
33
+ }
34
+
35
+ export const po: {
36
+ parse(buffer: Buffer | string, options?: ParseOptions): PoData;
37
+ compile(data: PoData, options?: { foldLength?: number; sort?: boolean }): Buffer;
38
+ };
39
+
40
+ export const mo: {
41
+ parse(buffer: Buffer, options?: ParseOptions): PoData;
42
+ compile(data: PoData): Buffer;
43
+ };
44
+ }