i18n-json-gen
v1.0.0
Published
自动从allLang.json生成多语言文件并实时监测更新的npm包
Readme
i18n-json-gen
自动从 allLang.json 生成多语言文件并实时监测更新的npm包。
安装
npm install i18n-json-gen使用方法
作为独立脚本使用
- 在项目根目录创建
allLang.json文件。 - 运行以下命令启动服务:
npm start作为 Webpack 插件使用
// vue.config.js 或 webpack.config.js
const { defineConfig } = require('@vue/cli-service');
const createI18nPlugin = require('i18n-json-gen');
module.exports = defineConfig({
configureWebpack: {
plugins: [
createI18nPlugin({
watchFile: 'src/locales/allLang.json',
outputDir: 'src/locales',
targetLanguages: ['zh-CN', 'en-US']
}).webpack
]
}
});作为 Vite 插件使用
// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import createI18nPlugin from 'i18n-json-gen';
export default defineConfig({
plugins: [
vue(),
createI18nPlugin({
watchFile: 'src/locales/allLang.json',
outputDir: 'src/locales',
targetLanguages: ['zh-CN', 'en-US']
}).vite
]
});文件结构
allLang.json: 包含所有语言配置项的文件。*.json: 自动生成的各语言文件,如zh-CN.json。
注意事项
allLang.json文件的修改会自动触发语言文件的更新。- 支持处理超过2000行的
allLang.json文件,采用局部更新减少内存消耗。
贡献
欢迎提交issue和PR!详情请见CONTRIBUTING.md。
License
本项目采用MIT协议,详见LICENSE。
变更日志
请查阅CHANGELOG.md。
