Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@atlassian/wrm-react-i18n

atlassianlabs764Apache-2.04.0.1TypeScript support: included

An internationalization i18n helper for WRM and React that can be used in Atlassian Server products

react, i18n, frontend, server, atlassian, dc, front-end, bitbucket, jira, confluence, jsd, webpack, loader, wrm

readme

@atlassian/wrm-react-i18n

node version webpack peer dependency version atlassian-webresource-webpack-plugin peer dependency version react peer dependency version npm downloads

An internationalization i18n helper for WRM and React that can be used in Atlassian Server products and plugins.

Motivation

If your work with the modern Front-End Server and React library there is a good chance you are already using I18n.getText() helper to internationalize your application. The bad news is, you can't fully use React components when you want to substitute the phrase arguments.

The @atlassian/wrm-react-i18n can help you with solving that problem. It's a small library build on top of the I18n.getText() function that adds the missing gap between WRM translation system and React.

For more information about the translations system check the Atlassian Development documentation page:

Installation

npm install @atlassian/wrm-react-i18n --save

Usage example

my-translations.properties

my.phrase.id=Hello {0} {1}!

MyFooComponent.jsx

import { I18n } from '@atlassian/wrm-react-i18n';
import BarComponent from './BarComponent.jsx';

class MyFooComponent extends React.Component {
  render() {
    return <p>{I18n.getText('my.phrase.id', <strong>React</strong>, <BarComponent>World</BarComponent>)}</p>;
  }
}

webpack config

Atlassian Web-Resource webpack Plugin

The @atlassian/wrm-react-i18n package depends on the browser runtime dependency called wrm/i18n. This is not the NPM package but AMD module defined in the browser runtime of a server product.

You need to use webpack and Atlassian Web-Resource webpack Plugin in order to bundle your Javascript code. Take a look at the example how to provide the require dependency:

// webpack.config.js
module.exports = {
  plugins: [
    new WRMPlugin({
      // your WRM config

      providedDependencies: {
        'wrm/i18n': {
          dependency: 'com.atlassian.plugins.atlassian-plugins-webresource-plugin:i18n',
          import: {
            var: 'require("wrm/i18n")',
            amd: 'wrm/i18n',
          },
        },
      },
    }),
  ],
};

For more information about the WRM Plugin please check the plugin page.

Minification of production bundle

You need to tell webpack not to minimize the usage of I18n.getText(). During the runtime of the server product WRM will transform your phrase keys into proper translations.

Starting from version 4.26.0 webpack is using new default minimizer called Terser.

Please check you webpack version before adding the required mangle exception.

Terser

If you are using default webpack Terser plugin:

// webpack.config.js
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  optimization: {
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          mangle: {
            // Don't mangle usage of I18n.getText() function
            reserved: ['I18n', 'getText'],
          },
        },
      }),
    ],
  },
};

Uglify

If you are using Uglify use this snippet:

// webpack.config.js
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          mangle: {
            // Don't mangle usage of I18n.getText() function
            reserved: ['I18n', 'getText'],
          },
        },
      }),
    ],
  },
};

FAQ

Why do I need to use this package?

There is a good chance that you actually don't need to use this package at all. If you are not using, React neither you are not using the substitution in your translation phrases that are a React components, then you don't need to us it.

