From ec8b1b0b8dd4159106bb6d87b2cd886aa2f283d0 Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 5 Dec 2024 18:07:38 +0800 Subject: [PATCH] feat: add multi-language files (#538) * feat: add multi-language files * test: fix --- build/build-locale.ts | 13 ++++++ build/sync-types.ts | 15 +++++++ demo/I18n/base.vue | 71 +++---------------------------- docs/en-US/guide/i18n.md | 63 ++++++++++------------------ docs/src/components/ProCode.vue | 3 +- docs/src/components/PwaPopup.vue | 2 +- docs/src/lang/index.ts | 72 ++------------------------------ docs/src/tsconfig.json | 1 + docs/zh-CN/guide/i18n.md | 63 ++++++++++------------------ package.json | 5 ++- src/Crud/index.test.ts | 2 +- src/Crud/useCrud.ts | 48 +++++++-------------- src/Form/useForm.ts | 30 ++++--------- src/Search/useSearch.ts | 29 ++++--------- src/Tabs/useTabs.ts | 36 ++++------------ src/composables/index.ts | 1 + src/composables/locale.ts | 28 +++++++++++++ src/locale/en.ts | 37 ++++++++++++++++ src/locale/zh-cn.ts | 37 ++++++++++++++++ vite.config.ts | 1 + 20 files changed, 230 insertions(+), 327 deletions(-) create mode 100644 build/build-locale.ts create mode 100644 build/sync-types.ts create mode 100644 src/composables/locale.ts create mode 100644 src/locale/en.ts create mode 100644 src/locale/zh-cn.ts diff --git a/build/build-locale.ts b/build/build-locale.ts new file mode 100644 index 00000000..e859b981 --- /dev/null +++ b/build/build-locale.ts @@ -0,0 +1,13 @@ +import fg from 'fast-glob' +import { defineConfig } from 'vite' +import { toAbsolute } from './utils' + +export default defineConfig({ + build: { + target: 'es2015', + outDir: toAbsolute('../lib/locale'), + lib: { + entry: fg.sync(toAbsolute('../src/locale/*.ts')), + }, + }, +}) diff --git a/build/sync-types.ts b/build/sync-types.ts new file mode 100644 index 00000000..680730f3 --- /dev/null +++ b/build/sync-types.ts @@ -0,0 +1,15 @@ +import fg from 'fast-glob' +import { copyFileRecursive, toAbsolute } from './utils' + +function transform(input: string) { + const outDir = input.replace(/\/types\//, '/lib/') + copyFileRecursive(input, outDir) +} + +(() => { + fg.sync([ + toAbsolute('../types/locale/*'), + toAbsolute('../types/styles/*'), + ]).map(transform) + console.log('sync-types done') +})() diff --git a/demo/I18n/base.vue b/demo/I18n/base.vue index 0634e6bb..c3d49603 100644 --- a/demo/I18n/base.vue +++ b/demo/I18n/base.vue @@ -6,7 +6,7 @@ > Switch lang - + import { computed, onMounted, onUnmounted, ref, watch } from 'vue' import { useClipboard } from '@vueuse/core' -import { useLocale } from 'element-plus' import { CaretTop, CaretBottom, DocumentCopy, VideoPlay, } from '@element-plus/icons-vue' -import { useShow } from 'element-pro-components' +import { useShow, useLocale } from 'element-pro-components' import { github } from '../utils/index' import { useStackBlitz } from '../composables/index' diff --git a/docs/src/components/PwaPopup.vue b/docs/src/components/PwaPopup.vue index 2ddc9b7d..ab1fe7dc 100644 --- a/docs/src/components/PwaPopup.vue +++ b/docs/src/components/PwaPopup.vue @@ -28,7 +28,7 @@