Registry / devops / vite-gc-i18n-plugin

vite-gc-i18n-plugin

JSON →
library1.1.9jsnpmunverified

Vite automatic translation plugin for internationalizing frontend applications (Vue2/3, React, etc.) without modifying source code. Current stable version: 1.1.9. Integrates Google Translate (default), Youdao Translate, and Baidu Translate, with support for custom translators. Compatible with Vite, Webpack, and Rollup. Provides intelligent text detection and automated locale file generation. Note: Youdao API keys in demo are exhausted; users must obtain their own.

npm install vite-gc-i18n-plugin
INSTALL
IMPORT
SIG · VITE-GC-I18N-PLUGI
V
vite-gc-i18n-plugin
devopsjavascriptv1.1.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vitePluginsAutoI18n
import vitePluginsAutoI18n from 'vite-gc-i18n-plugin'
const vitePluginsAutoI18n = require('vite-gc-i18n-plugin')
ESM default import; CJS require works but is not recommended for Vite projects.
YoudaoTranslator
import { YoudaoTranslator } from 'vite-gc-i18n-plugin'
Named export for Youdao translator class. Also exports GoogleTranslator and custom translator base class.
GoogleTranslator
import { GoogleTranslator } from 'vite-gc-i18n-plugin'
Default translator if none specified. Requires proxy configuration for Google access.

Configure Vite with the auto-translation plugin using Youdao translator. Disable Vue template hoisting to ensure all strings are detected.

// vite.config.ts import vitePluginsAutoI18n, { YoudaoTranslator } from 'vite-gc-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 ?? '' }) }) ] })
Debug
Known issues
gotchaYoudao API demo keys in the README are already exhausted. You must obtain your own from Youdao.
fix
Register at Youdao AI Open Platform and replace appId/appKey with your own.
affects: <=1.1.9
gotchaGoogle Translate may fail in regions without direct access. Default proxy configuration points to localhost:7890.
fix
Set a valid HTTP/SOCKS proxy via translator options or switch to Youdao/Baidu translator.
affects: <=1.1.9
deprecatedSupport for Vue template hoisting (hoistStatic) and caching (cacheHandlers) is deprecated; disable them to ensure all text is scanned.
fix
Set `hoistStatic: false` and `cacheHandlers: false` in Vue plugin options.
affects: <=1.1.9
gotchaLanguage switching requires assigning to `window.langMap` or using `window.$changeLang()`, which may conflict with other i18n solutions.
fix
Use `window.$changeLang(lang)` to switch language without full page reload.
affects: <=1.1.9
breakingThe plugin generates locale files and a global language map; ensure `lang/index.js` is present or configure output path.
fix
Place the locale directory (`lang/`) inside your project source. Check generated files after build.
affects: <=1.1.9
Errors
Common errors & fixes
Error: No translator configured. Please provide a translator instance.
Missing `translator` option in plugin configuration.
fix
Add `translator: new GoogleTranslator() // or YoudaoTranslator(...)` to plugin settings.
Error: Youdao API appId or appKey is empty.
Youdao translator created without valid API credentials.
fix
Ensure `appId` and `appKey` are provided, e.g., from environment variables.
Error: Cannot find module 'lang/index.js'
Generated locale file not found at expected path.
fix
Run the build to generate locale files. Ensure the `lang` directory exists in project root.
Upgrade
Version history
1.1.9latest on npm
Audit
Dependencies
viteoptionalPlugin designed for Vite build tool
Agent activity
2 hits · last 30 days
node
2
Resources
vite-gc-i18n-plugin — npm install vite-gc-i18n-plugin · libregistry