If you only want to translate a regular string like e.g. I18n.getText('foo.bar.key) then you can import the built-in runtime package called wrm/i18n:

import { i18n } from 'wrm/i18n';

console.log(I18n.getText('my.phrase.key'));

The @atlassian/wrm-react-i18n package is compatible with the wrm/i18n package and you should use only one of them inside a single ESM module.

Recipes

Writing unit test with Jest

If you will start using I18n.getText() function, then you will find that your unit tests will start failing with this error message:

Cannot find module 'wrm/format' from 'wrm-react-i18n.js'

or

Cannot find module 'wrm/i18n' from 'wrm-react-i18n.js'

In order to fix that you need to provide a missing module that is only available in the browser runtime when you run the Atlassian server product:

  1. Locate and edit your Jest config file e.g. jest.config.js
  2. Add module mapping for the missing modules:
module.exports = {
  moduleNameMapper: {
    '^wrm/format$': '<rootDir>/node_modules/@atlassian/wrm-react-i18n/format.js',
    '^wrm/i18n$': '<rootDir>/node_modules/@atlassian/wrm-react-i18n/i18n.js',
  },
};

The correct path to your node_modules directory might depend on the location where you store the jest.config.js file. For more information about the moduleNameMapper options visit the Jest documentation page.

Using with *.properties webpack loader

This package can be used with the @atlassian/i18n-properties-loader when you run your code with webpack dev server.

You can check the package description for more details and learn how to integrate it with your webpack configuration.

Minimum requirements

This plugin is compatible with:

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

4.0.0 (2025-05-29)

⚠ BREAKING CHANGES

  • @atlassian/wrm-react-i18n: Moved peer dependency webresource-webpack-plugin from atlassian- prefixed to @atlassian scoped

Bug Fixes

  • update wrm-react-i18n to be private (b42d318)
  • wrm-react-i18n: fix npm resolutions by correct peer dependency declaration (48dbf11)

Build System

  • @atlassian/wrm-react-i18n: Moved peer dependency webresource-webpack-plugin from atlassian- prefixed to @atlassian scoped (6cc2751)

3.0.2 (2024-07-09)

Bug Fixes

  • wrm-react-i18n: support webpack and atlassian webpack plugin 4+ (6bcb162)

3.0.1 (2024-07-08)

Bug Fixes

  • wrm-react-i18n: support only webpack v5 (b6cdc4e)

3.0.0 (2024-04-05)

⚠ BREAKING CHANGES

  • use wrm/i18n instead of wrm/format
  • make clear that min. supported version of WRM is 4.2

Bug Fixes

  • SPFE-900 Support WRM 5.3+ two-phase transforms i18n in wrm-react-i18n package (033f0d3)
  • SPFE-900: relax requirement on WRM version for wrm-react-i18n pkg (a14fae3)

2.0.1 (2022-02-10)

Bug Fixes

  • SPFE-900: relax requirement on WRM version for wrm-react-i18n pkg (a14fae3)

2.0.0 (2022-02-10)

⚠ BREAKING CHANGES

  • use wrm/i18n instead of wrm/format
  • make clear that min. supported version of WRM is 4.2

Features

Bug Fixes

  • SPFE-867 Fix rollup warnings about missing external modules (e8a7998)
  • SPFE-900 Support WRM 5.3+ two-phase transforms i18n in wrm-react-i18n package (033f0d3)

1.0.11 (2021-11-17)

Note: Version bump only for package @atlassian/wrm-react-i18n

1.0.10 (2021-10-14)

Note: Version bump only for package @atlassian/wrm-react-i18n

1.0.9 (2021-10-08)

Note: Version bump only for package @atlassian/wrm-react-i18n

1.0.8 (2021-09-24)

Note: Version bump only for package @atlassian/wrm-react-i18n

1.0.7 (2021-09-22)

  • Update internal dependencies

1.0.6 (2021-08-27)

Note: Version bump only for package @atlassian/wrm-react-i18n

1.0.2 (2021-08-26)

Bug Fixes

  • release: fix release script for the wrm package (482efe2)

1.0.1 (2021-08-26)

Note: We updated internal dependencies

1.0.0 (2021-07-01)

⚠ BREAKING CHANGES

  • We removed support for Node 10. The minimum required version is Node 12 now.

Features

  • drop support for Node 10 (2ef1e83)

0.8.1 (2021-03-08)

Bug Fixes

  • deps: Update Node version (1dadcca)

0.8.0 (2021-01-18)

Note: Version bump only for package @atlassian/wrm-react-i18n

0.8.0-alpha.0 (2021-01-13)

  • feat: SPFE-267 Add support for webpack 5 (f73b853)

0.7.0 (2020-06-25)

  • chore: update dependencies (38f5a33)
  • chore: update dependencies (c3d3caa)

0.6.0 (2020-05-11)

  • chore: Add note about minimal requirements (ee38cec)
  • chore: downgrade to Node version 10 (9fc7bab)
  • chore: fix running prettier (09867f3)
  • chore: Update minimal Node version to version 12 so we can support 'String.proptotype.matchall' (cb0ed25)

0.5.1 (2020-04-21)

Bug Fixes

  • fix missing types when creating production bundle (157de4c)

0.5.0 (2020-04-21)

Features

  • TS types for wrm-react-i18n (eda617c)

0.4.5 (2020-02-07)

Bug Fixes

  • Publish package again since version 0.4.4 didn't include JS files

0.4.4 (2020-01-27)

Note: Version bump only for package @atlassian/wrm-react-i18n