trans-spec 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ademola Thompson
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,547 @@
1
+ # Trans-Spec
2
+
3
+ **Translate your API documentation into any language in seconds.**
4
+
5
+ Trans-Spec automatically translates OpenAPI/Swagger specifications into multiple languages using AI, then provides a beautiful local viewer to browse your multilingual API docs.
6
+
7
+ ---
8
+
9
+ ## Why Trans-Spec?
10
+
11
+ Your API is ready. Your docs are in English. But your users speak Spanish, French, German, Japanese...
12
+
13
+ **Traditional approach:**
14
+
15
+ - Manually translate every endpoint description
16
+ - Maintain separate doc files per language
17
+ - Update each translation every time your API changes
18
+ - Expensive, slow, error-prone
19
+
20
+ **Trans-Spec approach:**
21
+
22
+ ```bash
23
+ npx trans-spec generate --spec api.yaml --languages es,fr,de,ja --source en
24
+ npx trans-spec serve
25
+ ```
26
+
27
+ Done. Your API docs are now available in 5 languages with a beautiful, browsable interface.
28
+
29
+ ---
30
+
31
+ ## Features
32
+
33
+ - **AI-Powered Translation** - Uses [Lingo.dev](https://lingo.dev) for high-quality, context-aware translations
34
+ - **One Command Setup** - No configuration files, no complex setup
35
+ - **Multiple Specs Support** - Translate and view multiple API specifications
36
+ - **20+ Languages** - Supports all major languages out of the box
37
+ - **Beautiful Viewer** - Clean, professional UI automatically generated
38
+ - **Customizable Viewer** - Eject and modify the viewer to match your brand
39
+ - **Incremental Updates** - Only retranslates what changed
40
+ - **Persistent Translations** - Cached locally, version-controlled
41
+ - **Smart Term Preservation** - Keeps technical terms like `user_id` untouched
42
+
43
+ ---
44
+
45
+ ## Quick Start
46
+
47
+ ### Prerequisites
48
+
49
+ - Node.js 18+
50
+ - An OpenAPI/Swagger spec file (YAML)
51
+ - Lingo.dev API key ([Get one free](https://lingo.dev))
52
+
53
+ ### Installation
54
+
55
+ No installation required! Use `npx`:
56
+
57
+ ```bash
58
+ npx trans-spec generate --spec openapi.yaml --languages es,fr,de
59
+ ```
60
+
61
+ **First run?** On Windows, the initial setup may take 1-2 minutes as npm downloads dependencies. This only happens once. Subsequent runs are instant.
62
+
63
+ ### 1. Translate Your API Spec
64
+
65
+ ```bash
66
+ npx trans-spec generate --spec openapi.yaml --languages es,fr,de
67
+ ```
68
+
69
+ **What happens:**
70
+
71
+ - Trans-Spec reads your OpenAPI spec
72
+ - Extracts all human-readable content (descriptions, parameters, responses)
73
+ - Translates to Spanish, French, and German using AI
74
+ - Saves translations to `.trans-spec/i18n/`
75
+
76
+ **First time?** You'll be prompted for your Lingo.dev API key. Get one at [lingo.dev](https://lingo.dev) (free tier: 10,000 words/month).
77
+
78
+ ### 2. View Your Multilingual Docs
79
+
80
+ ```bash
81
+ npx trans-spec serve
82
+ ```
83
+
84
+ Opens `http://localhost:3000` with your translated API documentation.
85
+
86
+ Use the language switcher to toggle between languages instantly.
87
+
88
+ ---
89
+
90
+ ## Commands
91
+
92
+ ### `generate`
93
+
94
+ Translate your OpenAPI spec into multiple languages.
95
+
96
+ ```bash
97
+ npx trans-spec generate --spec <path> --languages <langs> [--source <lang>]
98
+ ```
99
+
100
+ **Options:**
101
+
102
+ - `--spec` (required) - Path to your OpenAPI/Swagger file
103
+ - `--languages` - Comma-separated language codes (e.g., `es,fr,de`). Required for the first translation.
104
+ - `--source` - Source language of your spec (default: `en`)
105
+
106
+ **Examples:**
107
+
108
+ ```bash
109
+ # Translate to one language
110
+ npx trans-spec generate --spec api.yaml --languages es
111
+
112
+ # Translate to multiple languages
113
+ npx trans-spec generate --spec api.yaml --languages es,fr,de,ja,zh
114
+
115
+ # Specify source language (if not English)
116
+ npx trans-spec generate --spec api.yaml --source pt --languages en,es,fr
117
+
118
+ # Add more languages to existing translations
119
+ npx trans-spec generate --spec api.yaml --languages de,ja # Adds to existing es,fr
120
+ ```
121
+
122
+ ### `serve`
123
+
124
+ Start the local documentation viewer.
125
+
126
+ ```bash
127
+ npx trans-spec serve [--port <number>]
128
+ ```
129
+
130
+ **Options:**
131
+
132
+ - `--port` - Port to run server on (default: `3000`)
133
+
134
+ **Examples:**
135
+
136
+ ```bash
137
+ # Start on default port 3000
138
+ npx trans-spec serve
139
+
140
+ # Start on custom port
141
+ npx trans-spec serve --port 8080
142
+ ```
143
+
144
+ **First time running serve?** You'll be prompted to enter your Lingo.dev API key. This is needed to translate the viewer's UI labels (buttons, headers, etc.) to match your API spec's languages. The key is saved to `.env` for future use. DO NOT COMMIT THIS KEY TO GIT.
145
+
146
+ ### `eject`
147
+
148
+ Copy the viewer source code into your project for full customization.
149
+
150
+ ```bash
151
+ npx trans-spec eject
152
+ ```
153
+
154
+ **What it does:**
155
+
156
+ - Copies the entire React viewer into `./trans-spec-viewer/`
157
+ - Gives you complete control over the UI
158
+ - The ejected viewer is automatically detected and used by `serve`
159
+
160
+ **After ejecting:**
161
+
162
+ ```bash
163
+ cd trans-spec-viewer
164
+ npm install
165
+
166
+ # Customize the code in src/
167
+ # Modify components, styling, layout, etc.
168
+
169
+ # Then serve uses your customized version automatically
170
+ npx trans-spec serve
171
+ ```
172
+
173
+ **Use cases for ejecting:**
174
+
175
+ - **Branding** - Add your logo, colors, and company styling
176
+ - **Custom Features** - Add authentication, analytics, search, etc.
177
+ - **Layout Changes** - Modify the sidebar, add tabs, change structure
178
+ - **Deployment** - Build and deploy as a standalone documentation site
179
+ - **Integration** - Embed into existing docs or portals
180
+
181
+ **Example customizations:**
182
+
183
+ ```jsx
184
+ // trans-spec-viewer/src/App.jsx
185
+ // Add your logo
186
+ <header className="...">
187
+ <img src="/logo.png" alt="Company" />
188
+ <h1>{spec?.info?.title}</h1>
189
+ </header>
190
+
191
+ // trans-spec-viewer/src/components/Sidebar.jsx
192
+ // Change colors to match your brand
193
+ <button className="bg-blue-600 hover:bg-blue-700">
194
+ {/* Your custom styling */}
195
+ </button>
196
+ ```
197
+
198
+ **Building for production:**
199
+
200
+ ```bash
201
+ cd trans-spec-viewer
202
+ npm run build
203
+ # Outputs to dist/ - deploy to Vercel, Netlify, GitHub Pages, etc.
204
+ ```
205
+
206
+ ---
207
+
208
+ ## Usage
209
+
210
+ ### Basic Translation
211
+
212
+ ```bash
213
+ # Translate to one language
214
+ npx trans-spec generate --spec api.yaml --languages es
215
+
216
+ # Translate to multiple languages
217
+ npx trans-spec generate --spec api.yaml --languages es,fr,de,ja,zh
218
+ ```
219
+
220
+ ### Specify Source Language
221
+
222
+ By default, Trans-Spec assumes your spec is in English. If it's in another language:
223
+
224
+ ```bash
225
+ npx trans-spec generate --spec api.yaml --source pt --languages en,es,fr
226
+ ```
227
+
228
+ ### Add More Languages Later
229
+
230
+ ```bash
231
+ # Already translated to Spanish and French
232
+ # Now add German and Japanese
233
+ npx trans-spec generate --spec api.yaml --languages de,ja
234
+ ```
235
+
236
+ Trans-Spec automatically **merges** new languages with existing ones. Your previous translations stay intact.
237
+
238
+ ### Multiple API Specs
239
+
240
+ ```bash
241
+ npx trans-spec generate --spec api-v1.yaml --languages es,fr
242
+ npx trans-spec generate --spec api-v2.yaml --languages es,fr
243
+ ```
244
+
245
+ Both specs are translated and viewable. The viewer shows a dropdown to switch between them.
246
+
247
+ ### Update Your Spec
248
+
249
+ Made changes to your API? Just re-run the generate command without specifying languages:
250
+
251
+ ```bash
252
+ npx trans-spec generate --spec api.yaml
253
+ ```
254
+
255
+ Trans-Spec automatically:
256
+
257
+ - Uses your existing language configuration
258
+ - Only retranslates what changed
259
+ - Saves time and API credits
260
+
261
+ Want to add more languages? Include the --languages flag:
262
+
263
+ ```bash
264
+ npx trans-spec generate --spec api.yaml --languages de,ja
265
+ ```
266
+
267
+ This adds German and Japanese to your existing translations without affecting the others.
268
+
269
+ ---
270
+
271
+ ## How It Works
272
+
273
+ ### 1. **Intelligent Extraction**
274
+
275
+ Trans-Spec parses your OpenAPI spec and identifies what needs translation:
276
+
277
+ - ✅ Endpoint summaries and descriptions
278
+ - ✅ Parameter descriptions
279
+ - ✅ Response descriptions
280
+ - ✅ Error messages
281
+ - ❌ Parameter names (e.g., `user_id` stays as-is)
282
+ - ❌ Enum values (e.g., `draft`, `active`)
283
+ - ❌ Code examples
284
+ - ❌ URLs and paths
285
+
286
+ ### 2. **AI Translation**
287
+
288
+ Uses Lingo.dev's specialized translation engine:
289
+
290
+ - Context-aware (understands it's API documentation)
291
+ - Preserves technical terms automatically
292
+ - Maintains formatting (markdown, code blocks)
293
+ - Consistent terminology across endpoints
294
+
295
+ ### 3. **Smart Caching**
296
+
297
+ - Translations stored in `.trans-spec/i18n/`
298
+ - Version-controlled alongside your spec
299
+ - Only changed content gets retranslated
300
+ - Works offline after initial translation
301
+
302
+ ### 4. **Beautiful Viewer**
303
+
304
+ - Automatically generates a browsable interface
305
+ - Sidebar navigation by endpoint
306
+ - Language switcher (UI and API docs stay in sync)
307
+ - Clean, professional design
308
+ - Responsive (works on mobile)
309
+ - Fully customizable via `eject` command
310
+
311
+ ---
312
+
313
+ ## Supported Languages
314
+
315
+ Trans-Spec supports 20+ languages including:
316
+
317
+ 🇪🇸 Spanish (es) • 🇫🇷 French (fr) • 🇩🇪 German (de) • 🇮🇹 Italian (it) • 🇵🇹 Portuguese (pt, pt-BR)
318
+ 🇯🇵 Japanese (ja) • 🇨🇳 Chinese (zh, zh-Hans, zh-Hant) • 🇰🇷 Korean (ko)
319
+ 🇷🇺 Russian (ru) • 🇸🇦 Arabic (ar) • 🇮🇳 Hindi (hi) • 🇳🇱 Dutch (nl) • 🇵🇱 Polish (pl) • 🇹🇷 Turkish (tr)
320
+
321
+ See [Lingo.dev's supported locales](https://lingo.dev/cli/commands/show#locale-sources) for the full list.
322
+
323
+ ---
324
+
325
+ ## Customization
326
+
327
+ ### Eject the Viewer
328
+
329
+ Want complete control over the UI? Eject the viewer:
330
+
331
+ ```bash
332
+ npx trans-spec eject
333
+ ```
334
+
335
+ This creates `./trans-spec-viewer/` with the full React source. You can now:
336
+
337
+ **1. Customize the Design:**
338
+
339
+ ```bash
340
+ cd trans-spec-viewer/src
341
+ # Edit App.jsx, components/, or styles
342
+ ```
343
+
344
+ **2. Add Features:**
345
+
346
+ - Authentication/authorization
347
+ - Analytics tracking
348
+ - Custom navigation
349
+ - API key management
350
+ - Rate limiting display
351
+ - Webhook integration
352
+
353
+ **3. Deploy Independently:**
354
+
355
+ ```bash
356
+ cd trans-spec-viewer
357
+ npm run build
358
+ # Deploy dist/ to your hosting platform
359
+ ```
360
+
361
+ **4. Version Control:**
362
+
363
+ - Commit `trans-spec-viewer/` to your repo
364
+ - Your team gets the same customized viewer
365
+ - Track changes over time
366
+
367
+ The ejected viewer is **automatically used** by `npx trans-spec serve` - no additional configuration needed.
368
+
369
+ ### Manual Translation Edits
370
+
371
+ Translations are stored as YAML files:
372
+
373
+ ```
374
+ .trans-spec/
375
+ i18n/
376
+ en/
377
+ api.yaml
378
+ es/
379
+ api.yaml
380
+ fr/
381
+ api.yaml
382
+ ```
383
+
384
+ Edit them directly:
385
+
386
+ ```yaml
387
+ # .trans-spec/i18n/es/api.yaml
388
+ paths:
389
+ /users:
390
+ get:
391
+ summary: Obtener lista de usuarios
392
+ description: Recupera todos los usuarios del sistema
393
+ ```
394
+
395
+ Restart the viewer to see changes.
396
+
397
+ ---
398
+
399
+ ## Platform-Specific Notes
400
+
401
+ ### Windows
402
+
403
+ **First run may take time:** The initial `npx trans-spec generate` command downloads dependencies. On Windows, this can take 1-2 minutes due to npm package resolution. You'll see:
404
+
405
+ ```
406
+ 🌍 Trans-Spec
407
+ ⠋ Checking authentication (downloading dependencies on first run, this may take a minute)...
408
+ ```
409
+
410
+ **This only happens once.** Subsequent runs are instant.
411
+
412
+ **PowerShell users:** If you see execution policy errors:
413
+
414
+ ```powershell
415
+ Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
416
+ ```
417
+
418
+ **Git Bash users:** Commands work as-is.
419
+
420
+ ### macOS/Linux
421
+
422
+ No special setup required. Commands work out of the box.
423
+
424
+ ---
425
+
426
+ ## Troubleshooting
427
+
428
+ ### Command hangs at "Checking authentication..."
429
+
430
+ **Symptom:** First run shows spinning loader for 1-2 minutes
431
+
432
+ **Cause:** npm is downloading dependencies (one-time setup on Windows)
433
+
434
+ **Solution:** Wait for completion. Message explains this is expected. Subsequent runs are instant.
435
+
436
+ ### "No .trans-spec folder found"
437
+
438
+ **Solution:** Run `npx trans-spec generate --spec api.yaml --languages es,fr` first to create translations.
439
+
440
+ ### "Authentication failed"
441
+
442
+ **Solution:**
443
+
444
+ 1. Get your API key from [lingo.dev](https://lingo.dev) → Settings
445
+ 2. You'll be prompted to enter it when running commands
446
+ 3. It's saved locally for future use
447
+
448
+ ### "Translation failed"
449
+
450
+ **Possible causes:**
451
+
452
+ - No internet connection
453
+ - API rate limit exceeded (free tier: 10,000 words/month)
454
+ - Invalid OpenAPI spec format
455
+
456
+ **Solution:** Check the error message.
457
+
458
+ ### Translations look wrong
459
+
460
+ **Solution:**
461
+
462
+ - Delete `.trans-spec/` folder
463
+ - Run `npx trans-spec generate` again for fresh translations
464
+ - Or manually edit `.trans-spec/i18n/{lang}/api.yaml`
465
+
466
+ ### Viewer won't start after eject
467
+
468
+ **Solution:**
469
+
470
+ ```bash
471
+ cd trans-spec-viewer
472
+ rm -rf node_modules package-lock.json
473
+ npm install
474
+ npx trans-spec serve
475
+ ```
476
+
477
+ ### "API key not found" when running serve
478
+
479
+ **Solution:** You'll be prompted to enter your Lingo.dev API key. This is saved to the viewer's `.env` file for future use. The key is needed to translate the viewer's UI labels to match your spec's languages.
480
+
481
+ ---
482
+
483
+ ## FAQ
484
+
485
+ **Q: Is this free?**
486
+ A: Trans-Spec itself is free and open source. Translation costs depend on your Lingo.dev plan. Free tier: 10,000 words/month (enough for most small-medium APIs).
487
+
488
+ **Q: Can I use my own translation service?**
489
+ A: Currently, Trans-Spec uses Lingo.dev exclusively for best results. Support for other providers may be added in the future.
490
+
491
+ **Q: Does this work with Swagger 2.0?**
492
+ A: Yes! Trans-Spec supports both OpenAPI 3.x and Swagger 2.0.
493
+
494
+ **Q: Can I edit translations manually?**
495
+ A: Yes. Translations are in `.trans-spec/i18n/{lang}/api.yaml`. Edit directly and restart the viewer.
496
+
497
+ **Q: Will my API calls still work in other languages?**
498
+ A: Your API itself doesn't change. Only the **documentation** is translated. Endpoints, parameter names, and code examples remain unchanged.
499
+
500
+ **Q: How accurate are the translations?**
501
+ A: Lingo.dev uses specialized AI models for technical documentation. Accuracy is very high, but always review critical content.
502
+
503
+ **Q: Can I deploy the docs as a public website?**
504
+ A: Yes! Run `npx trans-spec eject`, then:
505
+
506
+ ```bash
507
+ cd trans-spec-viewer
508
+ npm run build
509
+ # Deploy dist/ to Vercel, Netlify, GitHub Pages, etc.
510
+ ```
511
+
512
+ **Q: Does this modify my original spec file?**
513
+ A: No. Your original spec is never touched. Translations are stored separately in `.trans-spec/`.
514
+
515
+ **Q: What happens if I eject and then update Trans-Spec?**
516
+ A: Your ejected viewer is independent. It won't be affected by Trans-Spec updates. You maintain full control.
517
+
518
+ **Q: Can I eject multiple times?**
519
+ A: No. Once ejected, the `trans-spec-viewer/` folder exists. Delete it first if you want to eject again with a fresh copy.
520
+
521
+ ---
522
+
523
+ ## Contributing
524
+
525
+ Contributions are welcome! Please open an issue or PR on [GitHub](https://github.com/ade555/trans-spec).
526
+
527
+ ---
528
+
529
+ ## License
530
+
531
+ MIT © Ademola Thompson
532
+
533
+ ---
534
+
535
+ ## Credits
536
+
537
+ Built with:
538
+
539
+ - [Lingo.dev](https://lingo.dev) - AI translation engine
540
+ - [Swagger Parser](https://github.com/APIDevTools/swagger-parser) - OpenAPI parsing
541
+ - [React](https://react.dev) - UI framework
542
+ - [Vite](https://vitejs.dev) - Build tool
543
+ - [Tailwind CSS](https://tailwindcss.com) - Styling
544
+
545
+ ---
546
+
547
+ **Made with ❤️ for developers building global APIs**