diff --git a/docs/site/use-translate.ts b/docs/site/use-translate.ts new file mode 100644 index 000000000..56c4dfbf3 --- /dev/null +++ b/docs/site/use-translate.ts @@ -0,0 +1,22 @@ +import Locale from '../../src/locale'; +import { camelize } from '../../src/utils/format/string'; +import { createTranslate } from '../../src/utils/create/translate'; + +let demoUid = 0; + +export function useTranslate(i18n: Record) { + const demoName = `demo-i18n-${demoUid++}`; + + if (i18n) { + const locales = {}; + const camelizedName = camelize(demoName); + + Object.keys(i18n).forEach((key) => { + locales[key] = { [camelizedName]: i18n[key] }; + }); + + Locale.add(locales); + } + + return createTranslate(demoName); +} diff --git a/jest.config.js b/jest.config.js index 741650f95..5048071b3 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,4 +6,7 @@ module.exports = { '!**/test/**', '!**/lang/**', ], + moduleNameMapper: { + '^@demo(.*)$': '/docs/site$1', + }, }; diff --git a/src/action-sheet/demo/index.vue b/src/action-sheet/demo/index.vue index 6caf16a52..5792591c0 100644 --- a/src/action-sheet/demo/index.vue +++ b/src/action-sheet/demo/index.vue @@ -53,43 +53,43 @@