Translate locale files at build time, with caching, as part of your normal Vite build.
npm install -D vite-plugin-shipi18nSet your own LLM key in the environment. It is read at translation time and never written to disk or sent anywhere except your provider:
# .env — never commit this
ANTHROPIC_API_KEY=your-key-hereUse OPENAI_API_KEY instead if you pass --provider openai.
shipi18n({ provider: 'anthropic', targetLanguages: ['es', 'fr'] })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
}),
],
})// Gate the PLUGIN, not the language list — an empty
// targetLanguages throws rather than skipping.
const translate = process.env.ANTHROPIC_API_KEY
? [shipi18n({ provider: 'anthropic', targetLanguages: ['es', 'fr', 'de'] })]
: []
export default defineConfig({
plugins: [...translate],
})That is the cache doing its job. Delete node_modules/.cache/vite-plugin-shipi18n to force a full re-translation.
Set ANTHROPIC_API_KEY (or OPENAI_API_KEY) in the build environment, or set targetLanguages to an empty array to skip translation in that environment.
Need help? Read the docs