intl.tsx 488 字节
Newer Older
R
Rongfeng Fu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import { createIntl } from 'react-intl';
import en_US from '@/i18n/strings/en-US.json';
import zh_CN from '@/i18n/strings/zh-CN.json';

const messages = {
  'en-US': en_US,
  'zh-CN': zh_CN,
};

export const getLocale = () => {
  const lang =
    typeof localStorage !== 'undefined'
      ? window.localStorage.getItem('umi_locale')
      : '';
  return lang || 'zh-CN';
};

export const locale = getLocale();

export const intl = createIntl({
  locale,
  messages: messages[locale],
});