Skip to main content
shipi18n logo|Documentation

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

OptionDefaultDescription
targetLanguagesRequired. Language codes to generate.
provideranthropicanthropic, openai, or a custom adapter.
apiKeyenv varYour provider key. Read from the environment when omitted.
modelprovider defaultOverride the model.
sourceDirpublic/locales/enDirectory holding the source locale files.
outputDirpublic/localesWhere translated files are written.
sourceLanguageenSource language code.
cachetrueSkip strings that have not changed since the last build.
fallback.fallbackToSourcetrueWrite the source text when a translation fails, so the build still succeeds.
fallback.regionalFallbacktrueResolve 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.