How to use the react-intl-universal.init function in react-intl-universal

To help you get started, we’ve selected a few react-intl-universal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dasdaq / Dasdaq-web / src / App.js View on Github external
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() {
github Itroads / react-admin-ts-starter / src / App.tsx View on Github external
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});
    });
  }
github elasticpath / react-pwa-reference-storefront / app / src / index.tsx View on Github external
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: '/' })
github LoopringSecondary / circulr / src / common / utils / localeSetting.js View on Github external
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'
}
github fontmoa / fontmoa / src / component / app / index.js View on Github external
loadLocales(locale = this.state.locale) {
    intl.init({
      currentLocale: locale, 
      locales,
    })
    .then(() => {
      this.setState({ locale,  initDone: true });
      this.loadMenu();
    });
  }
github YDJ-FE / ts-react-webpack / src / containers / shared / App / IntlWrapper.tsx View on Github external
getLocaleLoader(targetLocale).then(res => {
            intl.init({ currentLocale: targetLocale, locales: { [targetLocale]: res.localeData } }).then(() => {
                setCurrentLocale(targetLocale)
                setAntdLocaleData(res.antdLocaleData)
            })
        })
    }
github pythonkr / pyconkr-web / pages / _app.tsx View on Github external
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' })
  }
github krwu / ServerStatus-web / src / App.tsx View on Github external
.then(data => {
      return intl.init({
        currentLocale,
        locales: {
          [currentLocale]: data
        }
      });
    })
    .then(() => {
github caicloud / cyclone / web / src / index.js View on Github external
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(
  
    
      
        
      
    
  ,
github Dasdaq / Dasdaq-web / src / reducers / lang.js View on Github external
const initLang = (currentLocale) => intl.init({ currentLocale, locales })

react-intl-universal

Internationalize React apps. Not only for React component but also for Vanilla JS.

BSD-3-Clause
Latest version published 3 months ago

Package Health Score

75 / 100
Full package analysis