Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async componentDidMount() {
const { lang, saveUserData } = this.props
console.info(`用户语言为: ${lang}`)
// i18n 的黑魔法,不 await 阻塞会引起部分i18n文字为空白
await intl.init({
currentLocale: lang,
locales,
})
this.setState({ i18nLoaded: true })
getMyInfo().then(res => {
saveUserData(res)
})
}
render() {
public loadLocales() {
const lang = this.getLangs()
intl.init({
currentLocale: lang, // TODO: determine locale here
locales,
commonLocaleDataUrls: {
en: '/en.js', // the file
zh: '/zh.js' // the file
}
})
.then(() => {
// After loading CLDR locale data, start to render
this.setState({initDone: true});
});
}
import './theme/reset.less';
import 'bootstrap/dist/css/bootstrap.min.css';
import './theme/style.less';
import 'bootstrap/dist/js/bootstrap.bundle.min';
const locales = {};
epConfig.supportedLocales.forEach((locale) => {
// eslint-disable-next-line import/no-dynamic-require, global-require
const localeMessages = require(`./localization/${locale.value}.json`);
// eslint-disable-next-line import/no-dynamic-require, global-require
const debugMessages = require(`./localization/messages-${locale.value}.json`);
locales[locale.value] = { ...localeMessages, ...debugMessages };
});
// localisation init
intl.init({
currentLocale: UserPrefs.getSelectedLocaleValue(),
locales,
})
.then(() => {
// EP Configs init
init({
config: epConfig,
intl,
})
.then((componentsData) => {
ReactDOM.render(
,
document.getElementById('root'),
);
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js', { scope: '/' })
export function setLocale(value) {
console.log('locales:',value);
switch (value) {
case "zh-CN" :
moment.locale('zh-cn');
break;
case "en-US":
moment.locale('en');
break;
default:
moment.locale('en');
}
intl.init({
currentLocale: value || 'en-US',
locales,
});
console.log('locales:',intl);
window.locale = value || 'en-US'
}
loadLocales(locale = this.state.locale) {
intl.init({
currentLocale: locale,
locales,
})
.then(() => {
this.setState({ locale, initDone: true });
this.loadMenu();
});
}
getLocaleLoader(targetLocale).then(res => {
intl.init({ currentLocale: targetLocale, locales: { [targetLocale]: res.localeData } }).then(() => {
setCurrentLocale(targetLocale)
setAntdLocaleData(res.antdLocaleData)
})
})
}
super(props)
this.stores = {
scheduleStore: ScheduleStore,
authStore: AuthStore,
profileStore: ProfileStore,
sponsorStore: SponsorStore,
cfpStore: CFPStore,
proposalReviewStore: ProposalReviewStore,
ticketStore: TicketStore,
programStore: ProgramStore,
}
const { router: { query } } = this.props
const currentLocale = query![URL_LOCALE_KEY] as string || LOCALE_KEY_KR
intl.init({
currentLocale,
locales,
warningHandler: intlWarningHandler
})
i18n.changeLanguage(_.isEqual(LOCALE_KEY_KR, currentLocale) ? 'ko' : 'en')
i18n.init({ fallbackLng: 'ko' })
}
.then(data => {
return intl.init({
currentLocale,
locales: {
[currentLocale]: data
}
});
})
.then(() => {
import store from './store';
import CoreLayout from './layout';
import { Provider } from 'mobx-react';
import { LocaleProvider } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import enUS from 'antd/lib/locale-provider/en_US';
import _zhCN from './locale/zh-CN.yaml';
import _enUS from './locale/en-US.yaml';
import registerServiceWorker from './registerServiceWorker';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import intl from 'react-intl-universal';
const lang = localStorage.getItem('lang') || 'en-US';
intl.init({
currentLocale: lang,
locales: {
[lang]: lang === 'zh-CN' ? _zhCN : _enUS,
},
});
ReactDOM.render(
,
const initLang = (currentLocale) => intl.init({ currentLocale, locales })