react-intl

React-intl for non components

痞子三分冷 提交于 2019-12-04 19:37:36
问题 Currently I have the following code to expose react-intl to non-components, but it throws an error for intl as undefined. I have created a separate component as 'CurrentLocale' and inject-intl to it. The exporting function t will use intl formatMessage from CurrentLocale context. import React from 'react'; import {injectIntl} from 'react-intl'; import PropTypes from 'prop-types'; import { flow } from 'lodash'; class CurrentLocale extends React.Component { constructor(props,context){ super();

Injecting react-intl object into mounted Enzyme components for testing

China☆狼群 提交于 2019-12-04 10:02:59
问题 EDIT: Solved! Scroll down for the answer In our Component tests we need them to have access to the react-intl context. The problem is that we are mounting single components (with Enzyme's mount()) without their <IntlProvider /> parent wrapper. This is solved by wrapping the provider around but then the root points to the IntlProvider instance and not to CustomComponent . The Testing with React-Intl: Enzyme docs are still empty. <CustomComponent /> class CustomComponent extends Component {

react-intl - accessing nested messages

对着背影说爱祢 提交于 2019-12-04 03:56:02
I'm trying to use react-intl package inside an app. The app is rendered on the server so I wrote some code to determine which language to use and serve into IntlProvider . Translations were provided in messages.js file and they look like this: export default { en: { message: '...some message', nested: { anotherMessage: '...another message', } } de: { // ... } } What I do is something like this: // import messages from './messages.js' // Check the locale for the user (based on cookies or other things) const locale = ... // Get the required messages const messagesForLocale= = messages[locale]; /

react-intl 实现 React 国际化多语言

你。 提交于 2019-12-03 15:37:38
效果预览 React Intl 国际化步骤 创建国际化资源文件 根据语言获取国际化资源 引入 react-intl 的 local data 创建 LocaleProvider 国际化上下文组件 创建 react-intl 国际化上下文组件 使用 react-intl's components & apis,进行国际化开发 1. 创建国际化资源文件 目前我们管理资源文件的方式是在 src/locales 文件夹下: . ├── en-US.js ├── en-US.messages.js ├── zh-Hans.js └── zh-Hans.messages.js *.messages.js 是我们的资源文件(这里我们采用了 js 格式,你也可以使用 json 等等),返回的是一个对象,key 为我们翻译用的 id,value 为具体语言的翻译,内容是: export default { 'page.localeProvider.react': '{ name }, a JavaScript library for building user interfaces.', 'page.localeProvider.react.html': '<p>{ name } makes it painless to create interactive UIs. Design simple

react-intl vs react-i18next for ReactJS internationalization (i18n) [closed]

心已入冬 提交于 2019-12-03 09:28:14
I need to build a multilanguage application using ReactJS. The application needs a custom dictionary for different languages as well as automatic formatting of date/time, numbers and currency. From all I´ve seen there are 2 very popular libraries: reac-intl and react-i18next What would be the advantages between one and another ? What is the most supported and popular one ? What is the general choice for a ReactJS application supporting multiple languages ? jamuhl @whyp's response is not taking into account react-i18next is part of i18next which has additional 2100 stars (without having a huge

React-Intl How to use FormattedMessage in input placeholder

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm unsure how to get the values from <FormattedMessage {...messages.placeholderIntlText} /> into a placeholder format like input: <input placeholder={<FormattedMessage {...messages.placeholderIntlText} />} /> as it would return [Object object] in the actual placeholder. Is there a way to get the actual correct value? 回答1: The <Formatted... /> React components in react-intl are meant to be used in rendering scenarios and are not meant to be used in placeholders, alternate text, etc. They render HTML, not plain text, which is not useful in

react-intl vs react-i18next for ReactJS internationalization (i18n) [closed]

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to build a multilanguage application using ReactJS. The application needs a custom dictionary for different languages as well as automatic formatting of date/time, numbers and currency. reac-intl and react-i18next What would be the advantages between one and another ? What is the most supported and popular one ? What is the general choice for a ReactJS application supporting multiple languages ? 回答1: @whyp's response is not taking into account react-i18next is part of i18next which has additional 2100 stars (without having a huge

My redux-form is reinitialized when switching language by changing react-intl wrapper props

主宰稳场 提交于 2019-12-01 09:52:31
I'm wrapping my app inside an IntlProvider from react-intl v2 , like this: <IntlProvider locale={this.props.lang} messages={this.props.messages}> And I have my react-form forms down the tree. Everything is great. But if I'm starting to fill up a form, and I decide to change the language of the UI (by listening to an action that will update my lang and messages props through my redux store), the form is being reset :-/ I see the action redux-form/INITIALIZE being fired when the lang changes. And it happens even if I pass destroyOnUnmount: false to reduxForm() . It did not happen with

My redux-form is reinitialized when switching language by changing react-intl wrapper props

こ雲淡風輕ζ 提交于 2019-12-01 07:12:02
问题 I'm wrapping my app inside an IntlProvider from react-intl v2, like this: <IntlProvider locale={this.props.lang} messages={this.props.messages}> And I have my react-form forms down the tree. Everything is great. But if I'm starting to fill up a form, and I decide to change the language of the UI (by listening to an action that will update my lang and messages props through my redux store), the form is being reset :-/ I see the action redux-form/INITIALIZE being fired when the lang changes.

React-Intl How to use FormattedMessage in input placeholder

♀尐吖头ヾ 提交于 2019-11-28 18:33:47
I'm unsure how to get the values from <FormattedMessage {...messages.placeholderIntlText} /> into a placeholder format like input: <input placeholder={<FormattedMessage {...messages.placeholderIntlText} />} /> as it would return [Object object] in the actual placeholder. Is there a way to get the actual correct value? lsoliveira The <Formatted... /> React components in react-intl are meant to be used in rendering scenarios and are not meant to be used in placeholders, alternate text, etc. They render HTML, not plain text, which is not useful in your scenario. Instead, react-intl provides a