mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
23 lines
565 B
TypeScript
23 lines
565 B
TypeScript
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<string, any>) {
|
|
const demoName = `demo-i18n-${demoUid++}`;
|
|
|
|
if (i18n) {
|
|
const locales: Record<string, any> = {};
|
|
const camelizedName = camelize(demoName);
|
|
|
|
Object.keys(i18n).forEach((key) => {
|
|
locales[key] = { [camelizedName]: i18n[key] };
|
|
});
|
|
|
|
Locale.add(locales);
|
|
}
|
|
|
|
return createTranslate(demoName);
|
|
}
|