feat: 动态删除已注册的语料数据的方法 (#5986)

Co-authored-by: 王玉振 <wangyuzhen01@wangyuzhen01.local>
This commit is contained in:
Simon 2022-12-27 19:00:36 +08:00 committed by GitHub
parent 6845f54628
commit 2b1b7175ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -36,6 +36,7 @@ import {
makeTranslator,
register as registerLocale,
extendLocale,
removeLocaleData,
localeable
} from './locale';
import type {LocaleProps, TranslateFn} from './locale';
@ -140,6 +141,7 @@ export {
registerLocale,
makeTranslator,
extendLocale,
removeLocaleData,
localeable,
LocaleProps,
TranslateFn,

View File

@ -27,6 +27,19 @@ export function extendLocale(name: string, config: LocaleConfig) {
};
}
/** 删除语料数据 */
export function removeLocaleData(name: string, key: Array<string> | string) {
if (Array.isArray(key)) {
key.forEach(item => {
removeLocaleData(name, item);
});
return;
}
if (locales?.[name]?.[key]) {
delete locales[name][key];
}
}
const fns: {
[propName: string]: TranslateFn;
} = {};