appshot-cli 0.2.0 → 0.3.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/README.md +277 -17
- package/dist/cli.js +1 -1
- package/dist/commands/caption.d.ts.map +1 -1
- package/dist/commands/caption.js +74 -2
- package/dist/commands/caption.js.map +1 -1
- package/dist/commands/localize.d.ts.map +1 -1
- package/dist/commands/localize.js +150 -14
- package/dist/commands/localize.js.map +1 -1
- package/dist/commands/presets.d.ts.map +1 -1
- package/dist/commands/presets.js +10 -1
- package/dist/commands/presets.js.map +1 -1
- package/dist/commands/validate.d.ts.map +1 -1
- package/dist/commands/validate.js +64 -7
- package/dist/commands/validate.js.map +1 -1
- package/dist/services/translation.d.ts +18 -0
- package/dist/services/translation.d.ts.map +1 -0
- package/dist/services/translation.js +201 -0
- package/dist/services/translation.js.map +1 -0
- package/dist/types/ai.d.ts +25 -0
- package/dist/types/ai.d.ts.map +1 -0
- package/dist/types/ai.js +73 -0
- package/dist/types/ai.js.map +1 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -13,13 +13,14 @@ Generate beautiful, App Store-ready screenshots with device frames, gradients, a
|
|
|
13
13
|
- 🖼️ **Smart Frames** - Automatically detects portrait/landscape and selects appropriate device frame
|
|
14
14
|
- 🎨 **Gradients** - Beautiful gradient backgrounds with customizable colors
|
|
15
15
|
- ✏️ **Captions** - Add marketing text with full typography control (above or overlay)
|
|
16
|
-
- 🌍 **Localization** - Multi-language support for international app stores
|
|
16
|
+
- 🌍 **Localization** - Multi-language support with AI-powered translations for international app stores
|
|
17
17
|
- 📱 **Multi-Device** - Support for iPhone, iPad, Mac, Apple TV, Vision Pro, and Apple Watch
|
|
18
18
|
- 📏 **App Store Specs** - Built-in support for all official App Store screenshot resolutions
|
|
19
19
|
- ✅ **Validation** - Verify screenshots meet App Store requirements
|
|
20
20
|
- 🔄 **Orientation Detection** - Intelligently handles both portrait and landscape screenshots
|
|
21
21
|
- ⚡ **Fast** - Parallel processing with configurable concurrency
|
|
22
|
-
-
|
|
22
|
+
- 🤖 **AI Translation** - Real-time and batch translation using OpenAI models (GPT-4o, GPT-5, o1, o3)
|
|
23
|
+
- 🛠️ **CLI** - Simple command-line interface designed for agents and automation
|
|
23
24
|
|
|
24
25
|
## Quick Start
|
|
25
26
|
|
|
@@ -200,7 +201,7 @@ Options:
|
|
|
200
201
|
- `--force` - Overwrite existing files
|
|
201
202
|
|
|
202
203
|
### `appshot caption`
|
|
203
|
-
Interactively add or edit captions for screenshots with intelligent autocomplete.
|
|
204
|
+
Interactively add or edit captions for screenshots with intelligent autocomplete and AI-powered translation.
|
|
204
205
|
|
|
205
206
|
Features:
|
|
206
207
|
- **Autocomplete suggestions** - Shows previous captions as you type
|
|
@@ -208,10 +209,23 @@ Features:
|
|
|
208
209
|
- **Usage tracking** - Frequently used captions appear first
|
|
209
210
|
- **Learning system** - Improves suggestions over time
|
|
210
211
|
- **Device-specific** - Prioritizes captions used for the same device
|
|
212
|
+
- **Real-time translation** - Instantly translate captions as you type (requires OpenAI API key)
|
|
211
213
|
|
|
212
214
|
Options:
|
|
213
215
|
- `--device <name>` - Device name (required)
|
|
214
|
-
- `--lang <code>` -
|
|
216
|
+
- `--lang <code>` - Primary language code (default: en)
|
|
217
|
+
- `--translate` - Enable AI-powered real-time translation
|
|
218
|
+
- `--langs <codes>` - Target languages for translation (comma-separated)
|
|
219
|
+
- `--model <name>` - OpenAI model to use (default: gpt-4o-mini)
|
|
220
|
+
|
|
221
|
+
Example with translation:
|
|
222
|
+
```bash
|
|
223
|
+
# Add captions with instant translation to Spanish and French
|
|
224
|
+
appshot caption --device iphone --translate --langs es,fr
|
|
225
|
+
|
|
226
|
+
# Use a specific model for translation
|
|
227
|
+
appshot caption --device iphone --translate --langs zh-CN,ja --model gpt-5
|
|
228
|
+
```
|
|
215
229
|
|
|
216
230
|
Keyboard shortcuts:
|
|
217
231
|
- **Tab** - Autocomplete the top suggestion
|
|
@@ -369,24 +383,206 @@ Options:
|
|
|
369
383
|
- `--strict` - Validate against required presets only
|
|
370
384
|
- `--fix` - Suggest fixes for invalid screenshots
|
|
371
385
|
|
|
372
|
-
### `appshot localize`
|
|
373
|
-
Generate translations for captions using
|
|
386
|
+
### `appshot localize`
|
|
387
|
+
Generate translations for all existing captions using OpenAI's powerful language models.
|
|
374
388
|
|
|
375
389
|
Options:
|
|
376
|
-
- `--langs <codes>` - Target languages
|
|
377
|
-
- `--device <name>` - Specific device or all
|
|
378
|
-
- `--
|
|
390
|
+
- `--langs <codes>` - Target languages (comma-separated, required)
|
|
391
|
+
- `--device <name>` - Specific device or all devices
|
|
392
|
+
- `--model <name>` - OpenAI model to use (default: gpt-4o-mini)
|
|
393
|
+
- `--source <lang>` - Source language (default: en)
|
|
394
|
+
- `--review` - Review translations before saving
|
|
395
|
+
- `--overwrite` - Overwrite existing translations
|
|
396
|
+
|
|
397
|
+
Supported models:
|
|
398
|
+
- **GPT-4o models**: gpt-4o, gpt-4o-mini (using max_tokens)
|
|
399
|
+
- **GPT-5 models**: gpt-5, gpt-5-mini, gpt-5-nano (using max_completion_tokens)
|
|
400
|
+
- **o1 models**: o1, o1-mini (reasoning models)
|
|
401
|
+
- **o3 models**: o3, o3-mini (latest reasoning models)
|
|
402
|
+
|
|
403
|
+
Example usage:
|
|
404
|
+
```bash
|
|
405
|
+
# Translate all captions to Spanish, French, and German
|
|
406
|
+
appshot localize --langs es,fr,de
|
|
407
|
+
|
|
408
|
+
# Translate iPhone captions only, with review
|
|
409
|
+
appshot localize --device iphone --langs ja,ko --review
|
|
410
|
+
|
|
411
|
+
# Use GPT-5 for higher quality translations
|
|
412
|
+
appshot localize --langs zh-CN,zh-TW --model gpt-5
|
|
413
|
+
|
|
414
|
+
# Overwrite existing translations with new ones
|
|
415
|
+
appshot localize --langs es,fr --overwrite
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Setup:
|
|
419
|
+
```bash
|
|
420
|
+
# Set your OpenAI API key
|
|
421
|
+
export OPENAI_API_KEY="your-api-key-here"
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
## AI-Powered Translation 🤖
|
|
425
|
+
|
|
426
|
+
Appshot includes powerful AI translation capabilities using OpenAI's latest models, including GPT-4o, GPT-5, and reasoning models (o1, o3).
|
|
427
|
+
|
|
428
|
+
### Setup
|
|
429
|
+
|
|
430
|
+
First, set your OpenAI API key:
|
|
431
|
+
```bash
|
|
432
|
+
export OPENAI_API_KEY="your-api-key-here"
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Real-Time Translation
|
|
436
|
+
|
|
437
|
+
Translate captions instantly as you type them:
|
|
438
|
+
|
|
439
|
+
```bash
|
|
440
|
+
# Add captions with automatic translation to Spanish and French
|
|
441
|
+
appshot caption --device iphone --translate --langs es,fr
|
|
442
|
+
|
|
443
|
+
# Use a specific model for higher quality
|
|
444
|
+
appshot caption --device iphone --translate --langs zh-CN,ja --model gpt-5
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
When you enter a caption, translations appear immediately below:
|
|
448
|
+
```
|
|
449
|
+
? home.png: Welcome to the future
|
|
450
|
+
es: Bienvenido al futuro
|
|
451
|
+
fr: Bienvenue dans le futur
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Batch Translation
|
|
455
|
+
|
|
456
|
+
Translate all existing captions at once:
|
|
457
|
+
|
|
458
|
+
```bash
|
|
459
|
+
# Translate all captions to multiple languages
|
|
460
|
+
appshot localize --langs es,fr,de,ja,zh-CN
|
|
461
|
+
|
|
462
|
+
# Translate specific device only
|
|
463
|
+
appshot localize --device iphone --langs es,fr
|
|
464
|
+
|
|
465
|
+
# Review translations before saving
|
|
466
|
+
appshot localize --langs es,fr --review
|
|
467
|
+
|
|
468
|
+
# Use GPT-5 for best quality
|
|
469
|
+
appshot localize --langs ja,ko --model gpt-5
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### Supported Models
|
|
473
|
+
|
|
474
|
+
Appshot intelligently handles different OpenAI models and their specific requirements:
|
|
475
|
+
|
|
476
|
+
#### GPT-4o Series (General Purpose)
|
|
477
|
+
- **Models**: `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo`
|
|
478
|
+
- **Best for**: Fast, cost-effective translations
|
|
479
|
+
- **Parameter**: Uses `max_tokens`
|
|
480
|
+
- **Temperature**: Configurable (default 0.3)
|
|
481
|
+
|
|
482
|
+
#### GPT-5 Series (Advanced)
|
|
483
|
+
- **Models**: `gpt-5`, `gpt-5-mini`, `gpt-5-nano`
|
|
484
|
+
- **Best for**: High-quality, nuanced translations
|
|
485
|
+
- **Parameter**: Uses `max_completion_tokens`
|
|
486
|
+
- **Temperature**: Fixed at 1.0 (reasoning model requirement)
|
|
487
|
+
|
|
488
|
+
#### o1 Series (Deep Reasoning)
|
|
489
|
+
- **Models**: `o1`, `o1-mini`
|
|
490
|
+
- **Best for**: Complex marketing copy with cultural adaptation
|
|
491
|
+
- **Parameter**: Uses `max_completion_tokens`
|
|
492
|
+
- **Temperature**: Fixed at 1.0
|
|
493
|
+
|
|
494
|
+
#### o3 Series (Latest Reasoning)
|
|
495
|
+
- **Models**: `o3`, `o3-mini`
|
|
496
|
+
- **Best for**: State-of-the-art translation quality
|
|
497
|
+
- **Parameter**: Uses `max_completion_tokens`
|
|
498
|
+
- **Temperature**: Fixed at 1.0
|
|
499
|
+
|
|
500
|
+
### Language Support
|
|
501
|
+
|
|
502
|
+
Built-in support for 25+ languages:
|
|
503
|
+
- **European**: Spanish (es), French (fr), German (de), Italian (it), Portuguese (pt), Dutch (nl), Swedish (sv), Norwegian (no), Danish (da), Finnish (fi), Polish (pl), Russian (ru)
|
|
504
|
+
- **Asian**: Japanese (ja), Korean (ko), Simplified Chinese (zh-CN), Traditional Chinese (zh-TW), Hindi (hi), Thai (th), Vietnamese (vi), Indonesian (id), Malay (ms)
|
|
505
|
+
- **Middle Eastern**: Arabic (ar), Hebrew (he), Turkish (tr)
|
|
506
|
+
- **Portuguese Variants**: Brazilian Portuguese (pt-BR)
|
|
507
|
+
|
|
508
|
+
### Translation Features
|
|
509
|
+
|
|
510
|
+
#### Smart Caching
|
|
511
|
+
Translations are cached to avoid duplicate API calls. If you translate the same caption again, it returns instantly without using API credits.
|
|
512
|
+
|
|
513
|
+
#### Marketing-Optimized Prompts
|
|
514
|
+
The system uses specialized prompts designed for app marketing text:
|
|
515
|
+
- Maintains marketing tone and impact
|
|
516
|
+
- Keeps translations concise
|
|
517
|
+
- Ensures cultural appropriateness
|
|
518
|
+
- Preserves call-to-action strength
|
|
519
|
+
|
|
520
|
+
#### Error Handling
|
|
521
|
+
- Graceful fallback if API is unavailable
|
|
522
|
+
- Clear error messages for rate limits
|
|
523
|
+
- Automatic retry with delays for batch operations
|
|
524
|
+
- Continues with other translations if one fails
|
|
525
|
+
|
|
526
|
+
### Advanced Configuration
|
|
527
|
+
|
|
528
|
+
Create `.appshot/ai-config.json` for custom settings:
|
|
529
|
+
|
|
530
|
+
```json
|
|
531
|
+
{
|
|
532
|
+
"defaultModel": "gpt-5",
|
|
533
|
+
"temperature": 0.3,
|
|
534
|
+
"cache": true,
|
|
535
|
+
"systemPrompt": "You are translating premium app marketing text. Keep it impactful and concise."
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
### Cost Optimization Tips
|
|
540
|
+
|
|
541
|
+
1. **Use `gpt-4o-mini`** for draft translations (very cost-effective)
|
|
542
|
+
2. **Enable caching** to avoid retranslating identical text
|
|
543
|
+
3. **Batch operations** are more efficient than real-time for large projects
|
|
544
|
+
4. **Review mode** lets you verify before committing translations
|
|
545
|
+
|
|
546
|
+
### Example Workflow
|
|
547
|
+
|
|
548
|
+
```bash
|
|
549
|
+
# 1. Initialize project
|
|
550
|
+
appshot init
|
|
551
|
+
|
|
552
|
+
# 2. Add screenshots
|
|
553
|
+
cp ~/Desktop/screenshots/*.png screenshots/iphone/
|
|
554
|
+
|
|
555
|
+
# 3. Add captions with instant translation
|
|
556
|
+
appshot caption --device iphone --translate --langs es,fr,de
|
|
557
|
+
|
|
558
|
+
# 4. Build localized screenshots
|
|
559
|
+
appshot build --langs en,es,fr,de
|
|
560
|
+
|
|
561
|
+
# Output structure:
|
|
562
|
+
# final/
|
|
563
|
+
# iphone/
|
|
564
|
+
# en/
|
|
565
|
+
# home.png
|
|
566
|
+
# es/
|
|
567
|
+
# home.png
|
|
568
|
+
# fr/
|
|
569
|
+
# home.png
|
|
570
|
+
# de/
|
|
571
|
+
# home.png
|
|
572
|
+
```
|
|
379
573
|
|
|
380
574
|
## Multi-Language Support
|
|
381
575
|
|
|
382
|
-
Captions
|
|
576
|
+
Captions are stored with all translations in JSON format:
|
|
383
577
|
|
|
384
578
|
```json
|
|
385
579
|
{
|
|
386
580
|
"home.png": {
|
|
387
581
|
"en": "Organize your life",
|
|
388
582
|
"fr": "Organisez votre vie",
|
|
389
|
-
"es": "Organiza tu vida"
|
|
583
|
+
"es": "Organiza tu vida",
|
|
584
|
+
"de": "Organisieren Sie Ihr Leben",
|
|
585
|
+
"ja": "人生を整理する"
|
|
390
586
|
}
|
|
391
587
|
}
|
|
392
588
|
```
|
|
@@ -732,6 +928,64 @@ To reset a device to default settings:
|
|
|
732
928
|
appshot style --device iphone --reset
|
|
733
929
|
```
|
|
734
930
|
|
|
931
|
+
## Agent-First Design 🤖
|
|
932
|
+
|
|
933
|
+
Appshot is designed to work seamlessly with LLM agents and automation tools. The CLI interface is structured for predictable, scriptable operations that agents can easily control.
|
|
934
|
+
|
|
935
|
+
### Working with AI Agents
|
|
936
|
+
|
|
937
|
+
- **Structured Commands** - All commands have consistent, predictable outputs
|
|
938
|
+
- **JSON Support** - Most commands support `--json` output for agent parsing
|
|
939
|
+
- **Error Codes** - Consistent exit codes for automation workflows
|
|
940
|
+
- **File-Based Config** - Agents can modify `.appshot/config.json` directly
|
|
941
|
+
- **Batch Operations** - Process multiple devices/languages in single commands
|
|
942
|
+
|
|
943
|
+
### MCP (Model Context Protocol) Integration
|
|
944
|
+
|
|
945
|
+
Appshot works perfectly with MCP screenshot tools:
|
|
946
|
+
|
|
947
|
+
```bash
|
|
948
|
+
# Agent takes screenshot via MCP
|
|
949
|
+
mcp-screenshot capture --app "MyApp" --output ./screenshots/iphone/home.png
|
|
950
|
+
|
|
951
|
+
# Agent processes with appshot
|
|
952
|
+
appshot build --devices iphone
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
### Agent Workflow Example
|
|
956
|
+
|
|
957
|
+
```python
|
|
958
|
+
# Example: Agent automating screenshot generation
|
|
959
|
+
def generate_app_store_screenshots():
|
|
960
|
+
# 1. Agent captures screenshots from simulator/device
|
|
961
|
+
run_command("xcrun simctl io booted screenshot screen1.png")
|
|
962
|
+
|
|
963
|
+
# 2. Agent initializes appshot project
|
|
964
|
+
run_command("appshot init")
|
|
965
|
+
|
|
966
|
+
# 3. Agent configures styling
|
|
967
|
+
modify_json(".appshot/config.json", {
|
|
968
|
+
"gradient": {"colors": ["#FF5733", "#FFC300"]},
|
|
969
|
+
"devices": {"iphone": {"frameScale": 0.85}}
|
|
970
|
+
})
|
|
971
|
+
|
|
972
|
+
# 4. Agent adds captions programmatically
|
|
973
|
+
modify_json(".appshot/captions/iphone.json", {
|
|
974
|
+
"screen1.png": "Your perfect companion"
|
|
975
|
+
})
|
|
976
|
+
|
|
977
|
+
# 5. Agent builds final screenshots
|
|
978
|
+
run_command("appshot build --devices iphone")
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
### Why CLI-Only?
|
|
982
|
+
|
|
983
|
+
- **Predictable** - Agents need consistent, scriptable interfaces
|
|
984
|
+
- **Composable** - Integrates with any automation pipeline
|
|
985
|
+
- **Version Control** - All config is text files, perfect for Git
|
|
986
|
+
- **Fast** - No UI overhead, pure processing power
|
|
987
|
+
- **Universal** - Works on any system with Node.js
|
|
988
|
+
|
|
735
989
|
## Roadmap
|
|
736
990
|
|
|
737
991
|
- [x] Official App Store specifications support
|
|
@@ -739,12 +993,18 @@ appshot style --device iphone --reset
|
|
|
739
993
|
- [x] Partial frame support
|
|
740
994
|
- [x] Intelligent caption autocomplete
|
|
741
995
|
- [x] Apple Watch optimizations
|
|
742
|
-
- [
|
|
743
|
-
- [
|
|
744
|
-
- [ ]
|
|
745
|
-
- [ ]
|
|
746
|
-
- [ ]
|
|
747
|
-
- [ ]
|
|
996
|
+
- [x] Gradient presets system (24+ gradients)
|
|
997
|
+
- [x] **AI-Powered Translations** - Translate captions using OpenAI models (GPT-4o, GPT-5, o1, o3)
|
|
998
|
+
- [ ] **MCP Integration Guide** - Documentation for screenshot tool integration
|
|
999
|
+
- [ ] **Agent API Mode** - Structured JSON input/output for all commands
|
|
1000
|
+
- [ ] **Android Device Support** - Google Play Store specifications
|
|
1001
|
+
- [ ] **Batch Config Files** - Process multiple configurations in one run
|
|
1002
|
+
- [ ] **Screenshot Validation API** - Programmatic validation for CI/CD
|
|
1003
|
+
- [ ] **Auto-Caption Generation** - Use AI to generate marketing captions from screenshots
|
|
1004
|
+
- [ ] **Smart Frame Detection** - AI-powered frame selection based on screenshot content
|
|
1005
|
+
- [ ] **Pipeline Mode** - Stream processing for large batches
|
|
1006
|
+
- [ ] **WebP/AVIF Support** - Modern image formats for smaller files
|
|
1007
|
+
- [ ] **Differential Builds** - Only rebuild changed screenshots
|
|
748
1008
|
|
|
749
1009
|
## Support
|
|
750
1010
|
|
package/dist/cli.js
CHANGED
|
@@ -15,7 +15,7 @@ const program = new Command();
|
|
|
15
15
|
program
|
|
16
16
|
.name('appshot')
|
|
17
17
|
.description('Generate App Store–ready screenshots with frames, gradients, and captions.')
|
|
18
|
-
.version('0.
|
|
18
|
+
.version('0.3.0');
|
|
19
19
|
program.addCommand(initCmd());
|
|
20
20
|
program.addCommand(captionCmd());
|
|
21
21
|
program.addCommand(styleCmd());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caption.d.ts","sourceRoot":"","sources":["../../src/commands/caption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"caption.d.ts","sourceRoot":"","sources":["../../src/commands/caption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,MAAM,CAAC,OAAO,UAAU,UAAU,YA0MjC"}
|
package/dist/commands/caption.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import autocomplete from 'inquirer-autocomplete-standalone';
|
|
3
|
+
import { select } from '@inquirer/prompts';
|
|
3
4
|
import fuzzy from 'fuzzy';
|
|
4
5
|
import { promises as fs } from 'fs';
|
|
5
6
|
import path from 'path';
|
|
6
7
|
import pc from 'picocolors';
|
|
8
|
+
import { translationService } from '../services/translation.js';
|
|
7
9
|
import { loadCaptionHistory, saveCaptionHistory, updateFrequency, addToSuggestions, getSuggestions, learnFromExistingCaptions } from '../utils/caption-history.js';
|
|
8
10
|
export default function captionCmd() {
|
|
9
11
|
const cmd = new Command('caption')
|
|
10
12
|
.description('Interactively add/edit captions in a device folder')
|
|
11
13
|
.requiredOption('--device <name>', 'device name (iphone|ipad|mac|watch)')
|
|
12
|
-
.option('--lang <code>', 'language code', 'en')
|
|
13
|
-
.
|
|
14
|
+
.option('--lang <code>', 'primary language code', 'en')
|
|
15
|
+
.option('--translate', 'enable AI-powered translation')
|
|
16
|
+
.option('--langs <codes>', 'target languages for translation (comma-separated)')
|
|
17
|
+
.option('--model <name>', 'OpenAI model to use', 'gpt-4o-mini')
|
|
18
|
+
.action(async ({ device, lang, translate, langs, model }) => {
|
|
14
19
|
try {
|
|
15
20
|
const dir = path.join(process.cwd(), 'screenshots', device);
|
|
16
21
|
const captionsFile = path.join(process.cwd(), '.appshot', 'captions', `${device}.json`);
|
|
@@ -44,6 +49,49 @@ export default function captionCmd() {
|
|
|
44
49
|
// Load caption history for autocomplete
|
|
45
50
|
const history = await loadCaptionHistory();
|
|
46
51
|
await learnFromExistingCaptions(history);
|
|
52
|
+
// Check translation setup
|
|
53
|
+
let targetLanguages = [];
|
|
54
|
+
let selectedModel = model;
|
|
55
|
+
if (translate) {
|
|
56
|
+
if (!translationService.hasApiKey()) {
|
|
57
|
+
console.error(pc.red('Error:'), 'OpenAI API key not found');
|
|
58
|
+
console.log(pc.dim('Set the OPENAI_API_KEY environment variable to enable translations'));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
// Parse target languages
|
|
62
|
+
if (langs) {
|
|
63
|
+
targetLanguages = langs.split(',').map((l) => l.trim());
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// Ask for target languages if not provided
|
|
67
|
+
console.log(pc.cyan('\nSelect target languages for translation:'));
|
|
68
|
+
console.log(pc.dim('Common options: es, fr, de, it, pt, ja, ko, zh-CN'));
|
|
69
|
+
const langsInput = await autocomplete({
|
|
70
|
+
message: 'Target languages (comma-separated):',
|
|
71
|
+
default: 'es,fr,de',
|
|
72
|
+
source: async () => []
|
|
73
|
+
});
|
|
74
|
+
targetLanguages = langsInput.split(',').map((l) => l.trim());
|
|
75
|
+
}
|
|
76
|
+
// Validate model selection
|
|
77
|
+
const availableModels = translationService.getAvailableModels();
|
|
78
|
+
if (!availableModels.includes(selectedModel)) {
|
|
79
|
+
console.log(pc.yellow('\nSelect AI model for translation:'));
|
|
80
|
+
selectedModel = await select({
|
|
81
|
+
message: 'Choose model:',
|
|
82
|
+
choices: availableModels.map(m => {
|
|
83
|
+
const info = translationService.getModelInfo(m);
|
|
84
|
+
return {
|
|
85
|
+
value: m,
|
|
86
|
+
description: info ? `Context: ${info.contextWindow}, Max output: ${info.maxTokens}` : ''
|
|
87
|
+
};
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
await translationService.loadConfig();
|
|
92
|
+
console.log(pc.green('✓'), `Translation enabled: ${lang} → ${targetLanguages.join(', ')}`);
|
|
93
|
+
console.log(pc.dim(`Using model: ${selectedModel}\n`));
|
|
94
|
+
}
|
|
47
95
|
console.log(pc.bold(`\nAdding captions for ${device} (${lang}):`));
|
|
48
96
|
console.log(pc.dim('Type to search suggestions, use arrow keys to navigate'));
|
|
49
97
|
console.log(pc.dim('Press Tab to autocomplete, Enter to confirm\n'));
|
|
@@ -100,6 +148,30 @@ export default function captionCmd() {
|
|
|
100
148
|
captions[file] = {};
|
|
101
149
|
}
|
|
102
150
|
captions[file][lang] = text;
|
|
151
|
+
// Translate if enabled
|
|
152
|
+
if (translate && text && targetLanguages.length > 0) {
|
|
153
|
+
process.stdout.write(pc.dim(' Translating...'));
|
|
154
|
+
try {
|
|
155
|
+
const translations = await translationService.translate({
|
|
156
|
+
text,
|
|
157
|
+
targetLanguages,
|
|
158
|
+
model: selectedModel
|
|
159
|
+
});
|
|
160
|
+
// Clear the "Translating..." message
|
|
161
|
+
process.stdout.write('\r\x1b[K');
|
|
162
|
+
// Store translations
|
|
163
|
+
for (const [langCode, translation] of Object.entries(translations)) {
|
|
164
|
+
captions[file][langCode] = translation;
|
|
165
|
+
console.log(pc.dim(` ${langCode}: ${translation}`));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
// Clear the "Translating..." message
|
|
170
|
+
process.stdout.write('\r\x1b[K');
|
|
171
|
+
console.error(pc.yellow(' Translation failed:'), error instanceof Error ? error.message : String(error));
|
|
172
|
+
// Continue without translations
|
|
173
|
+
}
|
|
174
|
+
}
|
|
103
175
|
}
|
|
104
176
|
// Save updated captions
|
|
105
177
|
await fs.writeFile(captionsFile, JSON.stringify(captions, null, 2), 'utf8');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caption.js","sourceRoot":"","sources":["../../src/commands/caption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,YAAY,MAAM,kCAAkC,CAAC;AAC5D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,IAAI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EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,WAAW,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;YAC3F,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC,CAAC;QAC9G,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACxF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localize.d.ts","sourceRoot":"","sources":["../../src/commands/localize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"localize.d.ts","sourceRoot":"","sources":["../../src/commands/localize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,MAAM,CAAC,OAAO,UAAU,WAAW,YAyLlC"}
|