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>;
|
||||
@@ -1,11 +1,11 @@
|
||||
import { createBEM, BEM } from './bem';
|
||||
import { createComponent } from './component';
|
||||
// import { createI18N, Translate } from './i18n';
|
||||
import { createI18N, Translate } from './i18n';
|
||||
|
||||
type CreateNamespaceReturn = [
|
||||
ReturnType<typeof createComponent>,
|
||||
BEM,
|
||||
// Translate
|
||||
Translate
|
||||
];
|
||||
|
||||
export function createNamespace(name: string): CreateNamespaceReturn {
|
||||
@@ -13,6 +13,6 @@ export function createNamespace(name: string): CreateNamespaceReturn {
|
||||
return [
|
||||
createComponent(name),
|
||||
createBEM(name),
|
||||
// createI18N(name)
|
||||
createI18N(name)
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user