vite-auto-i18n-plugin

raw JSON →
1.1.16 verified Mon Apr 27 auth: no javascript

A Vite/Rollup plugin for automatic i18n translation, version 1.1.16, with active releases. Supports Vue2/3, React, and other JS frameworks, integrating multiple translation services (Google, Youdao, custom) without modifying source code. Compatible with Vite, Webpack, Rsbuild, and Rollup. Detects translatable text and generates language packs automatically. Requires Node >=14.18.0 and ships TypeScript types.

error Error: Dynamic require of 'vite-auto-i18n-plugin' is not supported
cause Using require() in an ESM context
fix
Replace require with import; ensure project is configured for ESM.
error TypeError: $changeLang is not a function
cause $changeLang not available before plugin initialization or outside browser
fix
Ensure plugin is properly loaded and $changeLang is used after DOM ready.
error Translation not applied after build
cause Vue template hoisting or caching enabled
fix
Set hoistStatic: false and cacheHandlers: false in vue plugin options.
deprecated Requires disabling Vue 3 template hoisting and caching for correct translation injection
fix Set hoistStatic: false and cacheHandlers: false in vue template compilerOptions.
gotcha YoudaoTranslator demo keys are rate-limited and often exhausted; must provide own keys.
fix Obtain valid appId and appKey from Youdao translation service.
gotcha Language switching via $changeLang requires component re-render (e.g., v-if toggle)
fix Use v-if re-mount pattern as shown in docs, or trigger re-render manually.
breaking ESM-only; does not support require()
fix Use import syntax or configure bundler for ESM.
npm install vite-auto-i18n-plugin
yarn add vite-auto-i18n-plugin
pnpm add vite-auto-i18n-plugin

Basic Vite configuration integrating the auto-i18n plugin with Vue and Youdao translation service.

import vitePluginsAutoI18n, { YoudaoTranslator } from 'vite-auto-i18n-plugin';
import vue from '@vitejs/plugin-vue';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          hoistStatic: false,
          cacheHandlers: false
        }
      }
    }),
    vitePluginsAutoI18n({
      translator: new YoudaoTranslator({
        appId: process.env.YOUDAO_APP_ID ?? '',
        appKey: process.env.YOUDAO_APP_KEY ?? ''
      })
    })
  ]
});