Last modified: May 08, 2021Author: Jakub Pomykała

FormatJS: changing translations in realtime

Here, you will learn how to configure FormatJS with translation hosting feature. Translation hosting allows your users to see translated messages right away when you click the 'Publish' button in the translation editor. Later, you will learn how to use <FormattedMessage/> and intl object.

Translation live updates

Let's start with learning how to integrate translation hosting feature to update translations right away when you click 'Publish' in the translation editor and a general configuration.

Install dependencies

Add react-intl library to your React app project.

# Using NPM
npm i -S react react-intl

# Using yarn
yarn add react react-intl

Get project token

Create a project in SimpleLocalize, and get your project token from the 'Integrations' tab. You will need the token to fetch translations from the server.

simplelocalize project token location

React-intl configuration

Create configuration like below:

import React from "react";
import {IntlProvider} from 'react-intl'
import LanguageContext from "./LanguageContext";

class SimpleLocalize extends React.Component {

  constructor(props) {
    this.state = {
      messages: undefined,
      language: "en"

  componentDidMount() {

  setupLanguageMessages = (language) => {
    const projectToken = "<YOUR_PROJECT_TOKEN>";
    const translationsUrl = `${projectToken}/_latest/${language}`;
    return fetch(translationsUrl)
      .then((data) => data.json())
      .then((messages) => this.setState({language, messages}));

  render() {
    return (
          changeLanguage: (language) => this.setupLanguageMessages(language)
          {this.state.messages ? this.props.children : null}

export default SimpleLocalize;

Wrap main component

Wrap your main application component with the created SimpleLocalize component to provide translations for React application.

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import SimpleLocalize from "./SimpleLocalize";


FormattedMessage usage

<FormattedMessage id="YOUR_TRANSLATION_KEY"/>

React will convert the FormattedMessage tag into a span tag and put concrete translation into it. You can also use <FormattedHTMLMessage id="TRANSLATION_WITH_CSS"/> which will also produce a message with HTML inside span tag. An example translation key could look like the following:

TRANSLATION_WITH_CSS = This is my <strong>text</strong>

Switching between languages

Use LanguageContext.Consumer to switch languages.

  {context => (<div className="App">
    <button onClick={() => context.changeLanguage("en")}>English</button>
    <button onClick={() => context.changeLanguage("es")}>Spanish</button>

Full application code is available on GitHub. Visit simplelocalize/simplelocalize-react-intl repository.

Edit your translations

Now you can edit messages in the translation editor and publish them using 'Save & Publish'. Your users will automatically see the changes!

FormatJS translation management