0

i need to import the data of my selected language in index.js to app.js

My index.js

import { IntlProvider, addLocaleData } from 'react-intl'
import en from 'react-intl/locale-data/en'
import fr from 'react-intl/locale-data/fr'
import english from '../popup/localMessages/en'
import french from '../popup/localMessages/fr'
addLocaleData(...en, ...fr)

const locale =
  (navigator.languages && navigator.languages[0]) ||
  navigator.language ||
  navigator.userLanguage ||
  'en-US'

const typeOfLang = {
  en: english,
  fr: french,
}
render(
    <Provider store={store}>
      <IntlProvider locale={locale} messages={typeOfLang[locale]}>
        <Content />
      </IntlProvider>
    </Provider>,
    mountNode
  )

and my app.js

  class App extends Component {
    render() {
    const { intl } = this.props
    const { locale, messages } = this.props.intl
return(
<Button
              label={intl.formatMessage({ id: 'messages' })}
              onClick={() => this.submit('ALL')}
            />
)
}

And my en.js

 import { defineMessages } from 'react-intl'

const english = defineMessages({
  title: {
    id: 'rock',
    defaultMessage: 'read',
  },
  all: {
    id: 'same',
    defaultMessage: 'ALL',
  }


});

export default english

iam not getting the data from the langauges files in App.js button. can you please help me on this/ correct my code if possible

4

1 回答 1

0

You should pass your locale data as an array in your index.js:

addLocaleData([...en, ...fr])
于 2018-04-26T18:49:45.010 回答