How to use react-intl-universal - 10 common examples

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 alibaba / react-intl-universal / examples / browser-example / src / App.js View on Github external
loadLocales() {
    let currentLocale = intl.determineLocale({
      urlLocaleKey: "lang",
      cookieLocaleKey: "lang"
    });
    if (!_.find(SUPPOER_LOCALES, { value: currentLocale })) {
      currentLocale = "en-US";
    }

    http
      .get(`locales/${currentLocale}.json`)
      .then(res => {
        console.log("App locale data", res.data);
        // init method will load CLDR locale data according to currentLocale
        return intl.init({
          currentLocale,
          locales: {
            [currentLocale]: res.data
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 YDJ-FE / ts-react-webpack / src / containers / shared / App / IntlWrapper.tsx View on Github external
function loadLocales() {
        let targetLocale = intl.determineLocale({ cookieLocaleKey: COOKIE_KEYS.LANG }) as LOCALES_KEYS
        // default is English
        if (!find(SUPPOER_LOCALES, { value: targetLocale })) {
            targetLocale = LOCALES_KEYS.EN_US
        }
        getLocaleLoader(targetLocale).then(res => {
            intl.init({ currentLocale: targetLocale, locales: { [targetLocale]: res.localeData } }).then(() => {
                setCurrentLocale(targetLocale)
                setAntdLocaleData(res.antdLocaleData)
            })
        })
    }
github pythonkr / pyconkr-web / utils / formatDate.ts View on Github external
export const formatDate = (formatTemplate: string) => (date: DateDTO) => {
  if (!date) {
    return '-'
  }
  const localeKey = intl.getInitOptions().currentLocale!

  return formatToTimeZone(date, formatTemplate, {
    // No type interface..(https://github.com/prantlf/date-fns-timezone/issues/10)
    locale: locales[localeKey],
    timeZone: 'Asia/Seoul'
  })
}
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 LoopringSecondary / circulr / src / components / tickers / ListTokenTickers.js View on Github external
function ListTokenTickers(props) {
  const {tickersOfSource:list,dispatch,token,tickers} = props;
  const tickersFm = new TickersFm(list);
  const listedTickers = tickersFm.getTickersBySymbol(token);
  const gotoTrade = (item)=>{
    routeActions.gotoPath(`/trade/${item.market}`)
  }
  console.log('ListTokenTickers',tickers);
  console.log('listedTickers',listedTickers);
  return (
    <div>
        <div>
            <div>
                <h4>{intl.get('ticker_list.title_loopring_tickers')}</h4>
            </div>
            
              <div style="{{minHeight:'65px'}}">
                  {
                    listedTickers.map((item,index)=&gt;{
                      const tickerFm = new TickerFm(item)
                      return (
                        <div>
                            <ul>
                                <li><h3>{item.market}</h3></li>
                                <li><small>{intl.get('ticker.price')}</small><span>{tickerFm.getLast()}</span></li>
                                <li><small>{intl.get('ticker.change')}</small><span>{tickerFm.getChange()}</span></li>
                            </ul>
                            <button>{intl.get('common.trade')} {token}</button>
                        </div>
                      )</div></div></div>
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)
            })
        })
    }

react-intl-universal

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

BSD-3-Clause
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis