-
Notifications
You must be signed in to change notification settings - Fork 1
CORE-1455: Missing translation for "Content Warning" #2638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds missing translations for "Content Warning" text across English, Spanish, and Polish locales. The changes implement internationalization support by introducing a new translation key i18n:content-warning:heading:aria-label and updating the LoginGate and ContentWarning components to use translated text instead of hardcoded English strings.
- Added translation key
i18n:content-warning:heading:aria-labelto all three language files (en, es, pl) - Updated
createIntlfunction to support optional message overrides for testing purposes - Modified
LoginGateandContentWarningcomponents to use the internationalization API - Updated corresponding test files to accommodate the internationalization changes
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/app/messages/en/messages.json |
Added English translation "Content Warning" for the new translation key |
src/app/messages/es/messages.json |
Added Spanish translation "Advertencia de contenido" for the new translation key |
src/app/messages/pl/messages.json |
Added Polish translation "Ostrzeżenie o treści" for the new translation key |
src/app/messages/createIntl.ts |
Enhanced to accept optional newMessages parameter for test message overrides |
src/app/content/components/LoginGate.tsx |
Replaced hardcoded "Content Warning" string with internationalized version using useIntl |
src/app/content/components/ContentWarning.tsx |
Replaced hardcoded "Content warning" string with internationalized version using useIntl |
src/app/content/components/LoginGate.spec.tsx |
Updated test to mock useIntl and added IntlProvider setup |
src/app/content/components/ContentWarning.spec.tsx |
Updated tests to mock useIntl and added IntlProvider setup |
src/app/content/highlights/components/Highlights.spec.tsx |
Updated tests to use new newMessages parameter of createIntl function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <> | ||
| {children} | ||
| <Modal heading='Content Warning'> | ||
| <Modal heading={intl.formatMessage({ id: 'i18n:content-warning:heading:aria-label' })}> |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Modal component's heading prop is passed to FormattedMessage which expects a translation key, not a translated string. Passing intl.formatMessage({ id: 'i18n:content-warning:heading:aria-label' }) will cause the Modal to treat the translated text as a key and attempt to translate it again. Instead, pass the translation key directly: heading='i18n:content-warning:heading:aria-label' and remove the useIntl hook usage.
| import { useSelector } from 'react-redux'; | ||
| import styled from 'styled-components/macro'; | ||
| import ModalWithScrollLock from '../../components/Modal'; | ||
| import { useIntl } from 'react-intl'; |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The useIntl import is no longer needed since the Modal component expects the translation key directly, not a pre-translated string. Remove this import.
| book, | ||
| children, | ||
| }: React.PropsWithChildren<{ book: Book }>) { | ||
| const intl = useIntl(); |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intl variable initialized with useIntl() is no longer needed since the Modal component expects the translation key directly. Remove this line.
| } | ||
|
|
||
| export default memoize(async(loc: string) => { | ||
| export default memoize(async(loc: string, newMessages?: Record<string, string>) => { |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memoize function from lodash/fp only uses the first argument as the cache key by default. This means calls like createIntl('en') and createIntl('en', { 'key': 'value' }) will return the same cached intl instance, ignoring the newMessages parameter on subsequent calls. If newMessages is intended to be different across calls with the same locale, consider using a custom resolver for memoization or not memoizing when newMessages is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newMessages are only meant for tests, right? Maybe call them testMessages or testOverrides.
You can use the memoize function from @openstax/ts-utils to avoid the quirk of lodash's only caching based on the first argument.
| jest.mock('react-intl', () => ({ | ||
| ...jest.requireActual('react-intl'), | ||
| useIntl: () => ({ | ||
| formatMessage: ({ id }: any) => id, | ||
| }), | ||
| })); |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock for useIntl makes the actual createIntl and RawIntlProvider usage in the test ineffective. Since useIntl is mocked to simply return the id, the intl instance created on line 25 is not used by the component. Consider either removing the mock to test with real translations, or removing the createIntl and RawIntlProvider setup since they're not being utilized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite get what copilot means here but maybe it's related to what it said about the modal component in the first few comments.
| jest.mock('react-intl', () => ({ | ||
| ...jest.requireActual('react-intl'), | ||
| useIntl: () => ({ | ||
| formatMessage: ({ id }: any) => id, | ||
| }), | ||
| })); |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock for useIntl makes the actual createIntl and RawIntlProvider usage in these tests ineffective. Since useIntl is mocked to simply return the id, the intl instances created in the tests are not used by the components. Consider either removing the mock to test with real translations, or removing the createIntl and RawIntlProvider setup since they're not being utilized.
| "i18n:toolbar:textresizer:button:increase:aria-label": "Zwiększ rozmiar tekstu", | ||
| "i18n:toolbar:textresizer:popup:heading": "Rozmiar tekstu" | ||
| "i18n:toolbar:textresizer:popup:heading": "Rozmiar tekstu", | ||
| "i18n:content-warning:heading:aria-label": "Ostrzeżenie o treści" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This translation should probably be confirmed by our contact at Katalyst
CORE-1455