translate-kit 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 translate-kit 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,155 @@
1
+ # translate-kit
2
+
3
+ AI-powered translation SDK for build time. No intermediaries, no vendor lock-in.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/translate-kit.svg)](https://www.npmjs.com/package/translate-kit)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
+ [![CI](https://github.com/guillermolg00/translate-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/guillermolg00/translate-kit/actions/workflows/ci.yml)
8
+
9
+ Uses your own AI models via [Vercel AI SDK](https://sdk.vercel.ai/) to translate your app at build time. Compatible with [next-intl](https://next-intl.dev/).
10
+
11
+ ## Features
12
+
13
+ - **Build-time AI translation** — translate JSON message files using any AI model
14
+ - **Incremental** — only new or modified keys get translated via a lock file system
15
+ - **Any provider** — OpenAI, Anthropic, Google, Mistral, Groq, or any Vercel AI SDK provider
16
+ - **Scanner** — extract translatable strings from JSX/TSX source code automatically
17
+ - **Codegen** — replace hardcoded strings with `t()` calls and inject imports/hooks
18
+ - **next-intl ready** — generates `useTranslations`-compatible message files
19
+
20
+ ## Quick Start
21
+
22
+ ```bash
23
+ # Install
24
+ npm install translate-kit @ai-sdk/openai
25
+ # or
26
+ bun add translate-kit @ai-sdk/openai
27
+
28
+ # Create config
29
+ npx translate-kit init
30
+
31
+ # Translate
32
+ npx translate-kit translate
33
+ ```
34
+
35
+ ## Configuration
36
+
37
+ ```ts
38
+ // translate-kit.config.ts
39
+ import { defineConfig } from "translate-kit";
40
+ import { openai } from "@ai-sdk/openai";
41
+
42
+ export default defineConfig({
43
+ model: openai("gpt-4o-mini"),
44
+ sourceLocale: "en",
45
+ targetLocales: ["es", "fr", "de"],
46
+ messagesDir: "./messages",
47
+
48
+ translation: {
49
+ batchSize: 50,
50
+ concurrency: 3,
51
+ context: "SaaS application for project management",
52
+ glossary: { Acme: "Acme" },
53
+ tone: "professional",
54
+ retries: 2,
55
+ },
56
+
57
+ scan: {
58
+ include: ["src/**/*.tsx", "app/**/*.tsx"],
59
+ exclude: ["**/*.test.*"],
60
+ keyStrategy: "hash",
61
+ translatableProps: ["placeholder", "title", "alt", "aria-label"],
62
+ i18nImport: "next-intl",
63
+ },
64
+ });
65
+ ```
66
+
67
+ ## Commands
68
+
69
+ ### `translate-kit translate`
70
+
71
+ Translate messages to all target locales.
72
+
73
+ ```bash
74
+ translate-kit translate # Translate all locales
75
+ translate-kit translate --locale es # Only Spanish
76
+ translate-kit translate --dry-run # Preview without translating
77
+ translate-kit translate --force # Re-translate everything
78
+ translate-kit translate --verbose # Verbose output
79
+ ```
80
+
81
+ ### `translate-kit scan`
82
+
83
+ Scan source code for translatable strings (JSX text, attributes, object properties).
84
+
85
+ ```bash
86
+ translate-kit scan # Scan and write to source locale file
87
+ translate-kit scan --dry-run # Preview found strings
88
+ ```
89
+
90
+ ### `translate-kit codegen`
91
+
92
+ Replace hardcoded strings with `t()` calls and inject `useTranslations` imports.
93
+
94
+ ```bash
95
+ translate-kit codegen # Transform source files
96
+ translate-kit codegen --dry-run # Preview changes
97
+ ```
98
+
99
+ ### `translate-kit init`
100
+
101
+ Interactive setup wizard. Creates a config file, optionally scaffolds next-intl integration, and can run the full pipeline (scan → codegen → translate).
102
+
103
+ ## How It Works
104
+
105
+ ```
106
+ scan → codegen → translate
107
+ ```
108
+
109
+ 1. **Scan** — parse JSX/TSX files with Babel, extract translatable strings, generate semantic keys via AI, write source locale JSON
110
+ 2. **Codegen** — replace hardcoded strings with `t("key")` calls, add `useTranslations` imports and hooks
111
+ 3. **Translate** — diff source messages against lock file, translate only new/modified keys, write target locale JSONs
112
+
113
+ Only changed keys are sent to the AI. A `.translate-lock.json` file tracks source hashes so re-runs are fast and cheap.
114
+
115
+ ## AI Providers
116
+
117
+ translate-kit works with any provider supported by Vercel AI SDK:
118
+
119
+ ```ts
120
+ import { openai } from "@ai-sdk/openai";
121
+ import { anthropic } from "@ai-sdk/anthropic";
122
+ import { google } from "@ai-sdk/google";
123
+ import { mistral } from "@ai-sdk/mistral";
124
+
125
+ // OpenAI
126
+ model: openai("gpt-4o-mini")
127
+
128
+ // Anthropic
129
+ model: anthropic("claude-sonnet-4-20250514")
130
+
131
+ // Google
132
+ model: google("gemini-2.0-flash")
133
+
134
+ // Mistral
135
+ model: mistral("mistral-large-latest")
136
+ ```
137
+
138
+ ## Scanner
139
+
140
+ The scanner extracts translatable strings from your source code:
141
+
142
+ - **JSX text** — `<h1>Welcome</h1>`
143
+ - **JSX attributes** — `<input placeholder="Enter name" />`
144
+ - **Expression containers** — `<div>{"Hello"}</div>`
145
+ - **Object properties** — `{ title: "Dashboard" }`
146
+
147
+ It automatically filters out non-translatable content like URLs, CSS classes, constants, and code identifiers. Keys are generated using AI for semantic, namespace-style naming (`common.save`, `nav.dashboard`, `form.enterName`).
148
+
149
+ ## Docs
150
+
151
+ Full documentation available at [translate-kit.vercel.app](https://translate-kit.vercel.app).
152
+
153
+ ## License
154
+
155
+ MIT