Vite Plugin
vite-plugin-shipi18n translates your locale files during the build, with caching, so no key and no model call ever reaches the browser.
Install
npm install -D vite-plugin-shipi18n @anthropic-ai/sdk
Configure
import { defineConfig } from 'vite'
import shipi18n from 'vite-plugin-shipi18n'
export default defineConfig({
plugins: [
shipi18n({
provider: 'anthropic', // or 'openai'
targetLanguages: ['es', 'fr', 'de'],
sourceDir: 'public/locales/en',
outputDir: 'public/locales',
// apiKey defaults to ANTHROPIC_API_KEY / OPENAI_API_KEY
}),
],
})Options
| Option | Default | Description |
|---|---|---|
targetLanguages | — | Required. Language codes to generate. |
provider | anthropic | anthropic, openai, or a custom adapter. |
apiKey | env var | Your provider key. Read from the environment when omitted. |
model | provider default | Override the model. |
sourceDir | public/locales/en | Directory holding the source locale files. |
outputDir | public/locales | Where translated files are written. |
sourceLanguage | en | Source language code. |
cache | true | Skip strings that have not changed since the last build. |
fallback.fallbackToSource | true | Write the source text when a translation fails, so the build still succeeds. |
fallback.regionalFallback | true | Resolve pt-BR from pt when a regional file is missing. |
Caching
Results are cached under node_modules/.cache/vite-plugin-shipi18n. A rebuild with unchanged strings makes no model calls at all. Delete that directory to force a full re-translation.
Skipping translation when there is no key
CI runners and contributors' machines usually have no key, and local builds should not spend tokens on every save. Gate the plugin, not the language list — an empty targetLanguages throws:
const translate = process.env.ANTHROPIC_API_KEY
? [shipi18n({ provider: 'anthropic', targetLanguages: ['es', 'fr', 'de'] })]
: []
export default defineConfig({
plugins: [...translate],
})Commit the generated locale files and a keyless build simply reuses them.
Security
The plugin runs in Vite's buildStart hook — on your machine or your CI runner, never in the browser. Your key is used at build time and is not part of the output bundle.