mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
17 lines
499 B
TypeScript
17 lines
499 B
TypeScript
import { get, isFunction } from '..';
|
|
import { camelize } from '../format/string';
|
|
import locale from '../../locale';
|
|
|
|
export function createI18N(name: string) {
|
|
const prefix = camelize(name) + '.';
|
|
|
|
return function (path: string, ...args: any[]): string {
|
|
const messages = locale.messages();
|
|
const message = get(messages, prefix + path) || get(messages, path);
|
|
|
|
return isFunction(message) ? message(...args) : message;
|
|
};
|
|
}
|
|
|
|
export type Translate = ReturnType<typeof createI18N>;
|