vite-i18n-plugin
v1.0.4
Published
vite-i18n-plugin
Readme
vite-i18n-plugin
Installing
Using npm:
npm i -D vite-i18n-pluginUsing yarn:
yarn add -D vite-i18n-pluginOptions
- languageList
Language list, default:
['cn', 'en'] - langType
Current lang, default:
cn - useLanguage
Specify the language type that automatically uses the key as the default translation, default:
cn - autoWriteAble
Automatically save translation files, default:
true - formatSpace
Number of spaces in the translation file json format, default:
2 - sourcePath
Translation file path
- removeUnUseKeys
Delete non-existent translation, default:
false - patten
Match language tag, default
['__']->__('')
Getting Started
- Dev config
// vite.config.js
const { serverI18nPlugin } = require('vite-i18n-plugin');
export default {
configureServer: [
serverI18nPlugin({
langType: 'cn',
useLanguage: 'cn',
languageList: ['cn', 'en'],
sourcePath: 'src/lang/lang.json'
})
],
...
}- Build config
// build.js
const { build } = require('vite');
const { buildI18nPlugin } = require('vite-i18n-plugin');
build({
rollupInputOptions: {
pluginsPreBuild: [
buildI18nPlugin({
langType: 'cn',
useLanguage: 'cn',
removeUnUseKeys: true,
languageList: ['cn', 'en'],
sourcePath: 'src/lang/lang.json'
})
]
},
...
})- Using
// index.js
console.log('__("你好")');
// or app.vue
<template>
<input placeholder="__('你好')" />
</template>- Result (src/lang/lang.json)
{
"你好": {
"cn": "你好",
"en": ""
}
}