| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /**
- * i18next-scanner 配置文件
- * 用于扫描代码中的翻译 key 并自动更新 locale JSON 文件
- *
- * 使用方法: pnpm run i18n
- */
- const typescriptTransform = require('i18next-scanner-typescript')
- module.exports = {
- input: [
- 'src/**/*.{js,jsx,ts,tsx,vue}',
- // 排除不需要扫描的目录
- '!src/locales/**',
- '!**/node_modules/**'
- ],
- output: './',
- options: {
- debug: false,
- removeUnusedKeys: true,
- sort: true,
- func: {
- // 扫描的函数名
- list: ['t', '$t', 'i18n.t'],
- extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue']
- },
- trans: {
- // Trans 组件 (如果使用)
- component: 'Trans',
- i18nKey: 'i18nKey',
- defaultsKey: 'defaults',
- extensions: ['.js', '.jsx', '.tsx', '.vue'],
- fallbackKey: false
- },
- // 支持的语言
- lngs: ['en', 'zh-cn'],
- ns: ['translation'],
- defaultLng: 'zh-cn',
- defaultNs: 'translation',
- // 默认值策略:中文使用 key 本身,英文留空待翻译
- defaultValue: (lng, ns, key) => {
- if (lng === 'zh-cn') {
- return key
- }
- return ''
- },
- resource: {
- loadPath: 'src/locales/{{lng}}.json',
- savePath: 'src/locales/{{lng}}.json',
- jsonIndent: 2,
- lineEnding: '\n'
- },
- nsSeparator: false, // 禁用 namespace 分隔符
- keySeparator: false, // 禁用 key 分隔符,支持扁平化 key
- interpolation: {
- prefix: '{{',
- suffix: '}}'
- }
- },
- // TypeScript 和 Vue 文件解析支持
- transform: typescriptTransform({
- extensions: ['.ts', '.tsx', '.vue'],
- tsOptions: {
- target: 'esnext'
- }
- })
- }
|