i18n.ts 377 B

12345678910
  1. import { get, camelize } from '..';
  2. import locale from '../../locale';
  3. export const useI18N = (name: string) => {
  4. const prefix = camelize(name) + '.';
  5. return (path: string, ...args: any[]): string => {
  6. const message = get(locale.messages(), prefix + path) || get(locale.messages(), path);
  7. return typeof message === 'function' ? message(...args) : message;
  8. };
  9. };