feat: i18n next

This commit is contained in:
chenjiahan
2020-07-05 08:26:58 +08:00
parent 3bc6495b04
commit 0a4c6676ba
16 changed files with 885 additions and 119 deletions
+16
View File
@@ -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>;
+3 -3
View File
@@ -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)
];
}