Reaction-intl versus reaction-i18next for internationalizing ReactJS (i18n)

I need to create a multilingual application using ReactJS. The application needs a custom dictionary for different languages, as well as automatic formatting of date / time, numbers and currency.

Out of everything I've seen, there are 2 very popular libraries:

reac-intl and react-i18next

What would be the benefits between both? What is the most supported and popular?

What is the general choice of a ReactJS application that supports multiple languages?

+7
javascript reactjs internationalization react-intl
source share
4 answers

@Whyp's answer doesn’t take into account the reaction - i18next is part of i18next, which has an additional 2100 stars (without having a huge company in the back).

intl reaction can be quite confusing (personal opinion). i18next provides additional functions for easier integration (resource loading, user language detection)

i18next does not respond only - find out as soon as you use everywhere ( https://www.i18next.com/supported-frameworks.html )

i18next has an additional service level: http://locize.com/ localization process solution next to internationalization (i18n)

+12
source share

A common choice is the intl reaction, which is more popular than the i18next reaction. He currently has 4.5k vs. reaction-i18next 300 stars on github. This is a localization solution in React.

Here is a tutorial to get started: https://medium.freecodecamp.com/internationalization-in-react-7264738274a0

+5
source share

js-lingui

I would like to introduce the alternative i18n libraries that I am developing.

  • works with both Vanilla JS ( lingui-i18n ) and React ( lingui-react )
  • lingui-react is the only library that fully supports built-in components and formatting (see below).
  • build on top of MessageFormat ICU
  • also includes CLI ( lingui-cli ) for creating message directories
  • it uses stream types and many compile-time checks to detect obvious errors in MessageFormat

Syntax

ICU MessageFormat is very flexible as it supports variables, plurals, ordinals, selection, number / date formatting, and is also extensible. However, complex messages are a little difficult to record.

lingui-i18n provides convenient syntax using ES6 template templates, and lingui-react provides similar syntax using React Components

Vanilla js

 import { i18n } from 'lingui-i18n' i18n.t`Hello World` i18n.t`Hello, my name is ${name}` i18n.plural({ value: count, one: "# book", other: "# books" }) 

Additional examples in lingui-i18n docs

To react

 import React from 'react' import { Trans, Plural } from 'lingui-react' class App extends React.Component { render() { const name = "Fred" const count = 42 return ( <div> // Static text <Trans>January</Trans> // Variables <Trans>Hello, my name is {name}</Trans> // Components <Trans>See the <a href="/more">description</a> below.</Trans> // Plurals <Plural value={count} zero={<strong>No books</strong>} one="# book" other="# books" /> </div> ) } } 

docs are part of the js-lingui core documents.

Built-in components and advanced formatting

I started writing this library because I need a) simple syntax and b) full support for built-in components.

Both react-intl and react-i18next have very limited support for react-i18next text and inline components. You can use the basic html tags inside the components ( This is <strong>bold</strong> text. ) Or insert the components as variables ( This is {el} text. Where el = <strong>bold</strong> ).

The problem with the first approach is that you cannot use custom React components. The problem with the second approach is that the translator works with 2 messages instead of one ( This is {el} text. And bold ). This is actually pretty bad because you need to translate the whole sentence in order to maintain context.

With lingui-react you can use any React components inside the translations, and the message is retrieved in one piece:

 <Trans>See the <Link to="/more">description</Link> below.</Trans> // for translator: See the <0>description</0> below. 

Another advantage of this solution is that the component name and details are hidden in the extracted message. I remember how we spent a lot of time updating translations only after we changed the class to an internal element.

Just compare it to interpolation in response-i18next or react-intl .

Requirements

Both lingui-i18n and lingui-react require presets for everything to work. This is a problem if you want to use it with the Create React application, since you need to either push or fork react-scripts .

+4
source share

Try the https://github.com/alibaba/react-intl-universal developed by the Alibaba Group. yahoo / react-intl can only be used as a layer of type React.Component. There is no way to internationalize it for a Vanilla JS file. For example, the following snippet is a common form validator that is used by many React.Component in our applications.

 export default const rules = { noSpace(value) { if (value.includes(' ')) { return 'Space is not allowed.'; } } }; 

alibaba / react-intl-universal is simple but powerful. This does not change the behavior of the components. And can be used in JSX and regular JS file.

+1
source share

All Articles