Skip to content

Commit 0d7aaaa

Browse files
feat!: Bump react-intl to v10 (#288)
Bumps react-intl to v10. BREAKING CHANGE: removes deprecated `injectIntl`+`intlShape`.
1 parent bf0779d commit 0d7aaaa

12 files changed

Lines changed: 78 additions & 434 deletions

File tree

‎docs/how_tos/i18n.rst‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,15 @@ These steps will allow your application to accept translation strings. See `fron
4444

4545
#. For places in your code where you need a display string, and it has to be a plain JavaScript string (e.g., a button label), you will need to do the following:
4646

47-
#. Inject the ``intl`` object into your component:
47+
#. Use a hook to access the ``intl`` object within your component:
4848

49-
#. ``import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';``;
49+
#. ``import { useIntl } from '@openedx/frontend-base';``;
5050

51-
#. add ``intl: intlShape.isRequired`` to your component's ``propTypes``.
52-
53-
#. instead of ``export Foo``, ``export injectIntl(Foo)`` .
51+
#. write ``const intl = useIntl();`` near the beginning of your component.
5452

5553
#. Define your messages using ``defineMessages``. This function doesn't actually do anything; it's just a hook for the translation pipeline to be able to find your translation strings. You can call ``defineMessages`` wherever you want, but if you have a lot of them you might want to move them to a separate file. Either ``MyAppName.messages.js`` (if your entire app has only a few strings) or ``SomeComponent.messages.js`` will work. Your file should look like the example below. For your own sanity, using a short camel-case string for the property name is fine as long as ``id`` is globally unique in the MFE. Example::
5654

57-
import { defineMessages } from '@edx/frontend-platform/i18n';
55+
import { defineMessages } from '@openedx/frontend-base';
5856

5957
const messages = defineMessages({
6058
'cartPayNow': {

‎package-lock.json‎

Lines changed: 57 additions & 291 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"prop-types": "^15.8.1",
117117
"react-dev-utils": "12.0.1",
118118
"react-focus-on": "^3.10.2",
119-
"react-intl": "^6.6.6",
119+
"react-intl": "^10.1.20",
120120
"react-refresh": "0.18.0",
121121
"react-refresh-typescript": "^2.0.9",
122122
"react-responsive": "^10.0.0",
@@ -160,7 +160,7 @@
160160
"nodemon": "^3.1.4"
161161
},
162162
"peerDependencies": {
163-
"@openedx/paragon": "^23.20.0",
163+
"@openedx/paragon": "^23.23.0",
164164
"@tanstack/react-query": "^5.81.2",
165165
"react": "^18.3.1",
166166
"react-dom": "^18.3.1",
Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -23,66 +23,6 @@
2323
*
2424
*/
2525

26-
/**
27-
* @name createIntl
28-
* @kind function
29-
* @see {@link https://formatjs.io/docs/react-intl/api#createIntl Intl}
30-
*/
31-
32-
/**
33-
* @name FormattedDate
34-
* @kind class
35-
* @see {@link https://formatjs.io/docs/react-intl/components/#formatteddate Intl}
36-
*/
37-
38-
/**
39-
* @name FormattedTime
40-
* @kind class
41-
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedtime Intl}
42-
*/
43-
44-
/**
45-
* @name FormattedRelativeTime
46-
* @kind class
47-
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedrelativetime Intl}
48-
*/
49-
50-
/**
51-
* @name FormattedNumber
52-
* @kind class
53-
* @see {@link https://formatjs.io/docs/react-intl/components/#formattednumber Intl}
54-
*/
55-
56-
/**
57-
* @name FormattedPlural
58-
* @kind class
59-
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedplural Intl}
60-
*/
61-
62-
/**
63-
* @name FormattedMessage
64-
* @kind class
65-
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedmessage Intl}
66-
*/
67-
68-
/**
69-
* @name IntlProvider
70-
* @kind class
71-
* @see {@link https://formatjs.io/docs/react-intl/components/#intlprovider Intl}
72-
*/
73-
74-
/**
75-
* @name defineMessages
76-
* @kind function
77-
* @see {@link https://formatjs.io/docs/react-intl/api#definemessagesdefinemessage Intl}
78-
*/
79-
80-
/**
81-
* @name useIntl
82-
* @kind function
83-
* @see {@link https://formatjs.io/docs/react-intl/api#useIntl Intl}
84-
*/
85-
8626
export {
8727
createIntl,
8828
defineMessages,
@@ -93,7 +33,10 @@ export {
9333
FormattedRelativeTime,
9434
FormattedTime,
9535
IntlProvider,
96-
useIntl
36+
useIntl,
37+
type IntlConfig,
38+
type ResolvedIntlConfig,
39+
type IntlShape,
9740
} from 'react-intl';
9841

9942
export {
@@ -104,14 +47,9 @@ export {
10447
getPrimaryLanguageSubtag,
10548
getSupportedLanguageList,
10649
handleRtl,
107-
intlShape,
10850
isRtl,
10951
LOCALE_CHANGED,
11052
LOCALE_TOPIC,
11153
mergeMessages,
112-
updateLocale
54+
updateLocale,
11355
} from './lib';
114-
115-
export {
116-
default as injectIntl
117-
} from './injectIntlWithShim';

‎runtime/i18n/injectIntlWithShim.jsx‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎runtime/i18n/lib.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import merge from 'lodash/merge';
2-
import PropTypes from 'prop-types';
32
import { MessageFormatElement } from 'react-intl';
43
import Cookies from 'universal-cookie';
54

@@ -51,18 +50,6 @@ const rtlLocales = [
5150

5251
let messages: Record<string, Record<string, string> | Record<string, MessageFormatElement[]> | undefined>;
5352

54-
/**
55-
* @memberof module:Internationalization
56-
*
57-
* Prior versions of react-intl (our primary implementation of the i18n service) included a
58-
* PropTypes-based 'shape' for its `intl` object. This has since been removed. For legacy
59-
* compatibility, we include an `intlShape` export that is set to PropTypes.object. Usage of this
60-
* export is deprecated.
61-
*
62-
* @deprecated
63-
*/
64-
export const intlShape = PropTypes.object;
65-
6653
/**
6754
* @memberof module:Internationalization
6855
*/

‎runtime/index.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,16 @@ export {
6767
getPrimaryLanguageSubtag,
6868
getSupportedLanguageList,
6969
handleRtl,
70-
injectIntl,
7170
IntlProvider,
72-
intlShape,
7371
isRtl,
7472
LOCALE_CHANGED,
7573
LOCALE_TOPIC,
7674
mergeMessages,
7775
updateLocale,
78-
useIntl
76+
useIntl,
77+
type IntlConfig,
78+
type ResolvedIntlConfig,
79+
type IntlShape,
7980
} from './i18n';
8081

8182
export {

‎runtime/jest.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
'<rootDir>/setupTest.js',
2020
],
2121
transformIgnorePatterns: [
22-
'/node_modules/(?!(@openedx|@edx)/)',
22+
'/node_modules/(?!(@openedx|@edx|react-intl|@formatjs|intl-messageformat)/)',
2323
],
2424
modulePathIgnorePatterns: [
2525
'/dist/',

‎shell/header/helpButtonSlotOperation.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('helpButtonSlotOperation', () => {
1919
mergeAppConfig(TEST_APP_ID, { SUPPORT_URL: 'https://help.example.com/test' });
2020

2121
const op = helpButtonSlotOperation({ appId: TEST_APP_ID, role: TEST_ROLE });
22+
// The following is for TypeScript, since `WidgetRendererProps` sometimes has 'element' and sometimes 'component'.
23+
if (!('element' in op)) throw new Error(`Expected ${JSON.stringify(op)} to have an 'element'.`);
2224
expect(isValidElement(op.element)).toBe(true);
2325

2426
const getUrl = (op.element as React.ReactElement<{ getUrl: () => string | undefined }>).props.getUrl;

‎shell/jest.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
'setupTest.js',
2121
],
2222
transformIgnorePatterns: [
23-
'/node_modules/(?!(@openedx|@edx)/)',
23+
'/node_modules/(?!(@openedx|@edx|react-intl|@formatjs|intl-messageformat)/)',
2424
],
2525
testPathIgnorePatterns: [
2626
'/site.config.test.tsx',

0 commit comments

Comments
 (0)