feat: i18n next
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { get, isFunction } from '../../../src/utils';
|
||||
import { camelize } from '../../../src/utils/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>;
|
||||
Reference in New Issue
Block a user