vue-vben-admin/src/hooks/web/useI18n.ts

22 lines
447 B
TypeScript
Raw Normal View History

2020-11-25 23:20:30 +08:00
import { getI18n } from '/@/setup/i18n';
export function useI18n(namespace?: string) {
const { t, ...methods } = getI18n().global;
function getKey(key: string) {
if (!namespace) {
return key;
}
if (key.startsWith(namespace)) {
return key;
}
return `${namespace}.${key}`;
}
return {
...methods,
t: (key: string, ...arg: Parameters<typeof t>) => {
return t(getKey(key), ...arg);
},
};
}